/* Counting Money — matches Free Homeschool Games style */

:root {
  --sky-top: #7ec8ea;
  --sky-mid: #c7ecfa;
  --sky-bottom: #f3fbff;
  --navy: #16324f;
  --navy-soft: #2a4a6b;
  --ink: #1a2b3c;
  --paper: #fffdf6;
  --gold: #ffd24a;
  --orange: #ff8a3d;
  --purple: #6c63ff;
  --teal: #1faf9a;
  --correct: #2db86a;
  --correct-dark: #1d8a4b;
  --miss: #e8a317;
  --shadow: 0 8px 0 rgba(22, 50, 79, 0.12);
  --font: "Trebuchet MS", "Segoe UI", "Avenir Next", "Avenir", system-ui, sans-serif;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--sky-bottom) 100%);
  background-attachment: fixed;
}

body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button, input { font-family: inherit; }

button { cursor: pointer; }

h1, h2, p { margin: 0; }

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin: 0 auto;
}

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

.brand { display: flex; align-items: center; gap: 10px; }

.home-link { display: grid; place-items: center; text-decoration: none; }
.site-mark { width: 44px; height: 44px; border-radius: 14px; display: block; }

.site-name { margin: 0; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.02em; }
.site-name a { color: var(--navy-soft); text-decoration: none; }
.site-name a:hover { text-decoration: underline; }

