/* ─────────────────────────────────────────
       TOKENS — Blue theme (Abacus 4 You)
    ───────────────────────────────────────── */
:root {
  --p: #0056b3;
  --p-dark: #004494;
  --p-light: #e6f0fa;
  --gold: #3b82f6;
  --gold-lt: #dbeafe;
  --err: #c62828;
  --err-lt: #fdecea;
  --ok: #2e7d32;
  --ok-lt: #e8f5e9;
  --bg: #ffffff;
  --bg-grad: #e2eefb;
  --border: rgba(0, 86, 179, 0.15);
  --r: 16px;
  --r-lg: 28px;
  --shadow: 0 4px 24px rgba(0, 86, 179, 0.15);
}

/* ─────────────────────────────────────────
       RESET
    ───────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ─────────────────────────────────────────
       BODY / PAGE
    ───────────────────────────────────────── */
body {
  font-family: "DM Sans", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-grad) 100%);
  background-size:
    20px 20px,
    100% 100%;
  background-attachment: fixed;
  padding-top: calc(var(--header-height, 70px) + 50px);
  padding-bottom: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ─────────────────────────────────────────
       CARD SHELL
    ───────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--r-lg);
  width: min(520px, calc(100vw - 32px));
  padding: 36px 32px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

/* top accent stripe */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(90deg, var(--p) 0%, var(--gold) 100%);
}

/* ─────────────────────────────────────────
       SCREENS
    ───────────────────────────────────────── */
.screen {
  display: none;
}
.screen.active {
  display: block;
  animation: pop 0.3s ease;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ─────────────────────────────────────────
       SETUP — HEADING
    ───────────────────────────────────────── */
.setup-head {
  text-align: center;
  margin-bottom: 28px;
}
.setup-badge {
  display: inline-block;
  background: var(--p-light);
  color: var(--p);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 4px 14px;
  border-radius: 50px;
  margin-bottom: 10px;
  border: 1px solid rgba(0, 86, 179, 0.2);
}
.setup-title {
  font-family: "Sora", sans-serif;
  font-size: 2rem;
  font-weight: 800;
  color: var(--p);
  line-height: 1.1;
}
.setup-sub {
  font-size: 14px;
  color: #78909c;
  margin-top: 6px;
}

/* ─────────────────────────────────────────
       MODE CARDS
    ───────────────────────────────────────── */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.mode-card {
  border: 2px solid #e0e0e0;
  border-radius: var(--r);
  padding: 18px 10px 14px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.18s,
    background 0.18s,
    transform 0.12s;
  user-select: none;
  background: #fafafa;
}
.mode-card:hover {
  border-color: var(--p);
  background: var(--gold-lt);
  transform: translateY(-2px);
}
.mode-card.selected {
  border-color: var(--p);
  background: var(--p-light);
}

/* SVG icon inside card */
.mode-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.mode-icon svg {
  width: 24px;
  height: 24px;
}
.icon-easy {
  background: #e8f5e9;
}
.icon-easy svg {
  stroke: #2e7d32;
}
.icon-hard {
  background: #fff3e0;
}
.icon-hard svg {
  stroke: #e65100;
}
.icon-beast {
  background: #fce4ec;
}
.icon-beast svg {
  stroke: #880e4f;
}

.mode-name {
  font-size: 14px;
  font-weight: 800;
  color: #263238;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.mode-desc {
  font-size: 11px;
  color: #90a4ae;
  margin-top: 4px;
  line-height: 1.4;
}
.mode-card.selected .mode-name {
  color: var(--p);
}
.mode-card.selected .mode-desc {
  color: #4caf50;
}

/* ─────────────────────────────────────────
       CUSTOMISE TOGGLE
    ───────────────────────────────────────── */
.cust-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  cursor: pointer;
  user-select: none;
}
.cust-row span {
  font-size: 13px;
  font-weight: 600;
  color: #90a4ae;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.cust-row:hover span {
  color: var(--p);
}
.cust-arrow {
  width: 16px;
  height: 16px;
  stroke: #90a4ae;
  fill: none;
  transition: transform 0.2s;
}
.cust-arrow.open {
  transform: rotate(90deg);
}

/* ─────────────────────────────────────────
       ADVANCED PANEL
    ───────────────────────────────────────── */
.adv-panel {
  background: #f5f7f8;
  border: 1.5px dashed #cfd8dc;
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 20px;
  display: none;
}

