/* ── Reset & Variables ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #070e1b;
  --surface:  #0c1525;
  --surface2: #111e30;
  --border2:  rgba(255,255,255,0.13);
  --accent:   #6c5fff;
  --text:     #e8edf8;
  --muted:    #8892aa;
  --green:    #34d399;
  --red:      #f87171;
  --header-h: 52px;
  --radius:   12px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; cursor: pointer; border: none; background: none; touch-action: manipulation; }

/* ── Screen ──────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100dvh; }

/* ── Header ──────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo-wrap  { display: flex; align-items: center; gap: 8px; }
.logo-back  { color: var(--muted); text-decoration: none; font-size: 1.1rem; padding: 6px 4px; transition: color 0.15s; }
.logo-back:hover { color: var(--text); }
.logo-title { font-weight: 800; font-size: 1rem; }
.logo-title span { color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 8px; }

.streak-display {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  min-width: 32px;
  text-align: center;
}
.streak-display.hot { color: #fb923c; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.25); }

.btn-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  color: var(--muted);
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover { color: var(--text); border-color: rgba(255,255,255,0.25); }

/* ── Game Body ───────────────────────────────────────────────────── */
.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 28px;
  gap: 20px;
}

/* ── Target ──────────────────────────────────────────────────────── */
.target-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 16px 40px;
}
.target-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--muted);
  text-transform: uppercase;
}
.target-num {
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

/* ── Expression Preview ─────────────────────────────────────────── */
.expr-preview {
  font-size: 14px;
  color: var(--muted);
  min-height: 22px;
  text-align: center;
  transition: color 0.2s;
}
.expr-preview.has-op { color: var(--text); }

/* ── Cards ───────────────────────────────────────────────────────── */
.cards-area {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 400px;
}

.num-card {
  background: var(--surface);
  border: 2px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 800;
  min-width: clamp(52px, 17vw, 68px);
  height: clamp(52px, 17vw, 68px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s, border-color 0.12s, transform 0.1s, color 0.12s;
  padding: 0 6px;
  text-align: center;
  line-height: 1.1;
  font-size: clamp(0.9rem, 3.5vw, 1.2rem);
}
.num-card:hover  { border-color: rgba(255,255,255,0.28); background: var(--surface2); }
.num-card:active { transform: scale(0.94); }

.num-card.selected-a {
  background: rgba(108,95,255,0.22);
  border-color: var(--accent);
  color: #fff;
}
.num-card.result {
  background: rgba(52,211,153,0.12);
  border-color: var(--green);
  color: var(--green);
  animation: cardIn 0.2s ease-out;
}
.num-card.wrong {
  background: rgba(248,113,113,0.12);
  border-color: var(--red);
  color: var(--red);
}

@keyframes cardIn {
  from { transform: scale(0.7); opacity: 0.3; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Operations ──────────────────────────────────────────────────── */
.ops-row {
  display: flex;
  gap: 10px;
}

.op-btn {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  width: 62px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, border-color 0.12s, transform 0.08s;
}
.op-btn:not(:disabled):hover  { background: var(--surface2); border-color: rgba(255,255,255,0.22); }
.op-btn:not(:disabled):active { transform: scale(0.93); }
.op-btn:disabled { opacity: 0.3; cursor: default; }
.op-btn.selected {
  background: rgba(108,95,255,0.20);
  border-color: var(--accent);
  color: #fff;
}

/* ── Action Row ──────────────────────────────────────────────────── */
.action-row {
  display: flex;
  gap: 10px;
}

.action-btn {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--muted);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.12s, border-color 0.12s;
}
.action-btn:not(:disabled):hover { color: var(--text); border-color: rgba(255,255,255,0.22); }
.action-btn:disabled { opacity: 0.3; cursor: default; }

/* ── Overlays ────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(7,14,27,0.82);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  backdrop-filter: blur(4px);
}
.overlay.active { display: flex; }

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 40px 28px 36px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: cardIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
}

.overlay-emoji { font-size: 3rem; margin-bottom: 4px; }
.overlay-card h2 { font-size: 1.8rem; font-weight: 800; }
.overlay-card > p { color: var(--muted); font-size: 0.95rem; }

.streak-badge {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fb923c;
  min-height: 24px;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #6c5fff, #a855f7);
  border-radius: var(--radius);
  color: #fff;
  font-weight: 700;
  padding: 14px 32px;
  font-size: 1rem;
  transition: opacity 0.15s, transform 0.1s;
  margin-top: 6px;
}
.btn-primary:hover  { opacity: 0.9; }
.btn-primary:active { transform: scale(0.97); }

.btn-ghost-lg {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 12px 32px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
  margin-top: 4px;
}
.btn-ghost-lg:hover { color: var(--text); border-color: rgba(255,255,255,0.25); }

/* ── Solution overlay ────────────────────────────────────────────── */
.overlay-card--solution {
  text-align: left;
  max-width: 360px;
  gap: 0;
}
.overlay-card--solution h2 {
  font-size: 1.3rem;
  margin-bottom: 18px;
  align-self: flex-start;
}
.solution-steps {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.solution-step {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.solution-step .step-result {
  color: var(--accent);
  font-weight: 800;
}

/* ── Info overlay ────────────────────────────────────────────────── */
.overlay-card--info {
  text-align: left;
  padding: 28px 24px;
  gap: 0;
  position: relative;
  max-width: 360px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}
.overlay-card--info h2 { font-size: 1.4rem; font-weight: 800; margin-bottom: 20px; }
.info-close {
  position: absolute; top: 16px; right: 16px;
  color: var(--muted); font-size: 14px; padding: 4px 8px; border-radius: 6px;
  transition: color 0.15s;
}
.info-close:hover { color: var(--text); }
.info-section {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border2);
}
.info-section:last-of-type { border-bottom: none; margin-bottom: 8px; }
.info-icon { font-size: 1.3rem; flex-shrink: 0; width: 28px; text-align: center; margin-top: 1px; }
.info-section > div > strong {
  display: block; font-size: 0.85rem; font-weight: 700;
  color: var(--text); margin-bottom: 3px;
}
.info-section p { font-size: 0.85rem; color: var(--muted); line-height: 1.5; margin: 0; }
.info-section p strong { display: inline; color: var(--text); }
.overlay-card--info .btn-primary { margin-top: 8px; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-height: 680px) {
  .game-body { justify-content: flex-start; padding-top: 12px; gap: 14px; }
  .target-wrap { padding: 12px 32px; }
}
