:root {
  --snap-ink: #102131;
  --snap-blue: #1479bd;
  --snap-blue-dark: #0d4f80;
  --snap-orange: #e76f2e;
  --snap-orange-dark: #9c3f13;
  --snap-card-radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: #e8f0f4; color: var(--snap-ink); font-family: Arial, Helvetica, sans-serif; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .46; }

.maths-snap-app { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }
.maths-snap-page { min-height: 0; padding: 10px 14px 12px; }
#mathsSnapHost { height: 100%; }
.maths-snap { height: 100%; min-height: 0; display: grid; grid-template-rows: auto auto minmax(230px, 1fr) auto auto; gap: 8px; }

.maths-snap-toolbar { display: flex; align-items: end; gap: 10px; min-width: 0; }
.maths-snap-toolbar label { display: grid; gap: 3px; color: #314b5d; font-size: .76rem; font-weight: 800; letter-spacing: .02em; }
.maths-snap-toolbar select { min-height: 38px; padding: 5px 32px 5px 10px; border: 2px solid #9bb4c4; border-radius: 8px; background: #fff; color: var(--snap-ink); font-weight: 800; }
.maths-snap-toolbar label:nth-child(1) select { min-width: 88px; }
.maths-snap-toolbar label:nth-child(2) select { min-width: 150px; }
.maths-snap-toolbar label:nth-child(3) select { min-width: 132px; }
.maths-snap-toolbar label:nth-child(4) select { min-width: 166px; }
.maths-snap-toolbar select:focus-visible, .maths-snap button:focus-visible { outline: 3px solid #f3bb2f; outline-offset: 2px; }
.maths-snap-fallback { margin: 0 0 5px; color: #73420d; font-size: .85rem; font-weight: 700; }
.maths-snap-print-worksheet { min-height: 38px; margin-left: auto; padding: 5px 13px; border: 2px solid #087eaf; border-radius: 8px; background: #fff; color: #075b7f; font-weight: 900; white-space: nowrap; }

.maths-snap-scorebar { display: grid; grid-template-columns: minmax(120px, 1fr) auto auto minmax(120px, 1fr); align-items: center; gap: 12px; min-height: 42px; padding: 5px 10px; border: 1px solid #c1d1db; border-radius: 10px; background: #fff; text-align: center; }
.maths-snap-score { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: .96rem; }
.maths-snap-score span, .maths-snap-pot span { display: inline-grid; min-width: 34px; min-height: 30px; place-items: center; border-radius: 7px; color: #fff; font-size: 1.12rem; }
.maths-snap-score--one span { background: var(--snap-blue-dark); }
.maths-snap-score--two span { background: var(--snap-orange-dark); }
.maths-snap-pot span { background: #354658; }

.maths-snap-table { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 86px minmax(0, 1fr); align-items: stretch; gap: 12px; }
.maths-snap-card { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; border: 4px solid #fff; border-radius: var(--snap-card-radius); background: #fff; box-shadow: 0 6px 16px rgba(20, 46, 66, .16); }
.maths-snap-card:first-child { border-color: #a9d4ef; }
.maths-snap-card:last-child { border-color: #f2c0a6; }
.maths-snap-card-face { width: 100%; height: 100%; min-height: 0; display: grid; place-items: center; padding: 10px; }
.maths-snap-card-back { display: none; width: min(52%, 180px); aspect-ratio: 3 / 4; place-items: center; border: 7px double rgba(255,255,255,.84); border-radius: 16px; background: repeating-linear-gradient(45deg, rgba(255,255,255,.12) 0 8px, transparent 8px 16px), #243d52; color: #fff; font-size: clamp(3.5rem, 10vw, 7rem); font-weight: 900; }
.maths-snap-card.is-face-down { background: linear-gradient(145deg, #274b64, #11283a); }
.maths-snap-card.is-face-down .maths-snap-card-face { display: none; }
.maths-snap-card.is-face-down .maths-snap-card-back { display: grid; }
.maths-snap-text-face { width: 100%; max-width: 100%; font-size: clamp(4rem, 10vw, 8.5rem); line-height: 1; letter-spacing: -.04em; overflow-wrap: anywhere; text-align: center; text-wrap: balance; }
.maths-snap-text-face.is-long { font-size: clamp(2.25rem, 4vw, 4rem); line-height: 1.08; letter-spacing: -.02em; }
.maths-snap-text-face.is-very-long { font-size: clamp(1.75rem, 3vw, 3.1rem); line-height: 1.12; letter-spacing: 0; }
.maths-snap-model-face > figure { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; margin: 0; display: grid; place-items: center; overflow: hidden; }
.maths-snap-model-face svg { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; overflow: visible; }
.maths-snap-model-face figcaption { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.maths-snap-model-face > .equation-bar-visual { width: 100%; height: 100%; min-height: 0; grid-template-rows: auto minmax(0, 1fr); }
.maths-snap-model-face > .equation-bar-visual .equation-bar-models { height: 100%; min-height: 0; grid-template-rows: minmax(0, 1fr); }
.maths-snap-model-face > .equation-bar-visual .bar-model-figure { min-height: 0; }
.maths-snap-pot-visual { align-self: center; display: grid; place-items: center; min-height: 86px; padding: 9px; border: 2px dashed #8aa1b1; border-radius: 14px; background: rgba(255,255,255,.62); color: #354658; }
.maths-snap-pot-visual span { font-size: 2rem; font-weight: 900; line-height: 1; }
.maths-snap-pot-visual small { font-weight: 800; }

.maths-snap-actions { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(150px, .62fr) minmax(180px, 1fr); gap: 12px; }
.maths-snap-actions button { min-height: 58px; border-radius: 12px; font-weight: 900; }
.maths-snap-claim { display: flex; align-items: center; justify-content: center; gap: 10px; border: 0; color: #fff; font-size: clamp(1.3rem, 2.2vw, 2rem); box-shadow: inset 0 -4px rgba(0,0,0,.18); touch-action: manipulation; }
.maths-snap-claim--one { background: var(--snap-blue-dark); }
.maths-snap-claim--two { background: var(--snap-orange-dark); }
.maths-snap-claim span { font-size: .72em; }
.maths-snap-claim kbd { min-width: 28px; padding: 3px 7px; border: 1px solid rgba(255,255,255,.65); border-radius: 6px; background: rgba(0,0,0,.15); font-size: .65em; }
.maths-snap-decision-actions { display: grid; }
.maths-snap-turn, .maths-snap-no-match, .maths-snap-new { border: 2px solid #334a5c; background: #fff; color: var(--snap-ink); font-size: 1.08rem; }
.maths-snap-turn { background: #f3bb2f; border-color: #75550a; }
.maths-snap-new { background: #dff4e8; border-color: #31734f; }
.maths-snap-feedback { min-height: 42px; margin: 0; display: grid; place-items: center; padding: 7px 12px; border-left: 5px solid #1479bd; border-radius: 7px; background: #fff; font-size: clamp(.9rem, 1.3vw, 1.05rem); font-weight: 700; text-align: center; }
.maths-snap.is-complete .maths-snap-feedback { border-left-color: #31734f; background: #edf9f2; }

@media (max-height: 760px) and (min-width: 800px) {
  .topbar { min-height: 56px; padding-block: 6px; }
  .maths-snap-page { padding-block: 7px; }
  .maths-snap { gap: 6px; }
  .maths-snap-toolbar select { min-height: 34px; }
  .maths-snap-scorebar { min-height: 36px; }
  .maths-snap-actions button { min-height: 50px; }
  .maths-snap-feedback { min-height: 36px; padding-block: 5px; }
}

@media (max-width: 760px) {
  .maths-snap-app { height: auto; min-height: 100vh; overflow: visible; }
  .maths-snap-page { padding: 8px; }
  #mathsSnapHost { height: auto; }
  .maths-snap { min-height: calc(100vh - 64px); grid-template-rows: auto auto auto auto auto; }
  .maths-snap-toolbar { align-items: stretch; flex-direction: column; gap: 7px; }
  .maths-snap-toolbar label { grid-template-columns: 82px minmax(0, 1fr); align-items: center; }
  .maths-snap-fallback { margin: 0; }
  .maths-snap-print-worksheet { width: 100%; margin-left: 0; }
  .maths-snap-scorebar { grid-template-columns: 1fr 1fr; gap: 6px; }
  .maths-snap-table { grid-template-columns: 1fr; grid-template-rows: 250px 54px 250px; gap: 8px; }
  .maths-snap-pot-visual { min-height: 0; grid-auto-flow: column; justify-content: center; gap: 5px; }
  .maths-snap-pot-visual span { font-size: 1.5rem; }
  .maths-snap-actions { grid-template-columns: 1fr 1fr; }
  .maths-snap-decision-actions { grid-column: 1 / -1; grid-row: 1; }
  .maths-snap-claim { font-size: 1.25rem; }
  .maths-snap-claim span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
