:root {
  /* Low-glare light theme: intentionally darker than a conventional white UI. */
  --bg: #c8d3de;
  --surface: #d8e1e9;
  --surface-2: #ced9e3;
  --text: #102030;
  --muted: #425568;
  --line: #8da3b8;
  --brand: #3657b8;
  --brand-strong: #294799;
  --accent: #966307;
  --success: #176c54;
  --cell: #d2dde7;
  --cell-selected: #aebfe9;
  --shadow: 0 16px 42px rgba(31, 50, 72, 0.16);
  color-scheme: light;
}

[data-theme="dark"] {
  /* Dark is the strict default: soft contrast, not harsh black and white. */
  --bg: #09121f;
  --surface: #101d2d;
  --surface-2: #15263a;
  --text: #e7edf5;
  --muted: #a9b7c8;
  --line: #344c68;
  --brand: #8398ff;
  --brand-strong: #9dadff;
  --accent: #e7bf5a;
  --success: #63cfa9;
  --cell: #1b2d42;
  --cell-selected: #31517a;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Make the board letters easy to scan for long periods. */
.letter-cell {
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  font-size: clamp(1rem, 1.65vw, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  border-width: 1.5px;
  border-color: color-mix(in srgb, var(--line) 92%, var(--text));
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--text) 5%, transparent),
    0 1px 2px rgba(20, 35, 50, 0.08);
}

[data-theme="dark"] .letter-cell {
  color: #e8eef6;
  background: #1b2d42;
  border-color: #405b78;
  text-shadow: none;
}

[data-theme="light"] .letter-cell {
  color: #0b1a29;
  background: #d1dce6;
  border-color: #8198ae;
  text-shadow: none;
}

/* The light theme should feel like soft paper/slate, not a bright white screen. */
[data-theme="light"] body {
  background:
    radial-gradient(circle at top left, rgba(54, 87, 184, 0.07), transparent 28rem),
    #c8d3de;
}

[data-theme="light"] .game-card {
  background: #d8e1e9;
  border-color: #91a6ba;
}

[data-theme="light"] .stat,
[data-theme="light"] .word-panel,
[data-theme="light"] .secondary-button {
  background: #ced9e3;
  border-color: #8ea4b8;
}

[data-theme="light"] .icon-button {
  background: #d7e0e8;
  border-color: #8ea4b8;
}

.game-layout {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.48fr);
}

.word-panel {
  border-color: color-mix(in srgb, var(--line) 90%, var(--text));
}

.panel-heading h2 {
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.word-list {
  gap: 9px;
}

.word-chip {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 9px 12px;
  border-width: 1.5px;
  border-color: color-mix(in srgb, var(--line) 88%, var(--text));
  background: color-mix(in srgb, var(--surface) 84%, var(--cell));
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  font-size: clamp(0.88rem, 1.4vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1.2;
}

[data-theme="dark"] .word-chip {
  background: #1b2d42;
  border-color: #45617e;
  color: #e8eef6;
}

[data-theme="light"] .word-chip {
  background: #d5dfe8;
  border-color: #8399ae;
  color: #0b1a29;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.word-chip.found {
  opacity: 0.72;
  font-weight: 700;
}

.stat span {
  font-weight: 650;
}

.stat strong {
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  font-weight: 700;
}

.secondary-button,
.primary-button {
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  font-weight: 700;
}

@media (max-width: 760px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .letter-cell {
    font-size: clamp(0.82rem, 3.5vw, 1.04rem);
  }

  .word-chip {
    min-height: 34px;
    padding: 7px 4px;
    font-size: clamp(0.72rem, 2.8vw, 0.86rem);
  }
}

@media (max-width: 430px), (max-height: 720px) {
  .letter-cell {
    font-size: clamp(0.76rem, 3.6vw, 0.98rem);
  }

  .word-chip {
    min-height: 31px;
    padding: 6px 2px;
    font-size: clamp(0.68rem, 2.75vw, 0.82rem);
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 0.46fr);
  }
}

/* ------------------------------------------------------------
   v6 gameplay visibility + desktop board-size restoration
   ------------------------------------------------------------ */

/* A short desktop viewport must not be mistaken for a small phone.
   This rule intentionally comes after the older max-height rule. */
@media (min-width: 761px) {
  .word-grid {
    width: clamp(440px, 35vw, 500px);
    gap: 4px;
  }

  .letter-cell {
    font-size: clamp(1rem, 1.15vw, 1.16rem);
  }
}

/* Live drag trail: deliberately obvious so the player can see every
   cell currently included before releasing the mouse/touch. */
[data-theme="dark"] .letter-cell.selecting {
  background: #536fd6;
  border-color: #c0cbff;
  color: #ffffff;
  box-shadow:
    0 0 0 2px rgba(125, 148, 255, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transform: scale(0.96);
}

[data-theme="light"] .letter-cell.selecting {
  background: #7187d8;
  border-color: #314a9f;
  color: #ffffff;
  box-shadow:
    0 0 0 2px rgba(54, 87, 184, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: scale(0.96);
}

/* Found letters stay visibly checked on the board after release. */
[data-theme="dark"] .letter-cell.found {
  background: #236a58;
  border-color: #71dfba;
  color: #f1fff9;
  box-shadow:
    0 0 0 1px rgba(113, 223, 186, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transform: none;
}

[data-theme="light"] .letter-cell.found {
  background: #91c9b4;
  border-color: #2f775f;
  color: #102d24;
  box-shadow:
    0 0 0 1px rgba(47, 119, 95, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transform: none;
}

/* During an active drag, the temporary selection color takes priority
   even when the line crosses an already-found letter. */
[data-theme="dark"] .letter-cell.found.selecting,
[data-theme="light"] .letter-cell.found.selecting {
  background: #536fd6;
  border-color: #c0cbff;
  color: #ffffff;
  transform: scale(0.96);
}
