/* Colors and font come from config/game-config.js (theme) and are applied as CSS variables. */
:root {
  --bg: #14213d;
  --bg-image: none;
  --panel: #1f2f56;
  --text: #f5f7ff;
  --muted: #9fb0d9;
  --accent: #fca311;
  --grid-bg: #ffffff;
  --grid-text: #1b1b2f;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --cell: 36px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg) var(--bg-image) center / cover no-repeat;
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#app { position: relative; height: 100%; width: 100%; }

.screen {
  display: none;
  position: absolute;
  inset: 0;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  flex-direction: column;
  align-items: center;
}
.screen.active { display: flex; }

.brand { text-align: center; margin: 8px 0 4px; }
.brand img { max-height: 72px; max-width: 70vw; }
.brand h1 { font-size: clamp(28px, 7vw, 44px); margin: 4px 0; letter-spacing: 0.02em; }
.brand p { margin: 0; color: var(--muted); }

.section-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 18px 0 8px;
  font-weight: 600;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  width: min(560px, 100%);
}

.cat {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 6px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform .1s, border-color .15s;
}
.cat .cat-icon { font-size: 26px; line-height: 1; height: 40px; display: flex; align-items: center; }
.cat .cat-icon img { width: 40px; height: 40px; }
.cat[aria-checked="true"] { border-color: var(--accent); }
.cat:active { transform: scale(.96); }

.segmented {
  display: flex;
  background: var(--panel);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.segmented button[aria-checked="true"] { background: var(--accent); color: #111; font-weight: 700; }

.best { color: var(--accent); min-height: 1.3em; margin: 14px 0 6px; font-weight: 600; }

.btn {
  font: inherit;
  border-radius: 999px;
  border: 2px solid var(--panel);
  background: var(--panel);
  color: var(--text);
  padding: 10px 18px;
  cursor: pointer;
  margin: 4px;
  transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.96); }
.btn:hover { filter: brightness(1.1); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 700; }
.btn.big { font-size: 20px; padding: 14px 48px; }
.btn.ghost { background: transparent; }
.icon-btn { width: 46px; height: 46px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.menu-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; margin-top: 8px; }

/* Game screen */
#screen-game { padding-top: max(10px, env(safe-area-inset-top)); overflow: hidden; }

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: min(900px, 100%);
  flex: 0 0 auto;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 52px; }
.hud-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.hud-stat span:last-child { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hint-btn { position: relative; width: 52px; height: 46px; padding: 0; font-size: 20px; }
.hint-btn span {
  position: absolute; top: -4px; right: -4px;
  background: var(--accent); color: #111; font-size: 11px; font-weight: 700;
  border-radius: 999px; min-width: 18px; height: 18px; line-height: 18px; text-align: center;
}
.hint-btn span.ad::before { content: "AD"; font-size: 9px; }
.hint-btn span.free::before { content: "+"; font-size: 13px; }
.hint-btn span.wait { background: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }

.play-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}
@media (orientation: landscape) and (min-aspect-ratio: 5/4) {
  .play-area { flex-direction: row; align-items: center; }
  #word-panel { max-width: 280px; align-self: center; }
}

#grid-wrap {
  position: relative;
  background: var(--grid-bg);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  touch-action: none;
  flex: 0 0 auto;
}
#grid {
  display: grid;
  position: relative;
  z-index: 2;
}
.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * .55);
  font-weight: 700;
  color: var(--grid-text);
  cursor: pointer;
}
.cell.hint { animation: hintPulse 1s ease-in-out 3; border-radius: 50%; }
@keyframes hintPulse { 0%, 100% { background: transparent; } 50% { background: var(--accent); } }

#found-layer {
  position: absolute;
  left: 8px; top: 8px;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}
#found-layer line { stroke-linecap: round; }
#found-layer .found-line { animation: draw .25s ease-out; }
@keyframes draw { from { opacity: 0; } to { opacity: 1; } }

#word-panel { width: min(560px, 100%); flex: 0 1 auto; min-height: 0; overflow-y: auto; }
#word-panel .section-label { margin-top: 0; text-align: center; }
#word-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
}
#word-list li { font-size: 17px; font-weight: 600; transition: opacity .3s; }
#word-list li.found { text-decoration: line-through; text-decoration-thickness: 2px; opacity: .45; }

