:root {
  color-scheme: light;
  --bg: #eef1ed;
  --ink: #17201c;
  --muted: #65706a;
  --panel: #fffdf7;
  --line: #24332d;
  --tile: #f7d98f;
  --tile-edge: #9f6d22;
  --board: #6ea397;
  --cell: #e9f4ee;
  --placed: #fff2bf;
  --selected: #f06f45;
  --new: #bfe6f0;
  --ok: #d8edc4;
  --bad: #ffd7d0;
  --shadow: 0 18px 50px rgba(17, 32, 28, 0.18);
  --cell-size: clamp(46px, calc((100vw - 474px) / 11), 62px);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(rgba(238, 241, 237, 0.9), rgba(238, 241, 237, 0.96)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cg fill='none' stroke='%236ea397' stroke-width='2' opacity='.28'%3E%3Cpath d='M20 20h36v36H20zM56 20h36v36H56zM92 20h36v36H92zM128 20h36v36h-36zM56 56h36v36H56zM128 56h36v36h-36zM164 56h36v36h-36zM20 92h36v36H20zM92 92h36v36H92zM164 92h36v36h-36zM20 128h36v36H20zM56 128h36v36H56zM128 128h36v36h-36zM92 164h36v36H92zM164 164h36v36h-36z'/%3E%3C/g%3E%3Cg fill='%23f06f45' opacity='.16'%3E%3Cpath d='M178 28l8 15 17 3-12 12 3 17-16-8-15 8 3-17-13-12 18-3z'/%3E%3C/g%3E%3C/svg%3E");
  overscroll-behavior: none;
}

button {
  min-height: 42px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff5d8;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition: transform 120ms ease, background-color 120ms ease;
}

button:hover {
  background: #ffe1a6;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.game-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) env(safe-area-inset-right) calc(22px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(420px, 520px);
  gap: 22px;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #a94727;
  font-size: 0.84rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.3rem, 5.4vw, 5.5rem);
  line-height: 0.92;
}

h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats div {
  min-width: 0;
  padding: 14px;
  border-right: 2px solid var(--line);
}

