:root {
  color-scheme: light;
  --ink: #202119;
  --muted: #5f6556;
  --paper: #fffdf4;
  --panel: #ffffff;
  --line: #d8d2bd;
  --cell: #f3efdd;
  --cell-hover: #e9e1c2;
  --banana: #f6d244;
  --banana-deep: #c99715;
  --leaf: #3f7d59;
  --red: #b34034;
  --blue: #276b8f;
  --shadow: 0 18px 46px rgba(52, 48, 31, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(246, 210, 68, 0.24), transparent 32rem),
    linear-gradient(135deg, #f9f4df 0%, #eef4ec 42%, #f7f8f3 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(216, 210, 189, 0.8);
  box-shadow: var(--shadow);
}

.help-button {
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid var(--leaf);
  background: #e6f2e5;
  color: #203e2d;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
}

.help-button:hover,
.help-button:focus-visible {
  outline: 3px solid rgba(63, 125, 89, 0.24);
  background: #d8ead7;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 2.4vw, 2.3rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 8px;
}

.stats div {
  min-height: 54px;
  padding: 8px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  display: grid;
  align-content: center;
}

.stats span {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats strong {
  font-size: 1.25rem;
  line-height: 1.1;
}

.play-area {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
}

.side-panel {
  min-height: 0;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(216, 210, 189, 0.8);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}

.control-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.control-group button {
  min-height: 42px;
  border: 1px solid #a38b3d;
  background: var(--banana);
  color: #241d07;
  font-weight: 800;
  cursor: pointer;
}

.control-group button:hover,
.control-group button:focus-visible {
  outline: 3px solid rgba(39, 107, 143, 0.25);
  background: #f9db62;
}

.control-group button:disabled {
  color: #897f61;
  background: #e8e1c8;
  border-color: #d4c9a5;
  cursor: not-allowed;
}

.word-panel {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.word-panel h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#wordList {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

#wordList li {
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
}

#wordList .bad {
  color: var(--red);
}

.board-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(216, 210, 189, 0.8);
  box-shadow: var(--shadow);
}

.board {
  --cell-size: clamp(34px, calc((100vw - 350px) / 17), 52px);
  width: max-content;
  display: grid;
  grid-template-columns: repeat(17, var(--cell-size));
  grid-template-rows: repeat(17, var(--cell-size));
  gap: 4px;
  margin: auto;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--line);
  background: var(--cell);
  display: grid;
  place-items: center;
}

.cell.drop-target {
  background: var(--cell-hover);
  border-color: var(--banana-deep);
}

.tile {
  width: 100%;
  aspect-ratio: 1;
  min-width: 34px;
  border: 1px solid #9c7b24;
  background: linear-gradient(145deg, #fff4a4, #e9bd35);
  color: #211b08;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 3px 7px rgba(74, 55, 7, 0.18);
  display: grid;
  place-items: center;
  position: relative;
  cursor: grab;
  font-weight: 900;
  touch-action: manipulation;
}

.tile:active {
  cursor: grabbing;
}

.tile.selected {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.tile.invalid {
  background: linear-gradient(145deg, #f5a09a, #c0392b);
  border-color: #8b1a14;
  color: #fff;
}

.tile.invalid .points {
  color: rgba(255, 255, 255, 0.75);
}

.letter {
  font-size: clamp(1.05rem, 2vw, 1.55rem);
}

.points {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 0.62rem;
  color: #5a4815;
}

.rack-area {
  min-height: 92px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(216, 210, 189, 0.8);
  box-shadow: var(--shadow);
  position: sticky;
  bottom: 10px;
  z-index: 3;
}


.rack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
  align-items: start;
}

.rack .tile {
  max-width: 54px;
}

.cell .tile {
  min-width: 0;
}

.how-modal {
  width: min(760px, calc(100vw - 28px));
  max-height: min(880px, calc(100vh - 28px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.how-modal::backdrop {
  background: rgba(32, 33, 25, 0.56);
}

.modal-card {
  position: relative;
  overflow: auto;
  max-height: min(880px, calc(100vh - 28px));
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 28px 90px rgba(32, 33, 25, 0.34);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.modal-close:hover,
.modal-close:focus-visible {
  outline: 3px solid rgba(39, 107, 143, 0.22);
}

.modal-copy {
  padding-right: 44px;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--leaf);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modal-copy h2 {
  font-size: clamp(1.45rem, 3vw, 2.2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.modal-copy p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

.how-gif {
  display: block;
  width: 100%;
  margin: 18px 0;
  border: 1px solid var(--line);
  background: var(--paper);
}

.rules-list {
  margin: 0;
  padding-left: 1.35rem;
  display: grid;
  gap: 10px;
  line-height: 1.45;
}

.rules-list li::marker {
  color: var(--banana-deep);
  font-weight: 900;
}

.rules-note {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.win-card {
  text-align: center;
  padding: 40px 32px;
}

.win-card .eyebrow {
  font-size: 1rem;
}

.win-card h2 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  margin-top: 8px;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 28px 0;
}

.win-stat {
  display: grid;
  align-content: center;
  min-width: 80px;
  padding: 12px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.win-stat span {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.win-stat strong {
  font-size: 1.6rem;
  line-height: 1.1;
}

.new-game-button {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.new-game-button:hover,
.new-game-button:focus-visible {
  outline: 3px solid rgba(39, 107, 143, 0.25);
  background: var(--cell);
}

.start-button {
  width: 100%;
  min-height: 48px;
  margin-top: 18px;
  border: 1px solid #a38b3d;
  background: var(--banana);
  color: #241d07;
  font-weight: 900;
  cursor: pointer;
}

.start-button:hover,
.start-button:focus-visible {
  outline: 3px solid rgba(39, 107, 143, 0.25);
  background: #f9db62;
}

.about {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px 18px 8px;
}

.about-inner {
  padding: 22px 24px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(216, 210, 189, 0.8);
  box-shadow: var(--shadow);
}

.about-inner h2 {
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  margin-bottom: 10px;
}

.about-inner p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.55;
  max-width: 78ch;
}

.site-footer {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.footer-inner {
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(216, 210, 189, 0.6);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.footer-inner a {
  color: var(--leaf);
  font-weight: 700;
  text-decoration: none;
}

.footer-inner a:hover,
.footer-inner a:focus-visible {
  text-decoration: underline;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px;
  }

  .game-topbar,
  .play-area {
    grid-template-columns: 1fr;
  }

  .game-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .help-button {
    width: 100%;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .side-panel {
    grid-template-rows: auto auto auto;
  }

  .word-panel {
    max-height: 150px;
  }

  .rack-area {
    bottom: 0;
  }

  .board {
    --cell-size: 38px;
  }
}

@media (max-width: 520px) {
  .brand-mark {
    width: 46px;
    height: 46px;
  }

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

  .stats div {
    min-height: 48px;
    padding: 8px;
  }

  .control-group {
    grid-template-columns: 1fr;
  }

  .modal-card {
    padding: 18px;
  }
}
