:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --text: #1b1f27;
  --muted: #646b78;
  --gold: #a8812e;
  --accent: #0a7c86;
  --cell: #ffffff;
  --border: #d9d2c3;
  --good: #1f8a4c;
  --bad: #c0392b;
  --shadow: 0 6px 24px rgba(0, 0, 0, .08);
  --gold-text: linear-gradient(180deg, #c8aa6e, #8a6a2c 55%, #5b4318);
  --veil: linear-gradient(180deg, rgba(244, 241, 234, .55), rgba(244, 241, 234, .85) 55%, var(--bg));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f17;
    --panel: #121a26;
    --text: #f0e6d2;
    --muted: #8f9bab;
    --gold: #c8aa6e;
    --accent: #0ac8b9;
    --cell: #0f1621;
    --border: #2b3646;
    --good: #2ecc71;
    --bad: #e74c3c;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    --gold-text: linear-gradient(180deg, #f0e6d2, #c8aa6e 55%, #785a28);
    --veil: linear-gradient(180deg, rgba(10, 15, 23, .25), rgba(10, 15, 23, .7) 55%, var(--bg));
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  position: relative;
  isolation: isolate;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; border-radius: 8px; padding: .5rem .9rem; border: 1px solid var(--border); background: var(--panel); color: var(--text); }
button.primary { background: var(--gold); color: #10141b; border-color: var(--gold); font-weight: 600; }
button.ghost { background: transparent; }
.top { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand nav" "meta meta"; gap: .75rem; align-items: center; padding: 1rem; max-width: 760px; margin: 0 auto; }
.brand { grid-area: brand; }
.meta { grid-area: meta; }
.top nav { grid-area: nav; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 600px) {
  .top { grid-template-columns: minmax(0, 1fr); grid-template-areas: "brand" "nav" "meta"; }
  .top nav { justify-content: flex-start; }
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; }
.brand img { filter: drop-shadow(0 2px 8px rgba(200, 170, 110, .35)); }
.wordmark { display: flex; flex-wrap: wrap; align-items: baseline; font-family: "Cinzel", Georgia, serif; font-weight: 800; font-size: 1.7rem; letter-spacing: .06em; line-height: 1; text-transform: uppercase; }
.wordmark .lol { background: var(--gold-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.wordmark .grid-word { color: var(--accent); margin-left: .1em; }
.wordmark small { flex-basis: 100%; font-family: system-ui, sans-serif; font-weight: 500; font-size: .62rem; letter-spacing: .28em; color: var(--muted); margin-top: .3rem; }
.backdrop { position: fixed; inset: 0; z-index: -1; background-size: cover; background-position: center 20%; opacity: 0; transition: opacity .8s ease; }
.backdrop::after { content: ""; position: absolute; inset: 0; background: var(--veil); }
.backdrop.loaded { opacity: 1; }
.meta { display: flex; gap: .5rem; align-items: center; color: var(--muted); flex-wrap: wrap; }
.pill { border: 1px solid var(--border); border-radius: 999px; padding: .2rem .7rem; background: color-mix(in srgb, var(--panel) 70%, transparent); backdrop-filter: blur(4px); }
.pill b { color: var(--text); }
nav { display: flex; gap: .4rem; }
main { max-width: 760px; margin: 0 auto; padding: 0 1rem 2rem; }
.grid { display: grid; grid-template-columns: minmax(70px, 1fr) repeat(3, minmax(0, 1.4fr)); gap: 8px; }
.grid > * { min-width: 0; }
.header-cell { overflow-wrap: anywhere; hyphens: auto; text-shadow: 0 1px 6px var(--bg); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: .4rem; font-size: .82rem; font-weight: 600; min-height: 64px; }
.header-cell small { font-weight: 400; color: var(--muted); text-transform: uppercase; font-size: .62rem; letter-spacing: .08em; margin-top: .2rem; }
.theme-pro small { color: var(--gold); }
.cell { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 10px; background: var(--cell); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: .3rem; position: relative; overflow: hidden; color: var(--muted); font-size: .75rem; }
.cell:hover:not(.solved):not(.locked) { border-color: var(--accent); }
.cell.solved { border-color: var(--good); color: var(--text); cursor: default; }
.cell.locked { cursor: default; opacity: .6; }
.cell img { width: 62%; border-radius: 8px; }
.cell .name { font-weight: 600; margin-top: .25rem; font-size: .8rem; text-align: center; }
.cell .rarity { position: absolute; top: 4px; right: 6px; font-size: .7rem; color: var(--gold); font-weight: 700; }
.cell .count { font-size: .7rem; }
.cell.shake { animation: shake .35s; border-color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.hint { color: var(--muted); font-size: .85rem; text-align: center; }
.actions { display: flex; gap: .5rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--panel); color: var(--text); width: min(520px, calc(100vw - 32px)); max-height: 85vh; padding: 1rem; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .75rem; }
.dialog-head h2 { margin: 0; color: var(--gold); }
.label { color: var(--muted); font-size: .8rem; }
.picker-title { font-weight: 600; }
#search { width: 100%; padding: .65rem .8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--cell); color: var(--text); font-size: 1rem; }
.class-filter { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }
.class-toggle { border-radius: 999px; padding: .25rem .7rem; font-size: .8rem; color: var(--muted); }
.class-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #10141b; font-weight: 600; }
.results { list-style: none; padding: 0; margin: .5rem 0 0; max-height: 50vh; overflow-y: auto; }
.results li { display: flex; align-items: center; gap: .6rem; padding: .4rem; border-radius: 8px; cursor: pointer; }
.results li:hover, .results li.active { background: var(--cell); }
.results li.used { opacity: .35; pointer-events: none; }
.results img { width: 32px; height: 32px; border-radius: 6px; }
.results small { color: var(--muted); }
.big-score { font-size: 2.4rem; font-weight: 700; color: var(--gold); text-align: center; }
.emoji { font-size: 1.6rem; text-align: center; letter-spacing: .2rem; line-height: 1.3; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .5rem; text-align: center; margin: .5rem 0 1rem; }
.stat-row div { border: 1px solid var(--border); border-radius: 10px; padding: .5rem; }
.stat-row b { display: block; font-size: 1.4rem; color: var(--gold); }
.answer-cell { margin: .75rem 0; }
.answer-cell h3 { font-size: .85rem; margin: 0 0 .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--border); border-radius: 999px; padding: .1rem .5rem .1rem .15rem; font-size: .75rem; }
.chip img { width: 20px; height: 20px; border-radius: 50%; }
.chip.mine { border-color: var(--good); }
.rules { padding-left: 1.2rem; line-height: 1.5; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .6rem 1rem; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
@media (max-width: 480px) {
  .header-cell { font-size: .68rem; min-height: 54px; padding: .2rem; }
  .cell .name { font-size: .66rem; }
  .grid { gap: 5px; }
}
.lang { font: inherit; border-radius: 8px; padding: .45rem .5rem; border: 1px solid var(--border); background: color-mix(in srgb, var(--panel) 70%, transparent); color: var(--text); cursor: pointer; }