.stats div:last-child {
  border-right: 0;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.stats strong {
  display: block;
  margin-top: 3px;
  font-size: 1.45rem;
}

.table {
  display: grid;
  grid-template-columns: minmax(680px, 1fr) 360px;
  gap: 22px;
  align-items: start;
}

.board-panel,
.side-panel > div {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.board-panel {
  padding: 16px;
  overflow-x: auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(11, var(--cell-size));
  grid-template-rows: repeat(11, var(--cell-size));
  width: calc(var(--cell-size) * 11);
  border: 3px solid var(--line);
  background: var(--line);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(36, 51, 45, 0.75);
  background: var(--cell);
  cursor: pointer;
  user-select: none;
}

.square.drop-target {
  outline: 4px solid rgba(240, 111, 69, 0.45);
  outline-offset: -5px;
}

.square.center {
  background: #ffe0c8;
}

.square.double-letter {
  background: #cce8ff;
}

.square.double-word {
  background: #ffd1c9;
}

.square.triple-letter {
  background: #b7dff0;
}

.square.triple-word {
  background: #f3b39f;
}

.square.occupied,
.square.staged {
  background: var(--placed);
}

.square.staged {
  outline: 4px solid var(--new);
  outline-offset: -5px;
}

.square.valid {
  background: var(--ok);
}

.square.invalid {
  background: var(--bad);
}

.bonus {
  max-width: 88%;
  color: rgba(23, 32, 28, 0.52);
  font-size: 0.63rem;
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  text-transform: uppercase;
}

.letter {
  position: relative;
  display: grid;
  place-items: center;
  width: 74%;
  height: 74%;
  border: 2px solid var(--tile-edge);
  border-radius: 6px;
  background: var(--tile);
  box-shadow: inset 0 -4px 0 rgba(159, 109, 34, 0.24);
  font-size: 1.35rem;
  font-weight: 950;
  line-height: 1;
}

.letter small {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.56rem;
}

.word-score-tag {
  position: absolute;
  right: 2px;
  bottom: 2px;
  z-index: 3;
  min-width: 34px;
  padding: 3px 7px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fffdf7;
  box-shadow: 0 6px 16px rgba(17, 32, 28, 0.18);
  color: #2f6a3a;
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
  pointer-events: none;
}

.status {
  min-height: 28px;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.status[data-tone="ok"] {
  color: #2f6a3a;
}

.status[data-tone="bad"] {
  color: #a33b2d;
}

.side-panel {
  display: grid;
  gap: 16px;
}

.rack-panel,
.translation-panel,
.word-panel {
  padding: 16px;
}

.rack {
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  gap: 8px;
  min-height: 64px;
  margin-bottom: 14px;
}

.rack.rack-drop-target {
  outline: 3px dashed rgba(240, 111, 69, 0.45);
  outline-offset: 4px;
}

.rack-tile {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0;
  aspect-ratio: 1;
  border: 2px solid var(--tile-edge);
  border-radius: 7px;
  background: var(--tile);
  box-shadow: inset 0 -4px 0 rgba(159, 109, 34, 0.24);
  cursor: pointer;
  font-size: 1.45rem;
  font-weight: 950;
}

.rack-tile[draggable="true"] {
  cursor: grab;
}

.rack-tile[draggable="true"]:active {
  cursor: grabbing;
}

.rack-tile small {
  position: absolute;
  right: 5px;
  bottom: 2px;
  font-size: 0.58rem;
}

.rack-tile.selected {
  border-color: var(--selected);
  outline: 4px solid rgba(240, 111, 69, 0.28);
}

.rack-tile.rack-drop-target {
  border-color: var(--selected);
  transform: translateY(-2px);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.move-preview {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: stretch;
  margin: 0 0 14px;
}

.move-preview > div:first-child {
  min-width: 0;
  padding: 10px;
  border: 2px solid rgba(36, 51, 45, 0.28);
  border-radius: 7px;
  background: #f5f8ee;
}

.move-preview span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.move-preview strong {
  display: block;
  margin-top: 2px;
  color: #2f6a3a;
  font-size: 1.3rem;
}

.pending-words {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-content: center;
  min-height: 58px;
  padding: 8px;
  border: 2px solid rgba(36, 51, 45, 0.28);
  border-radius: 7px;
  background: #fffaf0;
}

.played-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 9px;
  border: 2px solid rgba(36, 51, 45, 0.25);
  border-radius: 6px;
  background: #f5f8ee;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.played-words .chip {
  background: #e4f5ed;
  color: #294f3e;
}

.translation-window {
  height: 82px;
  overflow: hidden;
  border: 2px solid rgba(36, 51, 45, 0.28);
  border-radius: 7px;
  background: #f5f8ee;
}

.translation-track {
  display: grid;
  gap: 0;
}

.translation-line {
  min-height: 40px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(36, 51, 45, 0.16);
  animation: lineSlide 420ms ease both;
}

.translation-line strong {
  margin-right: 6px;
}

.translation-line span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.translation-line.empty {
  color: var(--muted);
  font-weight: 800;
}

.effects-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
}

.spark,
.score-burst {
  position: fixed;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff1a8;
  color: #17201c;
  font-weight: 950;
  will-change: transform, opacity;
}

.spark {
  width: 14px;
  height: 14px;
}

.score-burst {
  min-width: 58px;
  min-height: 34px;
  padding: 4px 10px;
}

.score-pop {
  animation: scorePop 620ms ease;
}

@keyframes lineSlide {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scorePop {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.28);
  }

  100% {
    transform: scale(1);
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  :root {
    --cell-size: clamp(48px, calc((100vw - 382px) / 11), 56px);
  }

  .game-shell {
    width: min(100% - 16px, 1180px);
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 430px;
    gap: 12px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: clamp(2rem, 4vw, 3.3rem);
  }

  .table {
    grid-template-columns: calc(var(--cell-size) * 11 + 6px) minmax(300px, 1fr);
    gap: 12px;
  }

  .board-panel,
  .side-panel > div {
    box-shadow: 0 10px 30px rgba(17, 32, 28, 0.14);
  }

  .board-panel,
  .rack-panel,
  .translation-panel,
  .word-panel {
    padding: 10px;
  }

  .side-panel {
    gap: 10px;
  }

  .translation-window {
    height: 76px;
  }

  .controls {
    gap: 8px;
  }
}

@media (max-width: 900px) {
  :root {
    --cell-size: clamp(36px, calc((100vw - 30px) / 11), 54px);
  }

  .topbar,
  .table {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .word-panel:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .game-shell {
    width: min(100% - 18px, 1440px);
  }

  .stats,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .stats div {
    border-right: 0;
    border-bottom: 2px solid var(--line);
  }

  .stats div:last-child {
    border-bottom: 0;
  }

  .board-panel {
    padding: 8px;
  }

  .letter {
    border-width: 1px;
    border-radius: 4px;
    font-size: 0.95rem;
  }

  .letter small,
  .rack-tile small {
    font-size: 0.46rem;
  }

  .bonus {
    font-size: 0.48rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .move-preview {
    grid-template-columns: 1fr;
  }
}
