:root {
  --bg: #101a24;
  --panel: #182633;
  --panel-2: #213345;
  --line: #2f4659;
  --text: #eef2f5;
  --muted: #9fb1c1;
  --accent: #ffc94a;
  --accent-2: #ff8f3f;
  --good: #4cc38a;
  --bad: #e5534b;
  --paper: #f4efe6;
  --ink: #16202a;
  --sel: #ffe28a;
  --word: #bfe0ff;
  --solved: #c9f0d8;
  --cell: 40px;
  --header-h: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.site-logo {
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  color: var(--text);
}

.site-logo span {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.page {
  padding: 8px 8px 40px;
  max-width: 1100px;
  margin: 0 auto;
}

.app {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  min-height: min(640px, calc(100svh - var(--header-h) - 16px));
}

.screen {
  padding: 16px;
}

/* ---------- Buttons ---------- */

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #2a4157;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #2a1a00;
  border-color: transparent;
}

.btn.big {
  font-size: 22px;
  padding: 16px 28px;
  width: min(360px, 100%);
}

.btn.small {
  padding: 6px 10px;
  font-size: 14px;
}

.btn.icon {
  min-width: 36px;
}

.coin {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff4b8, var(--accent) 45%, #c98a00);
  box-shadow: inset 0 0 0 1.5px #a86f00;
  vertical-align: -2px;
}

/* ---------- Home ---------- */

.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-top: 28px;
  text-align: center;
}

.logo {
  margin: 0;
  font-size: clamp(38px, 9vw, 64px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1;
}

.logo span {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 10px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
}

.coins-row {
  font-weight: 700;
  font-size: 18px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.chapter-card {
  width: min(360px, 100%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
}

.chapter-card .row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
}

.bar {
  height: 10px;
  background: #0c141c;
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--good), #9be15d);
  border-radius: 6px;
  transition: width 0.4s ease;
}

.daily-btn {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  border-color: #6b5520;
  background: linear-gradient(180deg, #2c2716, #221f14);
}

.daily-title {
  font-size: 18px;
  color: var(--accent);
}

.daily-sub {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.home-row {
  display: flex;
  gap: 10px;
}

/* ---------- Level map ---------- */

.screen-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.screen-bar h2 {
  margin: 0;
  font-size: 20px;
}

.stars-total {
  color: var(--accent);
  font-weight: 700;
}

.chapters {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chapter h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--muted);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.lvl {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  font-weight: 800;
  font-size: 18px;
}

.lvl .st {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--accent);
}

.lvl.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 201, 74, 0.35);
}

.lvl.locked {
  opacity: 0.35;
}

/* ---------- Achievements ---------- */

.ach-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.ach {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  opacity: 0.55;
}

.ach.done {
  opacity: 1;
  border-color: var(--good);
}

.ach strong {
  display: block;
}

.ach p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Play ---------- */

.play {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  min-height: min(640px, calc(100svh - var(--header-h) - 16px));
}

.play-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.play-title span {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 14px;
}

.coins-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  background: #0c141c;
  border-radius: 20px;
  padding: 4px 10px 4px 6px;
}

.coins-pill.bump {
  animation: bump 0.4s ease;
}

@keyframes bump {
  40% {
    transform: scale(1.2);
  }
}

.progress {
  height: 6px;
  background: #0c141c;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--good), #9be15d);
  transition: width 0.35s ease;
}

.play-main {
  flex: 1;
  display: flex;
  gap: 14px;
  min-height: 0;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #8a8378;
  margin: 0 -1px -1px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.58);
  line-height: 1;
  cursor: pointer;
  text-transform: uppercase;
}

.cell .num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: max(8px, calc(var(--cell) * 0.24));
  font-weight: 600;
  color: #4a4a4a;
}

.cell.in-word {
  background: var(--word);
}

.cell.solved {
  background: var(--solved);
  color: #0f5a33;
}

.cell.revealed {
  color: #a0521d;
}

.cell.cursor {
  background: var(--sel);
}

.cell.gold::after {
  content: '';
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: calc(var(--cell) * 0.22);
  height: calc(var(--cell) * 0.22);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff4b8, var(--accent) 50%, #c98a00);
}

.cell.gold-taken::after {
  display: none;
}

