@font-face {
  font-family: "Fredoka";
  src: url("vendor/fonts/fredoka.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  /* colour: chocolate ink, cream paper, one caramel accent (Polich's tan markings) */
  --ink: #2b1d14;
  --ink-2: #5d4a3c;
  --surface: #fffaf0;
  --bg: #f6efe0;
  --line: #e4d8c2;
  --accent: #f5a83c;
  --accent-hover: #ffb955;
  --accent-soft: #ffe6bd;
  --tint: rgba(43, 29, 20, .07);
  --placeholder: #7a6858;
  --good: #1f7a45;
  --good-bg: #d9f2e0;
  --good-ink: #114a29;
  --bad: #b3261e;
  --bad-bg: #fbe0dc;
  --bad-ink: #7a1a14;
  --heart: #e5463c;
  /* answer lanes, matched to the gate signs */
  --lane-a: #7cc0f0;
  --lane-b: #f2b552;
  --lane-c: #f58fa8;

  /* spacing: 4px steps */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* radius */
  --r-lg: 24px;
  --r-md: 14px;
  --r-sm: 10px;

  /* sticker edge: every raised surface shares this outline and hard shadow */
  --edge: 3px solid var(--ink);
  --lift: 0 5px 0 var(--ink);
  --lift-sm: 0 3px 0 var(--ink);
  --lift-lg: 0 7px 0 var(--ink);
  --lift-up: 0 9px 0 var(--ink);
  --flat: 0 0 0 var(--ink);

  /* type */
  --t-xs: 13px;
  --t-sm: 15px;
  --t-md: 17px;
  --t-lg: 22px;
  --t-xl: 30px;
  --t-2xl: 26px;
  --t-3xl: 40px;

  --font: "Fredoka", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cfeaf8;
  color: var(--ink);
  font: 400 var(--t-md)/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

h1, h2, h3 { margin: 0; line-height: 1.1; text-wrap: balance; }
h2 { font-size: var(--t-xl); font-weight: 600; }
h3 { font-size: var(--t-md); font-weight: 600; }
p { margin: 0; text-wrap: pretty; }
.num { font-variant-numeric: tabular-nums; }

.lead { color: var(--ink-2); max-width: 36ch; }
.help { color: var(--ink-2); font-size: var(--t-xs); max-width: 60ch; }
.label { font-size: var(--t-sm); font-weight: 600; }

.stack-sm { display: grid; gap: var(--s3); }
.row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* ---- buttons ---- */
.btn {
  font: 600 var(--t-md)/1 var(--font);
  min-height: 48px;
  padding: 0 var(--s5);
  border-radius: var(--r-md);
  border: var(--edge);
  box-shadow: var(--lift-sm);
  cursor: pointer;
  color: var(--ink);
  background: var(--surface);
  transition: transform .12s ease-out, box-shadow .12s ease-out, background-color .12s ease-out;
}
.btn:hover { background: var(--accent-soft); }
.btn:active { transform: translateY(3px); box-shadow: var(--flat); }
.btn:focus-visible, .iconbtn:focus-visible, .ans:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.btn.primary { background: var(--accent); min-height: 60px; font-size: var(--t-2xl); font-weight: 700; box-shadow: var(--lift); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:active { transform: translateY(5px); box-shadow: var(--flat); }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; padding: 0 var(--s3); color: var(--ink-2); min-height: 40px; font-size: var(--t-sm); }
.btn.ghost:hover { color: var(--ink); background: var(--tint); }
.btn.ghost:active { transform: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- title + results screens: wordmark and one card over the live scene ---- */
.title {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: var(--s5);
  padding: var(--s6) var(--s7);
  pointer-events: none;
}
.title > * { pointer-events: auto; }
.wordmark { width: min(430px, 100%); flex: none; }
.wordmark svg { display: block; width: 100%; height: auto; overflow: visible; }
.wm { font: 700 128px var(--font); stroke-linejoin: round; stroke-linecap: round; }
.wm-back { fill: var(--ink); stroke: var(--ink); stroke-width: 26px; }
.wm-front { fill: var(--surface); stroke: var(--ink); stroke-width: 20px; paint-order: stroke fill; }
.wm-front.run { fill: var(--accent); }

.card {
  width: min(400px, 100%);
  min-height: 0;
  background: var(--surface);
  border: var(--edge);
  border-radius: var(--r-lg);
  box-shadow: var(--lift-lg);
  padding: var(--s5);
  display: grid;
  gap: var(--s4);
  overflow-y: auto;
}
.facts { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: var(--s5); }
.facts.three { grid-template-columns: repeat(3, auto); justify-content: space-between; align-items: end; }
.facts dt { font-size: var(--t-xs); color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; }
.facts .big { font-size: var(--t-3xl); font-weight: 700; line-height: 1; }

.missed { list-style: none; margin: var(--s3) 0 0; padding: 0; display: grid; gap: var(--s4); }
.missed li { font-size: var(--t-sm); color: var(--ink-2); }
.missed strong { display: block; color: var(--good); font-size: var(--t-md); font-weight: 600; margin-top: var(--s1); }

@media (max-width: 760px) {
  .title { justify-content: space-between; align-items: center; padding: var(--s4) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom)); }
  .wordmark { width: min(300px, 72vw); margin-top: env(safe-area-inset-top); }
  .card { width: 100%; max-width: 460px; max-height: 58dvh; padding: var(--s4); gap: var(--s3); }
  #over { justify-content: flex-end; }
  #home .help { display: none; }
  #home .lead { font-size: var(--t-sm); }
}
@media (max-height: 600px) {
  .title { padding-top: var(--s3); padding-bottom: var(--s4); gap: var(--s3); }
  .wordmark { width: 210px; }
  .card { padding: var(--s4); gap: var(--s3); }
  #home .lead, #home .help { display: none; }
}
@media (max-height: 600px) and (min-width: 560px) {
  #home .stack-sm { grid-template-columns: 1fr 1fr; align-items: center; }
  #home .btn.primary { min-height: 52px; }
  #home .btn.secondary { min-height: 52px; padding: 0 var(--s3); font-size: var(--t-sm); }
}

/* ---- notes editor ---- */
.sheet { position: fixed; inset: 0; background: var(--bg); display: grid; grid-template-rows: auto 1fr; }
.sheet-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s5) calc(var(--s3) + 3px);
  background: var(--surface);
  border-bottom: var(--edge);
}
.sheet-head h2 { font-size: var(--t-lg); }
.sheet-head .btn.primary { min-height: 48px; font-size: var(--t-md); font-weight: 600; box-shadow: var(--lift-sm); }
.sheet-head .btn.primary:active { transform: translateY(3px); }
.sheet-grid {
  overflow-y: auto;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: var(--s7);
  padding: var(--s6) var(--s5) var(--s7);
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}
.col { display: grid; gap: var(--s3); min-width: 0; }