.adv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.adv-field label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #90a4ae;
  margin-bottom: 5px;
}
.adv-field input[type="number"] {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid #cfd8dc;
  color: var(--p);
  font-size: 1.2rem;
  font-weight: 700;
  padding: 4px 0;
  outline: none;
  transition: border-color 0.2s;
}
.adv-field input[type="number"]:focus {
  border-bottom-color: var(--p);
}

/* toggle rows */
.tog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-top: 1px solid #eceff1;
}
.tog-lbl {
  font-size: 14px;
  font-weight: 600;
  color: #37474f;
}
.tog-sub {
  font-size: 11px;
  color: #90a4ae;
  margin-top: 2px;
}

.tog {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.tog input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.tog-sl {
  position: absolute;
  inset: 0;
  background: #cfd8dc;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.tog-sl::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.tog input:checked + .tog-sl {
  background: var(--p);
}
.tog input:checked + .tog-sl::before {
  transform: translateX(20px);
}

/* ─────────────────────────────────────────
       START BUTTON
    ───────────────────────────────────────── */
.start-btn {
  width: 100%;
  border: none;
  border-radius: 50px;
  padding: 17px;
  cursor: pointer;
  background: var(--p);
  color: #fff;
  font-family: "Sora", sans-serif;
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  box-shadow: 0 6px 20px rgba(0, 86, 179, 0.35);
  transition:
    background 0.18s,
    transform 0.12s,
    box-shadow 0.18s;
}
.start-btn:hover {
  background: var(--p-dark);
  box-shadow: 0 8px 26px rgba(0, 86, 179, 0.45);
}
.start-btn:active {
  transform: scale(0.98);
}

/* ─────────────────────────────────────────
       GAME — TOP BAR
    ───────────────────────────────────────── */
.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.timer-pill {
  background: var(--p-light);
  color: var(--p);
  border: 1.5px solid rgba(0, 86, 179, 0.3);
  border-radius: 50px;
  padding: 6px 18px;
  font-size: 15px;
  font-weight: 800;
  min-width: 76px;
  text-align: center;
  transition:
    background 0.3s,
    border-color 0.3s,
    color 0.3s;
}
.timer-pill.urgent {
  background: var(--err-lt);
  border-color: #ef9a9a;
  color: var(--err);
}
.score-row {
  display: flex;
  gap: 8px;
}
.chip {
  padding: 6px 16px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 800;
}
.chip-ok {
  background: var(--ok-lt);
  color: var(--ok);
  border: 1.5px solid #a5d6a7;
}
.chip-bad {
  background: var(--err-lt);
  color: var(--err);
  border: 1.5px solid #ef9a9a;
}

/* progress bar */
.prog-wrap {
  height: 6px;
  background: #eceff1;
  border-radius: 3px;
  margin-bottom: 28px;
  overflow: hidden;
}
.prog-bar {
  height: 6px;
  width: 0%;
  background: linear-gradient(90deg, var(--p), var(--gold));
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ─────────────────────────────────────────
       FLASH ZONE
    ───────────────────────────────────────── */
.flash-zone {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}
.flash-num {
  font-size: 88px;
  font-weight: 900;
  color: var(--p);
  line-height: 1;
  transition: opacity 0.08s;
  letter-spacing: -2px;
}
.flash-sub {
  font-size: 13px;
  font-weight: 600;
  color: #90a4ae;
  margin-top: 10px;
  letter-spacing: 0.5px;
}

/* ─────────────────────────────────────────
       ANSWER ZONE
    ───────────────────────────────────────── */
.ans-zone {
  text-align: center;
}
.ans-prompt {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #90a4ae;
  margin-bottom: 14px;
}
#user-ans {
  width: 75%;
  background: transparent;
  border: none;
  border-bottom: 3px solid #cfd8dc;
  color: var(--p);
  font-size: 3rem;
  font-weight: 900;
  text-align: center;
  padding: 6px 0;
  outline: none;
  transition: border-color 0.2s;
  display: block;
  margin: 0 auto 24px;
}
#user-ans:focus {
  border-bottom-color: var(--p);
}
#user-ans::placeholder {
  color: #cfd8dc;
}

.result-bubble {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 44px;
  border-radius: 50px;
  font-size: 2.4rem;
  font-weight: 900;
  color: #fff;
  margin: 4px 0 14px;
  letter-spacing: -1px;
}
.bbl-ok {
  background: var(--ok);
}
.bbl-bad {
  background: var(--err);
}