.cell.wrong {
  animation: shake 0.35s ease;
  color: var(--bad);
}

.cell.pop {
  animation: pop 0.45s ease;
}

@keyframes shake {
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes pop {
  40% {
    transform: scale(1.15);
    z-index: 2;
  }
}

.clue-lists {
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  max-height: 560px;
}

.clue-lists h3 {
  margin: 0 0 4px;
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.clue-lists ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.clue-lists li {
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.3;
  cursor: pointer;
  display: flex;
  gap: 6px;
}

.clue-lists li b {
  min-width: 18px;
}

.clue-lists li.active {
  background: var(--panel-2);
  outline: 1px solid var(--accent);
}

.clue-lists li.done {
  color: var(--muted);
  text-decoration: line-through;
}

.clue-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--word);
  color: var(--ink);
  border-radius: 10px;
  padding: 6px;
}

.clue-bar .btn {
  background: rgba(255, 255, 255, 0.55);
  border-color: transparent;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}

.clue-text {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  min-height: 2.6em;
  display: flex;
  align-items: center;
  line-height: 1.3;
}

.clue-text .tag {
  font-weight: 800;
  margin-right: 6px;
  white-space: nowrap;
}

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

.hint-row .btn {
  flex: 1;
  font-size: 14px;
  padding: 8px;
}

.cost {
  color: var(--accent);
  margin-left: 4px;
}

.keyboard {
  display: none;
  flex-direction: column;
  gap: 6px;
  user-select: none;
  -webkit-user-select: none;
}

.kb-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  flex: 1;
  max-width: 44px;
  height: 46px;
  border-radius: 7px;
  border: none;
  background: #d7dee5;
  color: var(--ink);
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  padding: 0;
}

.key:active {
  background: #fff;
}

.key.wide {
  max-width: 64px;
  flex: 1.5;
  font-size: 14px;
}

@media (pointer: coarse), (max-width: 760px) {
  .keyboard {
    display: flex;
  }
  .clue-lists {
    display: none;
  }
}

.toast {
  position: absolute;
  left: 50%;
  top: 90px;
  transform: translateX(-50%);
  background: rgba(8, 14, 20, 0.92);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 800;
  padding: 8px 16px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  z-index: 5;
}

.toast.show {
  opacity: 1;
}

/* ---------- Overlay / results ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 14, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
}

.results {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  width: min(380px, 100%);
  text-align: center;
  animation: rise 0.35s ease;
}

@keyframes rise {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
}

.results h2 {
  margin: 0 0 6px;
  font-size: 26px;
}

.results .stars {
  font-size: 40px;
  letter-spacing: 6px;
  color: #55606b;
}

.results .stars .on {
  color: var(--accent);
  display: inline-block;
  animation: pop 0.4s ease both;
}

.results .stars .on:nth-child(2) {
  animation-delay: 0.15s;
}

.results .stars .on:nth-child(3) {
  animation-delay: 0.3s;
}

.results .meta {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}

.reward-lines {
  text-align: left;
  font-size: 14px;
  margin: 10px 0;
}

.reward-lines div {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px dashed var(--line);
}

.reward-lines .total {
  font-weight: 800;
  font-size: 16px;
  border-bottom: none;
  color: var(--accent);
}

.unlocked {
  background: #173324;
  border: 1px solid var(--good);
  border-radius: 8px;
  padding: 6px 8px;
  margin: 6px 0;
  font-size: 14px;
}

.goal {
  margin: 10px 0 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}

.goal .bar {
  margin-top: 6px;
}

.results .actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.results .actions .btn {
  flex: 1;
}

/* ---------- Ad slot and about ---------- */

.ad-slot:empty {
  display: none;
}

.ad-slot {
  margin: 16px auto 0;
  max-width: 728px;
  min-height: 90px;
}

.about {
  max-width: 760px;
  margin: 24px auto 0;
  color: var(--muted);
  line-height: 1.55;
  padding: 0 8px;
}

.about h2,
.about h3 {
  color: var(--text);
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 13px;
}

@media (max-width: 760px) {
  .page {
    padding: 0 0 32px;
  }
  .app {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .play {
    min-height: calc(100svh - var(--header-h));
    padding: 8px;
  }
}

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