/* ==========================================================
   Math Streak! — notebook paper, crayon-bright operators,
   big chunky keys sized for small fingers.
   ========================================================== */

:root {
  --paper:        #FFFBF2;
  --grid:         #D9E8F5;
  --margin-line:  #F4A3A3;
  --ink:          #24324A;
  --ink-soft:     #5B6B85;
  --white:        #FFFFFF;

  /* one crayon per operation */
  --add:      #FF6B4A;  --add-dark: #C9472B;
  --sub:      #2F9BFF;  --sub-dark: #1C6FC0;
  --mul:      #2BB673;  --mul-dark: #1B8552;
  --div:      #A66CFF;  --div-dark: #7A45CF;

  --sun:      #FFC93C;  --sun-dark: #D9A21A;
  --wrong:    #E5484D;
  --right:    #2BB673;

  --font-display: 'Lilita One', 'Arial Rounded MT Bold', sans-serif;
  --font-body:    'Nunito', 'Trebuchet MS', sans-serif;

  --radius:    22px;
  --ease-pop:  cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:  cubic-bezier(0.2, 0.8, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--ink);
  min-height: 100dvh;
  background-color: var(--paper);
  /* graph paper + red margin line */
  background-image:
    linear-gradient(90deg, transparent 54px, var(--margin-line) 54px, var(--margin-line) 56px, transparent 56px),
    linear-gradient(var(--grid) 1.5px, transparent 1.5px),
    linear-gradient(90deg, var(--grid) 1.5px, transparent 1.5px);
  background-size: 100% 100%, 32px 32px, 32px 32px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--sun); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---------- Corner controls ---------- */
.home-link {
  position: absolute; top: 12px; left: 66px; z-index: 5;
  font-size: 0.85rem; font-weight: 800; color: var(--ink-soft);
  text-decoration: none; padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.8);
}
.home-link:hover { color: var(--ink); }

.sound-toggle {
  position: absolute; top: 10px; right: 12px; z-index: 5;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--white); font-size: 1.3rem;
  box-shadow: 0 3px 0 var(--grid), 0 4px 10px rgba(36,50,74,0.12);
}

/* ---------- Screens ---------- */
.screen {
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: 64px 16px 32px 68px;  /* left pad clears the margin line */
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  animation: screenIn 0.45s var(--ease-out);
}
@media (max-width: 480px) {
  body {
    background-image:
      linear-gradient(var(--grid) 1.5px, transparent 1.5px),
      linear-gradient(90deg, var(--grid) 1.5px, transparent 1.5px);
    background-size: 28px 28px, 28px 28px;
  }
  .screen { padding-left: 16px; }
  .home-link { left: 12px; }
}

/* ---------- Title ---------- */
.title { text-align: center; line-height: 0.85; margin-top: 4px; }
.title__small {
  display: inline-block; font-family: var(--font-display);
  font-size: clamp(1.8rem, 7vw, 2.4rem); color: var(--sub);
  transform: rotate(-4deg); text-shadow: 0 3px 0 var(--sub-dark);
}
.title__big {
  display: block; font-family: var(--font-display);
  font-size: clamp(4rem, 17vw, 6rem); color: var(--add);
  letter-spacing: 0.01em;
  text-shadow: 0 5px 0 var(--add-dark), 0 10px 18px rgba(201,71,43,0.25);
}
.title__bang { display: inline-block; color: var(--sun); text-shadow: 0 5px 0 var(--sun-dark); animation: wiggle 2.4s ease-in-out infinite; }

.tagline { text-align: center; color: var(--ink-soft); font-size: 1.05rem; line-height: 1.45; }

/* ---------- Panels ---------- */
.panel {
  width: 100%; background: var(--white); border-radius: var(--radius);
  padding: 18px 18px 20px; border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
}
.panel__heading {
  display: block; font-family: var(--font-display); font-weight: 400;
  font-size: 1.35rem; text-align: center; margin-bottom: 12px;
}

/* ---------- Operation chips ---------- */
.ops { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 400px) { .ops { grid-template-columns: repeat(2, 1fr); } }

.op-chip {
  --c: var(--add); --cd: var(--add-dark);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 8px; border-radius: 18px;
  background: var(--paper); border: 3px dashed #C8D3E0; color: #9AA8BC;
  transition: transform 160ms var(--ease-pop), background 160ms, color 160ms;
}
.op-chip--sub { --c: var(--sub); --cd: var(--sub-dark); }
.op-chip--mul { --c: var(--mul); --cd: var(--mul-dark); }
.op-chip--div { --c: var(--div); --cd: var(--div-dark); }

.op-chip__sym { font-family: var(--font-display); font-size: 2.6rem; line-height: 1; }
.op-chip__label { font-size: 0.8rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em; }