.res-lbl {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.lbl-ok {
  color: var(--ok);
}
.lbl-bad {
  color: var(--err);
}

/* game action buttons */
.g-btn {
  width: 100%;
  border: none;
  border-radius: 50px;
  padding: 15px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 10px;
  transition: all 0.15s;
  display: block;
}
.g-btn:active {
  transform: scale(0.98);
}
.g-btn-p {
  background: var(--p);
  color: #fff;
  box-shadow: 0 5px 18px rgba(0, 86, 179, 0.3);
}
.g-btn-p:hover {
  background: var(--p-dark);
}
.g-btn-ghost {
  background: transparent;
  color: #90a4ae;
  border: 1.5px solid #cfd8dc;
}
.g-btn-ghost:hover {
  background: #f5f7f8;
  color: #546e7a;
}

/* ─────────────────────────────────────────
       END CARD
    ───────────────────────────────────────── */
.end-wrap {
  text-align: center;
  padding: 10px 0;
}

/* big animated circle score */
.score-ring-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 24px;
}
.score-ring-wrap svg {
  transform: rotate(-90deg);
}
.ring-bg {
  fill: none;
  stroke: #eceff1;
  stroke-width: 10;
}
.ring-bar {
  fill: none;
  stroke: var(--p);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 377;
  stroke-dashoffset: 377;
  transition: stroke-dashoffset 1s ease;
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-pct {
  font-size: 2rem;
  font-weight: 900;
  color: var(--p);
  line-height: 1;
}
.ring-acc {
  font-size: 11px;
  font-weight: 700;
  color: #90a4ae;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

.end-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--p);
  margin-bottom: 6px;
}
.end-sub {
  font-size: 14px;
  color: #78909c;
  margin-bottom: 24px;
}

.end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}
.stat-box {
  background: #f5f7f8;
  border-radius: var(--r);
  padding: 14px 8px;
}
.stat-val {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--p);
}
.stat-key {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #90a4ae;
  margin-top: 4px;
}
.stat-box.s-ok .stat-val {
  color: var(--ok);
}
.stat-box.s-bad .stat-val {
  color: var(--err);
}

/* ─────────────────────────────────────────
       RESPONSIVE
    ───────────────────────────────────────── */
@media (max-width: 400px) {
  .card {
    padding: 28px 20px;
  }
  .flash-num {
    font-size: 72px;
  }
  .mode-name {
    font-size: 12px;
  }
  .mode-icon {
    width: 34px;
    height: 34px;
  }
  .mode-icon svg {
    width: 20px;
    height: 20px;
  }
}


/* ─── BG ANIMATION FOR PRACTICE PAGES ─── */
.bg-animation {
  position: fixed; 
  top: 0; 
  left: 0;
  width: 100vw; 
  height: 100vh;
  z-index: -1; 
  overflow: hidden; 
  pointer-events: none;
}

.math-shape {
  position: absolute; 
  color: var(--p); /* Uses the primary blue from style.css */
  opacity: 0; 
  bottom: -100px;
  animation: floatUp linear infinite;
}

@keyframes floatUp {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.15; }
  90%  { opacity: 0.15; }
  100% { transform: translateY(-120vh) rotate(360deg); opacity: 0; }
}

/* Staggered positions and speeds */
.math-shape:nth-child(1)  { left: 10%; font-size: 2.5rem; animation-duration: 25s; animation-delay: 0s; }
.math-shape:nth-child(2)  { left: 25%; font-size: 1.8rem; animation-duration: 20s; animation-delay: 5s; }
.math-shape:nth-child(3)  { left: 40%; font-size: 3.5rem; animation-duration: 35s; animation-delay: 2s; }
.math-shape:nth-child(4)  { left: 60%; font-size: 2rem;   animation-duration: 22s; animation-delay: 8s; }
.math-shape:nth-child(5)  { left: 75%; font-size: 3rem;   animation-duration: 30s; animation-delay: 4s; }
.math-shape:nth-child(6)  { left: 90%; font-size: 1.8rem; animation-duration: 18s; animation-delay: 1s; }
.math-shape:nth-child(7)  { left: 15%; font-size: 2rem;   animation-duration: 28s; animation-delay: 12s; }
.math-shape:nth-child(8)  { left: 85%; font-size: 2.8rem; animation-duration: 26s; animation-delay: 9s; }
.math-shape:nth-child(9)  { left: 50%; font-size: 4rem;   animation-duration: 32s; animation-delay: 6s; }
.math-shape:nth-child(10) { left: 35%; font-size: 1.6rem; animation-duration: 19s; animation-delay: 15s; }