.brand h1 {
  font-size: clamp(1.15rem, 3vw, 1.6rem);
  color: var(--navy);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.tagline { font-size: 0.9rem; color: var(--navy-soft); font-weight: 700; }

.toggle {
  border: 3px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  min-height: 44px;
}
.toggle[aria-pressed="true"] { background: #e8ffe8; }

.screen { flex: 1; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

.card, .start-card, .end-card, .play-card {
  background: var(--paper);
  border: 3px solid var(--navy);
  border-radius: 28px;
  padding: 22px 20px 24px;
  box-shadow: var(--shadow);
}

.start-card, .end-card { width: 100%; margin: 0 auto; }

h2 { color: var(--navy); font-size: clamp(1.4rem, 3.5vw, 1.9rem); margin-bottom: 8px; }

.lead { font-size: 1.05rem; line-height: 1.45; font-weight: 600; margin-bottom: 16px; }

.label {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy-soft);
  margin: 14px 0 8px;
}

.player-row, .chip-row, .preset-row, .mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.player-pill, .chip, .preset, .mode-btn {
  border: 3px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
  min-height: 44px;
  box-shadow: 0 4px 0 rgba(22, 50, 79, 0.1);
}

.player-pill[aria-pressed="true"],
.chip[aria-pressed="true"],
.preset[aria-pressed="true"],
.mode-btn[aria-pressed="true"] {
  background: var(--gold);
}

.player-pill .edit {
  border: 0;
  background: transparent;
  padding: 0 0 0 6px;
  min-height: 0;
  font-size: 1rem;
  box-shadow: none;
}

.add-player { background: #e8ffe8; }

.preset, .mode-btn { border-radius: 16px; }
.mode-btn { flex: 1; min-width: 180px; text-align: left; }
.mode-btn .mode-title { display: block; font-size: 1.1rem; }
.mode-btn .mode-desc { display: block; font-size: 0.88rem; font-weight: 700; opacity: 0.9; }

.custom-panel {
  margin-top: 8px;
  padding: 8px 0 0;
}

.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  border: 3px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  border-radius: 14px;
  padding: 8px 12px;
  font-weight: 800;
  min-height: 44px;
}
.choice[aria-pressed="true"] { background: #d9fff3; }

.table-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.table-chips .chip { min-width: 48px; padding: 8px 10px; }

.summary { font-weight: 700; color: var(--navy-soft); margin: 10px 0 0; }

.start-btn, .primary, .secondary {
  border: 3px solid var(--navy);
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 800;
  font-size: 1.08rem;
  min-height: 52px;
  box-shadow: var(--shadow);
}
.start-btn, .primary { background: var(--orange); color: #fff; width: 100%; margin-top: 16px; }
.secondary { background: var(--paper); color: var(--navy); }

.start-btn:disabled, .primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.best-note { margin-top: 12px; font-weight: 700; color: var(--navy-soft); }

/* Play */
.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}
.stat, .prompt-box, .linkish {
  background: var(--paper);
  border: 3px solid var(--navy);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px 12px;
}
.stat { min-width: 86px; text-align: center; }
.stat .label { margin: 0; }
.stat .value { font-size: 1.55rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat.timer.warn .value { color: #d97706; }
.stat.timer.danger .value { color: #dc2626; }
.linkish { font-weight: 800; color: var(--navy); min-height: 64px; }

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

.fact-line {
  text-align: center;
  font-size: clamp(2.2rem, 10vw, 3.6rem);
  font-weight: 800;
  color: var(--navy);
  letter-spacing: 0.02em;
  line-height: 1.15;
  min-height: 1.3em;
}
.fact-line.ok { color: var(--correct-dark); }
.fact-line.teach { color: var(--navy); }

.answer-box {
  border: 3px solid var(--navy);
  border-radius: 18px;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  color: var(--navy);
  background: #fff;
  letter-spacing: 0.04em;
}
.answer-box.ok { background: #e8ffe8; border-color: var(--correct-dark); }
.answer-box.teach { background: #fff6d9; }

.feedback {
  min-height: 1.4em;
  text-align: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--navy-soft);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}
.key {
  border: 3px solid var(--navy);
  background: #fff;
  color: var(--navy);
  border-radius: 16px;
  font-size: 1.7rem;
  font-weight: 800;
  min-height: 60px;
  box-shadow: 0 5px 0 rgba(22, 50, 79, 0.12);
}
.key:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(22, 50, 79, 0.12); }
.key.wide { font-size: 1.2rem; }
.key.enter { background: var(--teal); color: #fff; }
.key.back { background: #f3efe4; }

/* End */
.score-big {
  font-size: clamp(2.4rem, 8vw, 3.8rem);
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
  margin: 8px 0 4px;
  text-align: center;
}
.end-card { text-align: center; }
.end-card .lead, .end-card .best-note { text-align: center; }

.missed-box {
  text-align: left;
  background: #fff7e8;
  border: 2px solid #f0d3a0;
  border-radius: 16px;
  padding: 12px 14px;
  margin: 14px 0 18px;
  max-height: 240px;
  overflow: auto;
}
.missed-box h3 { margin: 0 0 8px; color: var(--navy); font-size: 1rem; }
.missed-box ul { margin: 0; padding: 0 0 0 18px; columns: 2; gap: 12px; }
.missed-box li { margin: 0 0 4px; font-weight: 700; break-inside: avoid; }

.end-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.end-actions .primary, .end-actions .secondary { width: auto; margin-top: 0; }

.site-foot {
  margin: 12px 0 0;
  text-align: center;
  font-weight: 700;
  color: var(--navy);
  font-size: 0.92rem;
}
.site-foot a { color: var(--navy); }

.dialog-back {
  position: fixed;
  inset: 0;
  background: rgba(22, 50, 79, 0.35);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}
.dialog-back[hidden] { display: none !important; }
.dialog {
  background: var(--paper);
  border: 3px solid var(--navy);
  border-radius: 24px;
  padding: 20px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
}
.dialog h2 { margin-bottom: 10px; }
.dialog input {
  width: 100%;
  border: 3px solid var(--navy);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-actions .primary, .dialog-actions .secondary { min-height: 44px; padding: 8px 14px; font-size: 1rem; }

@media (min-width: 800px) and (min-height: 560px) {
  .play-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: center;
  }
  .fact-side { text-align: center; }
}

@media (max-width: 520px) {
  .missed-box ul { columns: 1; }
  .mode-btn { min-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .key, .start-btn { transition: none; }
}


/* Clock */

.pile {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 10px;
  min-height: 140px;
  margin: 8px 0 12px;
  padding: 10px 8px;
  background: #f4f0e4;
  border: 2px dashed #d8c9a0;
  border-radius: 16px;
}
.money-item {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  border-radius: 10px;
}
.money-item:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }
.money-item svg { display: block; pointer-events: none; }
.money-item.is-coin svg { width: var(--coin-size, 64px); height: var(--coin-size, 64px); }
.money-item.is-bill svg { width: var(--bill-w, 112px); height: var(--bill-h, 52px); }
.money-item.is-penny { --coin-size: 58px; }
.money-item.is-nickel { --coin-size: 64px; }
.money-item.is-dime { --coin-size: 52px; }
.money-item.is-quarter { --coin-size: 74px; }
.money-item.is-half { --coin-size: 80px; }
.money-item.is-dollar-coin { --coin-size: 72px; }
.money-item.is-bill-1 { --bill-w: 108px; --bill-h: 50px; }
.money-item.is-bill-5 { --bill-w: 112px; --bill-h: 52px; }
.money-item.is-bill-10 { --bill-w: 116px; --bill-h: 54px; }
.money-item.is-bill-20 { --bill-w: 120px; --bill-h: 56px; }

.prompt-line {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--navy);
  text-align: center;
  margin: 0 0 8px;
}
.tender-note {
  margin: 0 0 8px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.98rem;
}
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.choice-btn {
  appearance: none;
  border: 2px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  font: inherit;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 0.7rem 0.6rem;
  border-radius: 14px;
  cursor: pointer;
}
.choice-btn:hover { background: #ffe08a; }
.choice-btn.correct { background: var(--correct); color: #fff; }
.choice-btn.wrong { background: #ef5a5a; color: #fff; }
.choice-btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.choices[hidden] { display: none !important; }

.bank {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 8px 0;
}
.bank-btn {
  appearance: none;
  border: 2px solid #c9bd9a;
  background: #fffdf6;
  border-radius: 14px;
  padding: 6px 8px 8px;
  cursor: pointer;
  min-width: 72px;
  color: var(--navy);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bank-btn:hover { border-color: var(--navy); background: #fff6d6; }
.bank-btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.bank-btn .bank-label { line-height: 1.15; }
.running {
  text-align: center;
  font-weight: 800;
  color: var(--navy);
  margin: 4px 0 8px;
  font-size: 1.05rem;
}
.tray-label {
  margin: 8px 0 0;
  font-weight: 800;
  color: var(--navy);
  font-size: 0.92rem;
}
.check-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  appearance: none;
  border: 0;
  background: var(--orange);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  cursor: pointer;
}
.check-btn:hover { filter: brightness(1.05); }
.check-btn[hidden] { display: none !important; }
.feedback { min-height: 1.4em; text-align: center; font-weight: 700; margin: 8px 0 0; }
.feedback.ok { color: #1c7a3a; }
.feedback.bad { color: #b42318; }
.mode-btn[aria-pressed="true"],
.choice[aria-pressed="true"] {
  background: var(--gold);
  border-color: var(--navy);
  color: var(--navy);
}

@media (max-width: 520px) {
  .choices { grid-template-columns: 1fr 1fr; }
  .money-item.is-penny { --coin-size: 50px; }
  .money-item.is-nickel { --coin-size: 56px; }
  .money-item.is-dime { --coin-size: 46px; }
  .money-item.is-quarter { --coin-size: 64px; }
  .money-item.is-bill-1, .money-item.is-bill-5, .money-item.is-bill-10, .money-item.is-bill-20 {
    --bill-w: 96px; --bill-h: 46px;
  }
}