.op-chip[aria-pressed="true"] {
  background: var(--c); color: var(--white); border: 3px solid var(--cd);
  box-shadow: 0 5px 0 var(--cd); transform: translateY(-3px);
}
.op-chip:active { transform: translateY(2px); box-shadow: none; }
.shake { animation: shake 0.35s; }

.ops-hint { min-height: 1.2em; margin-top: 10px; text-align: center; font-size: 0.9rem; color: var(--ink-soft); }
.ops-hint.warn { color: var(--wrong); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-display); font-size: 1.6rem; letter-spacing: 0.02em;
  padding: 14px 34px; border-radius: 999px; color: var(--white);
  transition: transform 140ms var(--ease-pop), box-shadow 140ms;
}
.btn--go { background: var(--mul); box-shadow: 0 6px 0 var(--mul-dark), 0 12px 20px rgba(27,133,82,0.3); }
.btn--go:hover { transform: translateY(-2px); }
.btn--go:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--mul-dark); }
.btn--ghost { background: var(--white); color: var(--ink); border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink); font-size: 1.25rem; padding: 10px 24px; }
.btn--ghost:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn--save { background: var(--sub); box-shadow: 0 5px 0 var(--sub-dark); font-size: 1.3rem; padding: 10px 22px; }
.btn--save:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--sub-dark); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.best-line { min-height: 1.2em; color: var(--ink-soft); font-size: 0.95rem; }