textarea, input[type="text"] {
  font: 400 var(--t-sm)/1.45 var(--font);
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
  width: 100%;
}
textarea::placeholder { color: var(--placeholder); }
#notesText { min-height: 44dvh; resize: vertical; padding: var(--s4); border: var(--edge); border-radius: var(--r-md); }
.col .btn.primary { min-height: 48px; font-size: var(--t-md); font-weight: 600; box-shadow: var(--lift-sm); }
.col .btn.primary:active { transform: translateY(3px); }

.status { font-size: var(--t-sm); font-weight: 600; min-height: 1.45em; }
.status.bad { color: var(--bad); }
.status.good { color: var(--good); }
.empty { color: var(--ink-2); padding: var(--s6) 0; }
.skipbox summary { font-size: var(--t-sm); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.skipbox ul { list-style: none; margin: var(--s3) 0 0; padding: 0; display: grid; gap: var(--s3); max-height: 40dvh; overflow-y: auto; }
.skipbox li { display: grid; gap: 2px; font-size: var(--t-xs); }
.skip-text { font-weight: 600; overflow-wrap: anywhere; }
.skip-why { color: var(--ink-2); }

.qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s6); }
.qitem { display: grid; grid-template-columns: 28px 1fr; gap: var(--s2); align-items: start; }
.qitem .n { color: var(--ink-2); font-weight: 600; font-size: var(--t-sm); padding-top: var(--s2); }
.qitem textarea { resize: none; font-weight: 600; font-size: var(--t-md); field-sizing: content; min-height: 44px; }
.qitem .opts { grid-column: 2; display: grid; gap: var(--s1); }
.opt { display: grid; grid-template-columns: 28px 1fr; align-items: center; }
.opt input[type="radio"] { width: 20px; height: 20px; margin: 0; accent-color: var(--good); cursor: pointer; }
.opt.correct input[type="text"] { border-color: var(--good); background: var(--good-bg); font-weight: 600; }
.qitem .remove { grid-column: 2; justify-self: start; margin-left: var(--s4); }

@media (max-width: 860px) {
  .sheet-grid { grid-template-columns: 1fr; gap: var(--s6); padding: var(--s5) var(--s4) var(--s7); }
  #notesText { min-height: 30dvh; }
  .sheet-head { padding: var(--s2) var(--s3) calc(var(--s2) + 3px); gap: var(--s2); grid-template-columns: auto 1fr; }
  .sheet-head h2 { display: none; }
  .sheet-head #btnPlayDeck { justify-self: end; }
}

