:root {
  --ink: #1b2430;
  --paper: #f6f3ea;
  --card: #fffdf8;
  --muted: #5c6673;
  --line: #d9d0bf;
  --add: #c62828;
  --add-soft: #fde8e8;
  --sub: #2e7d32;
  --sub-soft: #e8f6ea;
  --mul: #1565c0;
  --mul-soft: #e6f0fb;
  --div: #00838f;
  --div-soft: #e4f6f7;
  --shadow: 0 10px 24px rgba(40, 28, 12, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #fff4d6 0%, transparent 40%),
    radial-gradient(circle at 90% 10%, #dcefff 0%, transparent 36%),
    var(--paper);
}

body {
  min-height: 100dvh;
}

a { color: inherit; }

.wrap {
  width: min(920px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand small {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--muted);
}

.brand strong {
  font-size: 22px;
}

.home-link {
  text-decoration: none;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  box-shadow: 0 2px 0 #cfc4af;
}

.hero {
  background: var(--card);
  border: 2px solid #eadfcb;
  border-radius: 28px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 42px);
}

.hero p {
  margin: 0;
  font-size: 18px;
  color: var(--muted);
  max-width: 46ch;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.game-card {
  display: block;
  text-decoration: none;
  background: var(--card);
  border: 3px solid #eadfcb;
  border-radius: 24px;
  padding: 20px;
  min-height: 210px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.game-card:hover { transform: translateY(-3px); }

.game-card.live { border-color: #f3b23a; }
.game-card.stub {
  background: repeating-linear-gradient(
    -12deg,
    #fffdf8,
    #fffdf8 12px,
    #f4efe4 12px,
    #f4efe4 13px
  );
  opacity: 0.92;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 9px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.badge.play { background: #ffe08a; }
.badge.soon { background: #e6e1d6; color: #6a6356; }

.game-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.ops-page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.score-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.pill {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.pane {
  background: var(--card);
  border: 3px solid #eadfcb;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.pane-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

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

.op-btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  min-height: 86px;
  color: #fff;
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,0.18);
  transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.08s ease;
}

.op-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.op-btn:disabled { cursor: default; }

.op-btn.add { background: var(--add); }
.op-btn.sub { background: var(--sub); }
.op-btn.mul { background: var(--mul); }
.op-btn.div { background: var(--div); }

.answer-btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  min-height: 86px;
  background: #243044;
  color: #fff;
  font-family: inherit;
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,0.18);
  transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.08s ease;
}

.answer-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.answer-btn:disabled { cursor: default; }

.op-btn.flash-good,
.answer-btn.flash-good {
  animation: good 0.45s ease 0s 4 alternate;
}

.op-btn.flash-bad,
.answer-btn.flash-bad {
  animation: bad 0.35s ease 0s 3 alternate;
}

@keyframes good {
  from { filter: brightness(1); box-shadow: 0 0 0 0 rgba(46, 125, 50, 0.1); }
  to { filter: brightness(1.35); background: #22c55e; box-shadow: 0 0 0 8px rgba(34, 197, 94, 0.25); }
}

@keyframes bad {
  from { filter: brightness(1); }
  to { filter: brightness(1.2); background: #ef4444; box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.28); }
}

.word-pane {
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.word {
  font-size: clamp(34px, 8vw, 64px);
  line-height: 1.1;
  margin: 0;
  text-transform: lowercase;
}

.word-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.problem-pane {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.problem {
  margin: 0;
  font-size: clamp(20px, 4.4vw, 30px);
  line-height: 1.35;
  text-align: center;
}

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-top: 12px;
}

@media (max-width: 640px) {
  .ops { grid-template-columns: repeat(2, 1fr); }
  .op-btn, .answer-btn { min-height: 74px; }
  .word-pane { min-height: 110px; }
  .problem-pane { min-height: 150px; }
}

.add-page .wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.add-sheet {
  width: min(480px, 100%);
  margin: 0 auto;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 36px;
  padding: 22px 18px 18px;
  box-shadow: var(--shadow);
}

.add-title {
  margin: 0 0 18px;
  text-align: center;
  font-size: 32px;
}

.add-board {
  position: relative;
  display: grid;
  grid-template-columns: 52px repeat(4, minmax(0, 1fr));
  grid-template-areas:
    ".    c1000 c100 c10 c1"
    ".    a1000 a100 a10 a1"
    "plus b1000 b100 b10 b1"
    "rule rule  rule rule rule"
    ".    s1000 s100 s10 s1";
  column-gap: 8px;
  row-gap: 8px;
  font-variant-numeric: tabular-nums;
}

.add-plus {
  align-self: center;
  justify-self: center;
  color: var(--add);
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
}

.add-rule {
  position: relative;
  z-index: 1;
  height: 4px;
  align-self: center;
  background: var(--ink);
  border-radius: 2px;
}

.add-cell {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  font-size: clamp(24px, 5.4vw, 34px);
  font-weight: 900;
  line-height: 1;
}

.add-cell.carry {
  width: 74%;
  justify-self: center;
  align-self: center;
  background: #e0e0e0;
  border-color: #bdbdbd;
  font-size: clamp(18px, 4vw, 26px);
}

.add-cell.carry.ghost {
  visibility: hidden;
}

.add-cell.carry.landed {
  animation: carry-land 0.35s ease;
}

@keyframes carry-land {
  from { transform: scale(0.55); background: #ffe08a; }
  to { transform: scale(1); background: #e0e0e0; }
}

.add-rect {
  position: absolute;
  z-index: 0;
  box-sizing: border-box;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: rgba(255, 196, 60, 0.42);
  pointer-events: none;
  transition: top 0.35s ease, left 0.35s ease, width 0.35s ease, height 0.35s ease;
}

.tens-part.flying {
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background: #fffdf8;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 10px 18px rgba(27, 36, 48, 0.25);
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
}

.add-status {
  margin: 14px 0 8px;
  min-height: 1.3em;
  text-align: center;
  font-weight: 800;
  color: var(--muted);
}

.add-answers {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 3px solid var(--ink);
}

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

.add-answers[hidden],
.add-choices[hidden],
.add-correct[hidden],
.add-rect[hidden] {
  display: none !important;
}

.add-choice {
  appearance: none;
  min-width: 0;
  min-height: 68px;
  border: 2px solid #7eafd4;
  border-radius: 14px;
  background: #d6ebfa;
  color: var(--ink);
  font-family: inherit;
  font-size: clamp(22px, 5vw, 32px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(27, 36, 48, 0.14);
  touch-action: manipulation;
}

.add-choice:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(27, 36, 48, 0.14);
}

.add-choice:disabled { cursor: default; }

.add-choice:focus-visible,
.add-correct:focus-visible {
  outline: 3px solid #f3b23a;
  outline-offset: 2px;
}

.add-choice.flash-good {
  animation: choice-good 0.28s ease 0s 2 alternate;
}

.add-choice.flash-bad {
  animation: choice-bad 0.22s ease 0s 2 alternate;
}

@keyframes choice-good {
  from { background: #d6ebfa; color: var(--ink); }
  to { background: #22c55e; color: #fff; box-shadow: 0 0 0 8px rgba(34, 197, 94, 0.28); }
}

@keyframes choice-bad {
  from { background: #d6ebfa; color: var(--ink); }
  to { background: #ef4444; color: #fff; box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.28); }
}

.add-correct {
  appearance: none;
  width: 100%;
  min-height: 84px;
  border: 0;
  border-radius: 16px;
  background: #2e7d32;
  color: #fff;
  font-family: inherit;
  font-size: 32px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #1b5e20;
  touch-action: manipulation;
}

.add-correct.show {
  animation: add-pop 0.28s ease;
}

.add-correct:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #1b5e20;
}

@keyframes add-pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (max-width: 640px) {
  .add-sheet { border-radius: 28px; padding: 16px 12px 14px; }
  .add-title { font-size: 28px; margin-bottom: 12px; }
  .add-board { grid-template-columns: 36px repeat(4, minmax(0, 1fr)); column-gap: 6px; row-gap: 6px; }
  .add-plus { font-size: 44px; }
  .add-cell { border-radius: 10px; }
  .add-choice { min-height: 58px; border-radius: 12px; }
  .add-choices { gap: 8px; }
}

@media (max-width: 360px) {
  .add-page .wrap { padding: 12px 0 8px; }
  .add-sheet { padding: 12px 8px 10px; }
  .add-title { margin-bottom: 8px; }
  .add-choice { min-height: 52px; }
  .add-status { margin: 8px 0 4px; }
  .add-answers { padding-top: 10px; }
  .add-page .footer-note { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .add-cell.carry.landed,
  .add-correct.show { animation: none; }
  .add-rect { transition: none; }
}
