:root {
  --bg: #f6f3ee;
  --bg-glow: #efe6d6;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --border: #e6e0d6;
  --text: #1f1c17;
  --muted: #6f685d;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --tile: #f3dca8;
  --tile-edge: #c9a563;
  --tile-ink: #3a2a12;
  --warn-soft: #fbece4;
  --warn: #a4502a;
  --blank: #b4462f;
  --shadow: 0 1px 2px rgb(40 30 10 / .06), 0 8px 24px rgb(40 30 10 / .06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --bg-glow: #1f1d18;
    --surface: #1d1c19;
    --surface-2: #23221e;
    --border: #34322c;
    --text: #efebe3;
    --muted: #a39d91;
    --accent: #6cc3a8;
    --accent-ink: #0f1f1a;
    --accent-soft: #1f3530;
    --tile: #d9bd82;
    --tile-edge: #9c7b3f;
    --tile-ink: #2a1e0b;
    --warn-soft: #3a241a;
    --warn: #f0a07a;
    --blank: #f59a78;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 500px at 50% -10%, var(--bg-glow), transparent 70%), var(--bg);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 780px; margin: 0 auto; padding: 48px 16px 32px; }

.hero { text-align: center; margin-bottom: 28px; }
.hero h1 {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2rem, 6vw, 2.9rem);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.sub { color: var(--muted); margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.entry { position: sticky; top: 12px; z-index: 2; }

.input-row { display: flex; gap: 8px; }

#letters {
  flex: 1;
  min-width: 0;
  font: 600 1.25rem/1 Inter, system-ui, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#letters::placeholder { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
#letters:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }

.primary {
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  transition: transform .1s, filter .15s;
}
.primary:not(:disabled):hover { filter: brightness(1.08); }
.primary:not(:disabled):active { transform: scale(.97); }

.icon-btn {
  width: 50px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
}
.icon-btn:not(:disabled):hover { color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.tiles { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; min-height: 40px; }
.tiles:empty { display: none; }

.tile {
  position: relative;
  width: 38px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--tile);
  color: var(--tile-ink);
  font: 700 1.15rem/1 Fraunces, Georgia, serif;
  box-shadow: inset 0 -3px 0 var(--tile-edge);
  animation: pop .18s ease-out;
}
.tile sub { position: absolute; right: 4px; bottom: 5px; font: 600 .55rem/1 Inter, sans-serif; }
.tile.blank { background: color-mix(in srgb, var(--tile) 55%, var(--surface)); }
.tile.small { width: 28px; height: 30px; font-size: .9rem; border-radius: 6px; box-shadow: inset 0 -2px 0 var(--tile-edge); }
.tile.small sub { display: none; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

.hint { margin: 10px 2px 0; font-size: .85rem; color: var(--muted); }
.hint .offline { color: var(--accent); font-weight: 500; }
.hint .error { color: var(--warn); font-weight: 500; margin-left: 6px; }

kbd {
  font: 600 .85em Inter, sans-serif;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
}

/* A letter played with a blank tile */
.bl { color: var(--blank); text-decoration: underline dotted; text-underline-offset: 3px; }

#results { margin-top: 20px; display: grid; gap: 16px; }

.section h2 {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}
.section h2 .n { color: var(--text); }

.banner { display: flex; gap: 12px; align-items: flex-start; }
.banner p { margin: 0; line-height: 1.5; }
.banner strong { display: block; margin-bottom: 2px; }
.banner.empty { background: var(--warn-soft); border-color: transparent; }
.banner.empty strong { color: var(--warn); }

.anagrams { display: flex; flex-wrap: wrap; gap: 10px; }
.anagram {
  font: 700 1.4rem/1 Fraunces, Georgia, serif;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.anagram small { font: 600 .75rem Inter, sans-serif; color: var(--muted); margin-left: 6px; letter-spacing: 0; }

.combos { display: grid; gap: 10px; }
.combo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.combo .words { display: flex; flex-wrap: wrap; gap: 6px; }
.combo .w {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
}
.combo .left { display: flex; align-items: center; gap: 4px; margin-left: auto; font-size: .8rem; color: var(--muted); }
.combo .left .tile { animation: none; }

.group + .group { margin-top: 16px; }
.group h3 { font-size: .85rem; margin: 0 0 8px; color: var(--muted); font-weight: 500; }
.group h3 b { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: .9rem;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-transform: lowercase;
}
.chip.common { font-weight: 600; border-color: var(--accent); }
.chip sup { font-size: .65rem; color: var(--muted); margin-left: 3px; font-weight: 500; }

.legend { font-size: .8rem; color: var(--muted); margin: -4px 0 14px; }

.more {
  margin-top: 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  padding: 4px 0;
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 520px) {
  .wrap { padding-top: 28px; }
  .card { padding: 16px; }
  .primary { padding: 0 16px; }
  .tile { width: 32px; height: 34px; font-size: 1rem; }
  .combo .left { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
