/* ── Design tokens ─────────────────────────────────────────────── */
:root {
  --bg:        #070e1b;
  --surface:   #0c1525;
  --surface2:  #111e33;
  --border:    #1e2d47;
  --accent:    #7c6af7;
  --text:      #e8eaf0;
  --muted:     #6b7a99;
  --radius:    12px;
  --radius-sm: 8px;
  --font:      system-ui, -apple-system, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── Screens ───────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px env(safe-area-inset-bottom, 12px);
}
.screen[hidden] { display: none; }

.screen--game {
  padding: 12px 12px env(safe-area-inset-bottom, 8px);
  gap: 10px;
  justify-content: flex-start;
}

/* ── Top bar ───────────────────────────────────────────────────── */
.top-bar {
  width: 100%;
  max-width: 480px;
  text-align: center;
  padding: 20px 0 12px;
  position: relative;
}

.top-bar__home {
  position: absolute;
  left: 0;
  top: 22px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}
.top-bar__home:hover { color: var(--text); }
.logo { font-size: 1.6rem; font-weight: 800; letter-spacing: -.5px; color: var(--text); }
.logo span { color: var(--accent); }
.tagline { margin-top: 4px; font-size: .82rem; color: var(--muted); }

/* ── Level select ──────────────────────────────────────────────── */
.packs {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 4px;
}

.pack-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px 20px;
}

.pack-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.pack-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.pack-progress {
  font-size: .78rem;
  color: var(--muted);
  margin-left: auto;
}

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

.level-btn {
  aspect-ratio: 1;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, color .15s, transform .1s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.level-btn:hover  { border-color: var(--accent); color: var(--text); }
.level-btn:active { transform: scale(.94); }

.level-btn--done {
  border-color: #22c55e;
  color: #4ade80;
}
.level-btn--done::after {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: .6rem;
  color: #4ade80;
}

.level-btn--current {
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 2px rgba(124,106,247,.2);
}

/* ── Game header ───────────────────────────────────────────────── */
.game-header {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-label {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  text-align: center;
}

.moves-wrap {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.moves-num { font-size: 1.2rem; font-weight: 800; }
.moves-lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Board ─────────────────────────────────────────────────────── */
.board-wrap {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  line-height: 0;
}

canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ── Game footer ───────────────────────────────────────────────── */
.game-footer {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-ghost {
  font-family: var(--font);
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn-primary:active,
.btn-secondary:active,
.btn-ghost:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  padding: 12px 20px;
  width: 100%;
}

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 20px;
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  padding: 8px 10px;
}
.btn-ghost:hover { color: var(--text); }

.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--muted);
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--font);
  transition: color .15s;
}
.btn-icon:hover { color: var(--text); }

.btn-sound {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  padding: 4px 6px;
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s;
}
.btn-sound:hover      { opacity: .9; }
.btn-sound--muted     { opacity: .28; }

/* ── Win overlay ───────────────────────────────────────────────── */
.win-screen {
  position: fixed;
  inset: 0;
  background: rgba(7, 14, 27, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .25s ease;
}
.win-screen[hidden] { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.win-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(320px, 90vw);
  animation: slideUp .3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.win-emoji  { font-size: 3rem; line-height: 1; }
.win-title  { font-size: 1.8rem; font-weight: 900; }
.win-detail { color: var(--muted); font-size: .88rem; margin-bottom: 4px; }
.win-detail strong { color: var(--text); }

.win-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

/* ── Fill hint ─────────────────────────────────────────────────── */
.fill-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid #fbbf24;
  color: #fbbf24;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 700;
  white-space: nowrap;
  z-index: 50;
  pointer-events: none;
  animation: hintIn .2s ease;
}
.fill-hint[hidden] { display: none; }

@keyframes hintIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 10px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}
