:root {
  color-scheme: dark;
  --bg: #111719;
  --bg-soft: #172123;
  --panel: #1d2929;
  --panel-2: #243233;
  --tile: #ead2a2;
  --tile-dark: #6c5129;
  --text: #f4efe1;
  --muted: #9fb1aa;
  --line: rgba(244, 239, 225, 0.12);
  --teal: #4fc0ad;
  --amber: #f0ac45;
  --danger: #f07367;
  --ok: #8ddc8a;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --body-background:
    radial-gradient(circle at 20% 0%, rgba(79, 192, 173, 0.12), transparent 30%),
    linear-gradient(180deg, #111719 0%, #101313 100%);
  --board-background: linear-gradient(180deg, var(--panel) 0%, #192323 100%);
  --input-background: rgba(0, 0, 0, 0.18);
  --tile-face: linear-gradient(180deg, #f2dcaa 0%, #dfbd75 100%);
  --tile-text: #33230e;
}

body[data-theme="notebook"] {
  color-scheme: light;
  --bg: #f3ead8;
  --bg-soft: #fff8eb;
  --panel: #fffdf6;
  --panel-2: #e9f0fb;
  --tile: #ffffff;
  --tile-dark: #c8d2df;
  --text: #20304c;
  --muted: #66758b;
  --line: rgba(46, 81, 130, 0.2);
  --teal: #4d8fca;
  --amber: #2f65b0;
  --danger: #c95858;
  --ok: #357f5f;
  --shadow: 0 16px 34px rgba(53, 80, 116, 0.16);
  --body-background:
    url("/notebook-doodles.svg"),
    linear-gradient(90deg, rgba(47, 101, 176, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, #f7f0e2 0%, #edf4ff 100%);
  --board-background:
    linear-gradient(rgba(65, 128, 196, 0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(65, 128, 196, 0.13) 1px, transparent 1px),
    #fffdf7;
  --input-background:
    linear-gradient(rgba(65, 128, 196, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(65, 128, 196, 0.12) 1px, transparent 1px),
    rgba(255, 255, 255, 0.72);
  --tile-face: linear-gradient(180deg, #ffffff 0%, #eef3fb 100%);
  --tile-text: #255ca8;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--body-background);
  background-size: auto, auto, auto;
  background-position: top center, top left, top left;
  background-attachment: fixed, scroll, scroll;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.topbar,
.score-strip,
.panel,
.board,
.mode-tabs,
.feedback,
.bottom-actions {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  margin: 0;
  font-size: 28px;
  font-weight: 850;
  line-height: 1;
}

.player {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.stars-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  justify-content: center;
  padding: 8px 9px;
  border-radius: 8px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line);
}

.stars-button span {
  line-height: 1;
}

.stars-button span:first-child {
  color: var(--amber);
  font-size: 17px;
  line-height: 1;
}

.shop-gear {
  width: 18px;
  height: 18px;
  fill: none;
  color: var(--muted);
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stars-button strong {
  min-width: 1ch;
  color: var(--amber);
  white-space: nowrap;
}

.stars-button strong:empty {
  display: none;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 18px 0 14px;
  padding: 4px;
  background: color-mix(in srgb, var(--panel-2) 62%, transparent);
  border-radius: 8px;
}

.tab {
  min-height: 36px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.tab.active {
  background: var(--teal);
  color: color-mix(in srgb, var(--bg) 16%, #09211c);
}

.tab:not(.active):disabled {
  opacity: 0.48;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.score-strip.turn-score-strip {
  grid-template-columns: 0.72fr minmax(0, 1.34fr) minmax(82px, 0.82fr);
}

.score-strip div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
}

.score-strip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.score-strip strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-strip .wide-score strong {
  font-size: clamp(19px, 5vw, 24px);
  text-align: center;
}

.score-strip .wide-score {
  text-align: center;
}

.board {
  padding: 14px;
  background: var(--board-background);
  background-size: auto, auto, 28px 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-tray {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 7px 8px 7px 14px;
  border: 1px solid rgba(234, 210, 162, 0.18);
  border-radius: 8px;
  background: var(--input-background);
  background-size: auto, auto, 24px 24px;
}

#currentWord {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 24px;
  font-weight: 850;
  color: var(--tile);
}

#currentWord.hint-slots {
  flex: 1;
  display: flex;
  align-items: center;
  gap: clamp(5px, 1.8vw, 9px);
  overflow-x: auto;
  overflow-y: hidden;
  overflow-wrap: normal;
  scrollbar-width: none;
}

#currentWord.hint-slots::-webkit-scrollbar {
  display: none;
}

.hint-slot {
  width: clamp(30px, 9vw, 42px);
  min-width: clamp(30px, 9vw, 42px);
  height: clamp(30px, 9vw, 42px);
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

.selected-letter {
  border-radius: 8px;
  background: var(--tile-face);
  box-shadow: 0 3px 0 var(--tile-dark), 0 8px 18px rgba(0, 0, 0, 0.18);
  color: var(--tile-text);
}

.hint-letter {
  border-radius: 8px;
  background: var(--tile-face);
  box-shadow: 0 3px 0 var(--tile-dark), 0 8px 18px rgba(0, 0, 0, 0.18);
  color: var(--tile-text);
  opacity: 0.7;
}

.hint-ghost {
  color: var(--tile);
  font-size: 13px;
  opacity: 0.35;
}

.ghost-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
  margin: 18px 0;
}

.tile,
.turn-cell,
.hand-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border-radius: 8px;
  background: var(--tile-face);
  color: var(--tile-text);
  box-shadow: 0 5px 0 var(--tile-dark), 0 12px 24px rgba(0, 0, 0, 0.25);
  font-size: clamp(19px, 6.4vw, 30px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.turn-board {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.turn-board.preview {
  pointer-events: none;
}

.turn-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
  width: min(100%, 420px);
  margin: 0 auto;
}

.turn-cell {
  border: 1px solid rgba(244, 239, 225, 0.1);
  background: color-mix(in srgb, var(--bg-soft) 88%, #172123);
  box-shadow: inset 0 0 0 1px rgba(79, 192, 173, 0.08);
  font-size: clamp(16px, 5.5vw, 28px);
}

.turn-cell.filled {
  border: 0;
  background: var(--tile-face);
  box-shadow: 0 3px 0 var(--tile-dark), 0 8px 18px rgba(0, 0, 0, 0.2);
}

.turn-cell.pending {
  outline: 2px solid var(--teal);
}

.turn-cell.anchor {
  box-shadow: inset 0 0 0 2px rgba(240, 172, 69, 0.5);
}

.turn-cell.preview-cell,
.hand-tile.preview-cell {
  opacity: 0.5;
  filter: saturate(0.78);
}

.hand-tile.preview-hand-tile {
  opacity: 1;
  filter: none;
}

.turn-cell.preview-cell:not(.filled) {
  background: color-mix(in srgb, var(--bg-soft) 78%, transparent);
}

.turn-hand {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
  width: min(100%, 420px);
  margin: 10px auto 8px;
}

.hand-tile {
  font-size: clamp(18px, 6vw, 30px);
  box-shadow: 0 3px 0 var(--tile-dark), 0 8px 18px rgba(0, 0, 0, 0.2);
}

.hand-tile.selected {
  outline: 3px solid var(--teal);
  transform: translateY(-3px);
}

.hand-tile.used {
  opacity: 0.34;
  transform: translateY(4px);
}

.tile.used {
  opacity: 0.36;
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--tile-dark);
}

.tile:disabled {
  cursor: default;
  filter: grayscale(0.2);
  opacity: 0.58;
  transform: none;
  box-shadow: 0 2px 0 var(--tile-dark);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.primary,
.secondary,
.wide {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 820;
}

#hintButton,
.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.icon-action svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-action span {
  min-width: 18px;
  font-weight: 850;
  color: var(--amber);
}

.primary {
  background: var(--amber);
  color: #211405;
}

.secondary {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.feedback {
  min-height: 42px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--teal) 18%, transparent);
  color: color-mix(in srgb, var(--teal) 28%, var(--text));
  font-size: 14px;
}

.feedback.bad {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: color-mix(in srgb, var(--danger) 46%, var(--text));
}

.feedback.good {
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  color: color-mix(in srgb, var(--ok) 42%, var(--text));
}

.feedback a {
  color: var(--tile);
  font-weight: 850;
  text-decoration: none;
}

.feedback a:hover {
  text-decoration: underline;
}

.panel-grid {
  display: grid;
  gap: 12px;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 16px;
}

.panel-title span,
.text-button {
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  padding: 0;
  background: transparent;
}

.word-list,
.leaderboard {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 34px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.word-list li {
  padding: 6px 9px;
  border-radius: 7px;
  background: rgba(234, 210, 162, 0.12);
  color: var(--tile);
  font-size: 13px;
  font-weight: 760;
}

.word-list button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
}

.solutions-title {
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

.solutions-list li {
  background: rgba(79, 192, 173, 0.1);
  color: #c8eee7;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.missed-list li {
  background: rgba(220, 80, 80, 0.08);
  color: #f0b8b8;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dispute-btn {
  background: none;
  border: 1px solid rgba(220, 80, 80, 0.5);
  border-radius: 4px;
  color: #e07070;
  cursor: pointer;
  font-size: 11px;
  padding: 2px 7px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.15s;
}

.dispute-btn:hover {
  opacity: 1;
}

.leaderboard {
  display: grid;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.leaderboard strong {
  color: var(--text);
}

.leaderboard li.history-row {
  grid-template-columns: minmax(82px, 0.85fr) minmax(0, 1fr) auto;
}

.leaderboard li.history-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard .leaderboard-section {
  grid-template-columns: 1fr auto;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.leaderboard .leaderboard-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.leaderboard .leaderboard-section span {
  font-size: 12px;
}

.leaderboard .tournament-summary {
  grid-template-columns: 1fr;
  gap: 3px;
}

.leaderboard .tournament-summary span {
  line-height: 1.35;
}

.history-row.win span:first-child {
  color: var(--ok);
}

.history-row.loss span:first-child {
  color: var(--danger);
}

.bottom-actions {
  position: sticky;
  bottom: 0;
  padding-top: 14px;
  background: linear-gradient(180deg, rgba(17, 23, 25, 0), var(--bg) 34%);
}

.wide {
  width: 100%;
}

.shop-dialog {
  width: min(calc(100% - 28px), 430px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.shop-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.shop-dialog form {
  padding: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

.shop-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 8px;
}

.shop-section-title h3 {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.shop-section-title span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  padding: 11px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  color: color-mix(in srgb, var(--ok) 42%, var(--text));
}

.setting-row strong {
  font-size: 14px;
  font-weight: 500;
}

.setting-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.dictionary-list,
.theme-list {
  display: grid;
  gap: 8px;
}

.dictionary-item,
.theme-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--bg-soft);
  text-align: left;
  box-shadow: inset 0 0 0 1px var(--line);
}

.dictionary-item.selected,
.theme-item.selected {
  box-shadow: inset 0 0 0 2px var(--teal);
}

.dictionary-item strong,
.dictionary-item span,
.theme-item strong,
.theme-item span {
  display: block;
}

.dictionary-item strong,
.theme-item strong {
  font-size: 14px;
}

.dictionary-item span span,
.theme-item span span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.dictionary-state {
  min-width: 82px;
  padding: 7px 8px;
  border-radius: 7px;
  background: rgba(240, 172, 69, 0.12);
  color: var(--amber);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.dictionary-item.selected .dictionary-state,
.theme-item.selected .dictionary-state {
  background: rgba(79, 192, 173, 0.14);
  color: var(--teal);
}

.theme-item {
  grid-template-columns: 38px 1fr auto;
}

.theme-item.locked {
  cursor: default;
  opacity: 0.72;
}

.theme-item.locked:not(.selected) .dictionary-state {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.theme-item.locked.selected {
  opacity: 1;
}

.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.theme-swatch[data-theme-preview="classic"] {
  background: linear-gradient(135deg, #1d2929 0 50%, #ead2a2 50% 100%);
}

.theme-swatch[data-theme-preview="notebook"] {
  background:
    linear-gradient(rgba(47, 101, 176, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47, 101, 176, 0.18) 1px, transparent 1px),
    #fffdf7;
  background-size: 7px 7px;
}

.shop-items {
  display: grid;
  gap: 8px;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-soft);
  text-align: left;
}

.shop-item strong {
  color: var(--amber);
  white-space: nowrap;
  flex: 0 0 auto;
}

.shop-item span strong {
  display: block;
  color: var(--text);
}

.shop-item small {
  display: block;
  max-width: 250px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.shop-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 860px);
  }

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