/* ---- HUD ---- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(var(--s3) + env(safe-area-inset-top)) var(--s4) 0;
}
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; display: block; }
.hearts { display: flex; gap: var(--s1); color: var(--heart); }
.heart { width: 34px; height: 34px; fill: currentColor; stroke: var(--ink); stroke-width: 2.4; transition: transform .2s ease-out; }
.heart.lost { fill: var(--surface); opacity: .75; transform: scale(.82); }
.scorebox {
  display: flex; align-items: baseline; gap: var(--s2);
  background: var(--surface);
  border: var(--edge);
  box-shadow: var(--lift-sm);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s4);
  font-weight: 700; font-size: var(--t-2xl); line-height: 1;
}
.streak { font-size: var(--t-sm); font-weight: 600; color: var(--good); }
.hud-btns { display: flex; gap: var(--s2); justify-content: flex-end; }
.iconbtn {
  width: 46px; height: 46px; border-radius: var(--r-md);
  border: var(--edge); box-shadow: var(--lift-sm);
  background: var(--surface); color: var(--ink); cursor: pointer;
  display: grid; place-items: center;
  transition: transform .12s ease-out, box-shadow .12s ease-out;
}
.iconbtn:active { transform: translateY(3px); box-shadow: var(--flat); }

.qcard {
  margin: var(--s4) auto 0;
  width: min(calc(100% - 2 * var(--s4)), 680px);
  background: var(--surface);
  border: var(--edge);
  box-shadow: var(--lift);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s5);
  display: grid; gap: var(--s3);
  animation: drop .2s ease-out;
}
#qtext { font-size: var(--t-lg); font-weight: 600; line-height: 1.25; text-wrap: balance; }
#qtext.long { font-size: var(--t-md); }
.qbar { height: var(--s2); border-radius: var(--s1); background: var(--line); overflow: hidden; }
.qbar i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.qresult { font-weight: 600; font-size: var(--t-md); }
.qresult.good { color: var(--good); }
.qresult.bad { color: var(--bad); }

.tip {
  position: absolute; left: 50%; top: 20%;
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 2 * var(--s4));
  background: var(--ink); color: var(--surface);
  padding: var(--s2) var(--s4); border-radius: var(--r-md);
  font-size: var(--t-sm); font-weight: 500; text-align: center;
}

.answers {
  position: absolute; left: 50%; bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 2 * var(--s3)), 780px);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2);
  align-items: stretch;
  animation: rise .2s ease-out;
}
.ans {
  font: 500 var(--t-sm)/1.25 var(--font);
  color: var(--ink);
  background: var(--surface);
  border: var(--edge);
  box-shadow: var(--lift-sm);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s2) var(--s3);
  display: grid; gap: var(--s1); justify-items: center; align-content: start;
  text-align: center; cursor: pointer;
  min-height: 84px;
  transition: transform .15s ease-out, background-color .15s ease-out, box-shadow .15s ease-out;
}
.ans .letter {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--ink);
  font-size: var(--t-sm); font-weight: 700; line-height: 1;
}
.ans:nth-child(1) .letter { background: var(--lane-a); }
.ans:nth-child(2) .letter { background: var(--lane-b); }
.ans:nth-child(3) .letter { background: var(--lane-c); }
.ans .txt { overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.ans.here { background: var(--accent-soft); transform: translateY(-6px); box-shadow: var(--lift-up); }
.ans.right { background: var(--good-bg); color: var(--good-ink); }
.ans.wrong { background: var(--bad-bg); color: var(--bad-ink); }
@media (min-width: 700px) { .ans { font-size: var(--t-md); } }

@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

.iconbtn.corner { position: fixed; z-index: 2; top: calc(var(--s3) + env(safe-area-inset-top)); right: var(--s4); }

.info-btn { position: fixed; z-index: 2; right: var(--s4); bottom: calc(var(--s4) + env(safe-area-inset-bottom)); }
.fb-btn { right: calc(var(--s4) + 46px + var(--s2)); text-decoration: none; }
#about .dialog { gap: var(--s4); }
#about .dialog p { color: var(--ink-2); }
#about .btn.primary { min-height: 52px; font-size: var(--t-lg); }
#about .stack-sm { margin-top: var(--s2); }

/* ---- pause ---- */
.overlay { position: fixed; inset: 0; z-index: 10; background: rgba(43, 29, 20, .55); display: grid; place-items: center; padding: var(--s4); }
.dialog { background: var(--surface); border: var(--edge); box-shadow: var(--lift-lg); border-radius: var(--r-lg); padding: var(--s6); width: min(100%, 340px); display: grid; gap: var(--s5); }

/* ---- share-image mode (?shot) ---- */
.shot .card, .shot .iconbtn { display: none; }
.shot .wordmark { width: 500px; }
.face .wordmark { display: none; }

/* ---- support ---- */
.btn.small { min-height: 44px; font-size: var(--t-sm); padding: 0 var(--s3); }
.extras { flex-wrap: wrap; }
.extras .btn { white-space: nowrap; flex-basis: 140px; }
#bugText { resize: vertical; min-height: 120px; }
#bugTrap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.dialog.support { width: min(100%, 380px); gap: var(--s4); max-height: 100%; overflow-y: auto; padding: var(--s5); }
.dialog.support > p:not(.help) { color: var(--ink-2); }
.qr { display: block; width: min(100%, 250px); height: auto; margin: 0 auto; border: var(--edge); border-radius: var(--r-md); background: #fff; }
a.btn { display: grid; place-items: center; text-decoration: none; }
.dialog.support .btn.primary { min-height: 52px; font-size: var(--t-lg); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