.toast {
  position: absolute;
  left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(0, 0, 0, .8);
  padding: 8px 18px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Create screen */
#screen-create h2 { margin: 8px 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; width: min(480px, 100%); margin: 8px 0; color: var(--muted); font-size: 14px; }
.field input, .field textarea, .field select, .share-link {
  font: inherit; font-size: 16px; color: var(--text); background: var(--panel);
  border: 2px solid transparent; border-radius: 10px; padding: 10px; width: 100%;
  -webkit-user-select: text; user-select: text;
}
.field textarea { resize: vertical; }
.share-link { width: min(480px, 100%); margin: 8px 0; font-size: 13px; }
.error { color: #ff8a8a; min-height: 1.2em; margin: 4px 0; }

/* Overlays */
.overlay {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(5, 10, 25, .75);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.overlay[hidden] { display: none; }
.card {
  background: var(--panel);
  border-radius: 20px;
  padding: 26px 22px;
  width: min(360px, 90vw);
  display: flex; flex-direction: column; align-items: stretch; text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  animation: pop .25s ease-out;
}
.card h2 { margin: 0 0 10px; }
.end-score { font-size: 22px; margin: 4px 0; }
.end-score span { font-size: 44px; font-weight: 800; color: var(--accent); display: block; }
.muted { color: var(--muted); margin: 4px 0; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

[dir="rtl"] #word-list { direction: rtl; }
@media (orientation: landscape) and (min-aspect-ratio: 5/4) {
  .toast { left: auto; right: 24px; transform: translate(0, 20px); }
  .toast.show { transform: translate(0, 0); }
}

/* Daily challenge + stats */
.daily-card {
  display: flex; align-items: center; gap: 12px;
  width: min(560px, 100%); margin: 14px 0 0; padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent), #ffcf5c);
  color: #111; border: 0; border-radius: var(--radius);
  font: inherit; text-align: left; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
  transition: transform .1s;
}
.daily-card[hidden] { display: none; }
.daily-card:active { transform: scale(.98); }
.daily-card.done { background: var(--panel); color: var(--text); }
.daily-icon { display: flex; }
.daily-text { display: flex; flex-direction: column; flex: 1; }
.daily-text strong { font-size: 18px; }
.daily-text span { font-size: 13px; opacity: .8; }
.streak { display: inline-flex; align-items: center; gap: 3px; font-weight: 800; font-size: 18px; color: #7c2d12; }
.daily-card.done .streak { color: var(--accent); }
.streak.zero { opacity: .45; }
.repair { margin-top: 6px; border-color: var(--accent); color: var(--accent); }
.streak-line { color: var(--accent); font-weight: 700; margin: 0 0 8px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 6px 0 16px; }
.stats-grid div { display: flex; flex-direction: column; align-items: center; }
.stats-grid span { font-size: 28px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.stats-grid small { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* Journey */
[hidden] { display: none !important; }
.journey-card {
  display: flex; align-items: center; gap: 12px;
  width: min(560px, 100%); margin: 14px 0 0; padding: 14px 16px;
  background: linear-gradient(135deg, #2a9d8f, #7bc96f);
  color: #0b1d17; border: 0; border-radius: var(--radius);
  font: inherit; text-align: left; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
  transition: transform .1s;
}
.journey-card:active { transform: scale(.98); }
.journey-meta { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 4px; background: rgba(0, 0, 0, .22); color: #fff; border-radius: 999px; padding: 3px 9px; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.pill svg { color: #ffd166; }

.map-head { display: flex; align-items: center; gap: 8px; width: min(560px, 100%); }
.map-head h2 { flex: 1; margin: 0; }
#map-worlds { width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; margin: 10px 0; }
.world { --world: var(--accent); background: var(--panel); border-radius: var(--radius); border-top: 6px solid var(--world); padding: 12px 12px 14px; }
.world h3 { margin: 0; color: var(--world); }
.world-sub { margin: 2px 0 10px; color: var(--muted); font-size: 13px; }
.world.closed { opacity: .55; }
.level-path { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 8px; }
.level-path .node:nth-child(10n+6), .level-path .node:nth-child(10n+7), .level-path .node:nth-child(10n+8), .level-path .node:nth-child(10n+9), .level-path .node:nth-child(10n+10) { transform: translateX(10%); }
.node {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid var(--world); background: transparent; color: var(--text);
  font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0;
}
.node .node-n { font-size: 18px; font-weight: 800; }
.node .node-stars { font-size: 10px; letter-spacing: 1px; color: #ffd166; min-height: 12px; }
.node.done { background: var(--world); color: #111; }
.node.done .node-stars { color: #5a3e00; }
.node.current { box-shadow: 0 0 0 4px rgba(255, 255, 255, .85); animation: nodePulse 1.4s ease-in-out infinite; }
.node.locked { border-style: dashed; opacity: .45; cursor: default; }
@keyframes nodePulse { 50% { box-shadow: 0 0 0 7px rgba(255, 255, 255, .35); } }
.map-continue { position: sticky; bottom: 0; }

#screen-game.journey #puzzle-title { color: var(--world); }
.cell { position: relative; }
.cell.bonus { background: radial-gradient(circle, rgba(249, 199, 79, .85) 0 55%, transparent 58%); border-radius: 50%; }
.cell.locked { background: repeating-linear-gradient(45deg, rgba(90, 90, 120, .28) 0 4px, transparent 4px 8px); color: #5c5c78; }
.cell.locked::before { content: ""; position: absolute; top: 2px; right: 2px; width: 28%; height: 22%; border-radius: 2px; background: #6c6c88; }
.cell.bomb { background: radial-gradient(circle, #c9184a 0 52%, transparent 55%); color: #fff; border-radius: 50%; }
.cell.bonus::after { content: "\2605"; position: absolute; top: -2px; right: 0; font-size: 10px; line-height: 1; color: #7a4b00; }
.cell.bomb::after { content: attr(data-fuse); position: absolute; top: -4px; right: -4px; min-width: 18px; height: 16px; line-height: 16px; font-size: 10px; text-align: center; border-radius: 8px; background: #1b1b2f; color: #fff; padding: 0 3px; }
.cell.bomb.urgent { animation: urgent .6s ease-in-out infinite; }
@keyframes urgent { 50% { transform: scale(1.12); } }
.hint-btn span.cost { background: #f9c74f; }
.end-stars { font-size: 38px; letter-spacing: 6px; color: #ffd166; margin: 0 0 4px; }
.coins-line { color: #f9c74f; font-weight: 700; margin: 0 0 8px; }

/* Coach, selection preview, settings, save notice */
.coach {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  width: min(560px, 100%); margin-top: 8px; padding: 8px 8px 8px 14px;
  background: var(--panel); border-left: 4px solid var(--accent); border-radius: 12px;
}
.coach p { margin: 0; flex: 1; font-size: 15px; line-height: 1.35; }
.coach .btn { margin: 0; padding: 8px 14px; flex: 0 0 auto; border-color: var(--accent); }
#found-layer .coach-line { stroke-dasharray: var(--len) var(--len); animation: coachDraw 1.8s ease-in-out infinite; }
@keyframes coachDraw { 0% { stroke-dashoffset: var(--len); opacity: .9; } 70% { stroke-dashoffset: 0; opacity: .9; } 100% { stroke-dashoffset: 0; opacity: 0; } }
#found-layer line.sel { stroke-dasharray: none; }
body.cvd #found-layer line.sel { stroke: rgba(20, 33, 61, .45); }
.sel-preview {
  position: absolute; left: 50%; top: -14px; transform: translate(-50%, -100%); z-index: 5;
  background: var(--accent); color: #111; font-weight: 800; letter-spacing: .12em;
  padding: 4px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap; font-size: 18px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
}
.settings .setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; border-bottom: 1px solid rgba(255, 255, 255, .08); text-align: left; }
.settings .setting[hidden] { display: none; }
.settings input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.settings input[type="range"] { width: 45%; accent-color: var(--accent); }
.settings output { color: var(--muted); font-size: 13px; margin-left: 4px; }
.settings .btn { margin-top: 14px; }
.notice { width: min(560px, 100%); margin: 12px 0 0; padding: 8px 12px; border-radius: 10px; background: rgba(255, 138, 138, .12); color: #ffc4c4; font-size: 14px; text-align: center; }
.btn:focus-visible, .cat:focus-visible, .node:focus-visible, .segmented button:focus-visible, .daily-card:focus-visible, .journey-card:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition: none !important; }
body.reduce-motion .cell.hint { animation: none; background: var(--accent); }

/* Low-end phones: blurring the whole screen behind an overlay is the costliest paint in the game. */
@media (pointer: coarse) {
  .overlay { backdrop-filter: none; background: rgba(5, 10, 25, .88); }
}
#word-list li.bonus::before, #word-list li.bomb::before, #word-list li.locked::before {
  content: ""; display: inline-block; width: .6em; height: .6em; margin-right: .35em; vertical-align: .08em;
}
#word-list li.bonus::before { background: #f9c74f; border-radius: 50%; }
#word-list li.bomb::before { background: #c9184a; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
#word-list li.locked::before { background: repeating-linear-gradient(45deg, #9fb0d9 0 2px, transparent 2px 4px); border: 1px solid #9fb0d9; border-radius: 2px; }
#word-list li.locked { color: var(--muted); }

@media (max-height: 760px) and (min-width: 480px) {
  .brand { margin: 0; }
  .brand h1 { font-size: 34px; margin: 0; }
  .journey-card, .daily-card { margin-top: 10px; padding-top: 10px; padding-bottom: 10px; }
  .section-label { margin: 12px 0 6px; }
  .cat { padding: 6px 6px; flex-direction: row; justify-content: center; gap: 6px; }
  .cat .cat-icon, .cat .cat-icon img { height: 26px; width: 26px; }
  .best { margin: 8px 0 2px; }
}
