:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #1f2a44;
  --muted: #6b7280;
  --primary: #4f6ef7;
  --primary-dark: #3b57d6;
  --good: #4CAF50;
  --bad: #ef5350;
  --accent: #ffb020;
  --border: #e3e8f0;
  --shadow: 0 6px 20px rgba(31, 42, 68, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--card);
  padding: 10px 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--ink); }
.topbar nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--primary); font-weight: 600; }
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: none; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }

.container { max-width: 720px; margin: 0 auto; padding: 20px 16px 48px; }

.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

h1 { font-size: 1.7rem; margin: 0 0 16px; }
h2 { font-size: 1.25rem; margin: 20px 0 10px; }

/* Forms */
form.stack { display: flex; flex-direction: column; gap: 14px; }
label { font-weight: 600; display: block; margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }

.btn {
  display: inline-block;
  width: 100%;
  padding: 16px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #eef1f8; color: var(--primary-dark); }
.btn.accent { background: var(--accent); color: #3a2a00; }

.muted { color: var(--muted); }
.center { text-align: center; }

/* Flash messages */
.flashes { margin-bottom: 16px; }
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 8px; font-weight: 600; }
.flash-error { background: #fdecea; color: #b3261e; }
.flash-success { background: #e7f6e9; color: #1e6b2a; }

/* Home menu */
.menu { display: grid; gap: 14px; }
.game-list { list-style: none; padding: 0; margin: 8px 0 0; }
.game-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }

/* Play screen */
.play-wrap { text-align: center; }
.progress-line { color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.game-title { font-size: 1rem; color: var(--primary-dark); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.prompt {
  font-size: clamp(2.6rem, 12vw, 5rem);
  font-weight: 800;
  margin: 18px 0 8px;
  min-height: 1.2em;
}
.intro { font-size: 1.1rem; color: var(--muted); margin-bottom: 10px; min-height: 1.2em; }

.options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 20px 0;
}
.option {
  font-size: clamp(1.8rem, 8vw, 3rem);
  font-weight: 800;
  padding: 24px 8px;
  border: 3px solid var(--border);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform .05s ease, border-color .1s ease;
}
.option:active { transform: translateY(2px); }
.option:disabled { cursor: default; }
.option.correct { border-color: var(--good); background: #e7f6e9; }
.option.wrong { border-color: var(--bad); background: #fdecea; }
.option .tens { color: var(--bad); }
.option .ones { color: var(--ink); }
.option .mirror { display: inline-block; transform: scaleX(-1); }

.hint-area { margin: 16px 0; min-height: 10px; }
.abacus { width: 100%; max-width: 520px; margin: 0 auto; display: block; }

.controls { margin-top: 8px; }
.speak-btn {
  font-size: 1.6rem; background: #eef1f8; border: none; border-radius: 12px;
  padding: 10px 16px; cursor: pointer;
}

/* Summary */
.big-stars { font-size: 2.2rem; font-weight: 800; margin: 10px 0; }
.record-banner { font-size: 1.8rem; font-weight: 800; color: var(--accent); margin: 10px 0; }
.bar { background: #e0e0e0; border-radius: 10px; overflow: hidden; height: 26px; margin: 14px 0; }
.bar > span { display: block; height: 100%; background: var(--good); }

/* Scores tables */
table { width: 100%; border-collapse: collapse; margin-top: 8px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
tr.me { background: #fff8e1; }
.rank { width: 44px; font-weight: 800; }
.val { text-align: right; font-weight: 700; }

/* Settings */
.game-config { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.game-config h3 { margin: 0 0 4px; }
.game-desc { margin: 0 0 10px; font-size: 0.9rem; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.field-row label { margin: 0; }
.range-inputs { display: flex; align-items: center; gap: 8px; }
.range-inputs input { width: 90px; }
.switch input { width: auto; transform: scale(1.4); }

/* Fireworks canvas overlay */
#fireworks {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 5;
}

@media (min-width: 520px) {
  .options { grid-template-columns: repeat(2, 1fr); }
}