/* ---------- Leaderboard ---------- */
.board { list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.board__item {
  display: grid; grid-template-columns: 2.4rem 1fr auto auto; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 14px; background: var(--paper);
}
.board__item--you { background: #FFF1C2; outline: 3px solid var(--sun); outline-offset: -3px; animation: pop 0.5s var(--ease-pop); }
.board__rank { font-family: var(--font-display); font-size: 1.15rem; text-align: center; color: var(--ink-soft); }
.board__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.board__ops { display: flex; gap: 3px; }
.board__op {
  width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 0.85rem; color: var(--white); line-height: 1;
}
.board__op--add { background: var(--add); }
.board__op--sub { background: var(--sub); }
.board__op--mul { background: var(--mul); }
.board__op--div { background: var(--div); }
.board__score { font-family: var(--font-display); font-size: 1.35rem; min-width: 2.5ch; text-align: right; }
.board__empty { text-align: center; color: var(--ink-soft); padding: 10px; }

/* ---------- HUD ---------- */
.screen--play { gap: 14px; padding-top: 58px; }
.hud { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.hud__streak { display: flex; align-items: baseline; gap: 6px; }
.hud__flame { font-size: 1.8rem; align-self: center; }
.hud__count { font-family: var(--font-display); font-size: 2.6rem; line-height: 1; color: var(--add); text-shadow: 0 3px 0 var(--add-dark); }
.hud__count.bump { animation: bump 0.4s var(--ease-pop); }
.hud__label { color: var(--ink-soft); font-size: 0.95rem; }
.hud__level {
  font-family: var(--font-display); font-size: 1.1rem; color: var(--ink);
  background: var(--sun); padding: 6px 14px; border-radius: 999px;
  box-shadow: 0 4px 0 var(--sun-dark);
}
.hud__level.bump { animation: bump 0.6s var(--ease-pop); }

/* ---------- Problem card (index card look) ---------- */
.card-stage { position: relative; width: 100%; }
.problem-card {
  --c: var(--add); --cd: var(--add-dark);
  position: relative; width: 100%;
  background:
    linear-gradient(transparent 0 46px, var(--c) 46px 50px, transparent 50px),
    repeating-linear-gradient(transparent 0 37px, #E3ECF7 37px 39px) 0 50px / 100% calc(100% - 50px) no-repeat,
    var(--white);
  border-radius: var(--radius); border: 3px solid var(--ink);
  box-shadow: 8px 8px 0 var(--cd);
  padding: 70px 14px 18px; min-height: 210px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: rotate(-1deg);
  transition: box-shadow 200ms;
}
.problem-card.op-sub { --c: var(--sub); --cd: var(--sub-dark); transform: rotate(0.8deg); }
.problem-card.op-mul { --c: var(--mul); --cd: var(--mul-dark); transform: rotate(-0.6deg); }
.problem-card.op-div { --c: var(--div); --cd: var(--div-dark); transform: rotate(1deg); }
.problem-card.deal { animation: deal 0.4s var(--ease-out); }
.problem-card.right { animation: rightPop 0.35s var(--ease-pop); }
.problem-card.wrong { animation: shake 0.45s; box-shadow: 8px 8px 0 var(--wrong); }

.problem {
  display: flex; align-items: center; justify-content: center; flex-wrap: nowrap; gap: 0.25em;
  font-family: var(--font-display); line-height: 1;
  font-size: clamp(2.6rem, 13vw, 4.4rem);
}
.problem.long { font-size: clamp(2rem, 9.5vw, 3.4rem); }
.problem__op { color: var(--c); }
.problem__eq { color: var(--ink-soft); }
.problem__answer {
  min-width: 1.6em; padding: 0.06em 0.18em 0.1em; border-radius: 14px;
  border: 4px dashed #B9C6D8; text-align: center; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
}
.problem__answer.filled { border-style: solid; border-color: var(--c); }
.problem-card.right .problem__answer { background: #D9F7E7; border-color: var(--right); color: var(--mul-dark); }
.problem-card.wrong .problem__answer { background: #FDE2E3; border-color: var(--wrong); color: var(--wrong); }

.caret { width: 4px; height: 0.8em; background: var(--c); border-radius: 2px; margin-left: 2px; animation: blink 1s steps(2) infinite; }
.problem__answer.filled .caret,
.locked .caret { display: none; }

.feedback { min-height: 1.6em; margin-top: 12px; font-size: 1.15rem; font-weight: 900; text-align: center; }
.feedback.good { color: var(--mul-dark); }
.feedback.bad { color: var(--wrong); }

/* celebration emoji burst */
.burst { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.burst span { position: absolute; left: 50%; top: 45%; font-size: 1.8rem; animation: fly 0.9s var(--ease-out) forwards; }

/* ---------- Number pad ---------- */
.pad { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.key {
  font-family: var(--font-display); font-size: 2.1rem; line-height: 1;
  height: clamp(56px, 9dvh, 74px); border-radius: 18px;
  background: var(--white); color: var(--ink);
  border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  transition: transform 80ms, box-shadow 80ms, background 120ms;
  touch-action: manipulation; user-select: none;
}
.key:active, .key.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); background: #F1F6FC; }
.key--back { background: #FFE7E0; font-size: 1.7rem; }
.key--enter { background: var(--mul); color: var(--white); font-size: 2.2rem; }
.key--enter:active, .key--enter.pressed { background: var(--mul-dark); }
.pad.disabled .key { pointer-events: none; opacity: 0.6; }

.quit-link { margin-top: 6px; color: var(--ink-soft); font-size: 0.9rem; text-decoration: underline; padding: 6px; }

/* ---------- Game over ---------- */
.screen--over { gap: 16px; }
.over__title { font-family: var(--font-display); font-weight: 400; font-size: clamp(2.4rem, 10vw, 3.4rem); color: var(--sub); text-shadow: 0 4px 0 var(--sub-dark); text-align: center; }
.over__score { display: flex; flex-direction: column; align-items: center; }
.over__num {
  font-family: var(--font-display); font-size: clamp(6rem, 28vw, 9rem); line-height: 0.9;
  color: var(--add); text-shadow: 0 7px 0 var(--add-dark), 0 14px 26px rgba(201,71,43,0.25);
  animation: pop 0.6s var(--ease-pop);
}
.over__label { font-family: var(--font-display); font-size: 1.6rem; color: var(--ink); }
.over__best { min-height: 1.2em; font-size: 1.05rem; color: var(--ink-soft); text-align: center; }
.over__best.new { color: var(--sun-dark); font-weight: 900; font-size: 1.2rem; }

.miss {
  width: 100%; text-align: center; background: var(--white); border: 3px dashed var(--wrong);
  border-radius: var(--radius); padding: 12px 16px;
}
.miss__heading { color: var(--ink-soft); font-size: 0.95rem; }
.miss__problem { font-family: var(--font-display); font-size: 2.2rem; margin: 2px 0; }
.miss__problem strong { color: var(--mul); font-weight: 400; }
.miss__yours { color: var(--ink-soft); }
.miss__yours s { color: var(--wrong); text-decoration-thickness: 3px; }

.submit-row { display: flex; gap: 10px; }
.submit-row input {
  flex: 1; min-width: 0; font: 800 1.2rem var(--font-body); color: var(--ink);
  padding: 10px 14px; border-radius: 14px; border: 3px solid var(--ink); background: var(--paper);
}
.submit-msg { min-height: 1.2em; margin-top: 8px; text-align: center; color: var(--ink-soft); }
.submit-msg.ok { color: var(--mul-dark); }
.submit-msg.err { color: var(--wrong); }

.over__actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 14px; }

/* ---------- Animations ---------- */
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(12deg); } 92% { transform: rotate(-8deg); } }
@keyframes shake { 0%, 100% { translate: 0; } 20% { translate: -10px; } 40% { translate: 9px; } 60% { translate: -6px; } 80% { translate: 4px; } }
@keyframes bump { 0% { scale: 1; } 40% { scale: 1.35; } 100% { scale: 1; } }
@keyframes pop { 0% { scale: 0.6; opacity: 0; } 100% { scale: 1; opacity: 1; } }
@keyframes deal { from { opacity: 0; translate: 60px 0; } to { opacity: 1; translate: 0; } }
@keyframes rightPop { 0% { scale: 1; } 45% { scale: 1.05; } 100% { scale: 1; } }
@keyframes blink { to { opacity: 0; } }
@keyframes fly {
  0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2) rotate(var(--rot)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
