/* ------------------------------------------------------------------
   Riso / mechanical. Cream stock, black ink, hard offset shadows,
   halftone screen, split-flap clock. Light only, by design.
   ------------------------------------------------------------------ */

@font-face {
  font-family: 'Bagel Fat One';
  src: url('./fonts/bagelfatone-latin.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Archivo';
  src: url('./fonts/archivo-latin.woff2') format('woff2');
  font-weight: 100 900; font-style: normal; font-display: swap;
}

:root {
  --paper:   #F2F0E9;
  --card:    #EFECE3;
  --ink:     #1A1A18;
  --orange:  #D9541E;
  --orange-d:#B8410F;
  --cobalt:  #1E42A0;
  --mustard: #E5AF1F;
  --oxblood: #7A1F26;

  --edge: 3px;
  --drop: 6px;
  --r: 14px;

  --display: 'Bagel Fat One', Georgia, serif;
  --ui: 'Archivo', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', sans-serif;

  /* flip tile geometry — one place to resize the whole clock */
  --tile-w: 62px;
  --tile-h: 92px;
  --tile-fs: 74px;
  --tile-inner: calc(var(--tile-h) - var(--edge) * 2);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100svh;
  overflow-x: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* halftone dot screen over the whole page ------------------------- */
.halftone {
  position: fixed; inset: 0; z-index: 5;
  pointer-events: none;
  background-image: radial-gradient(var(--ink) 0.5px, transparent 0.6px);
  background-size: 4px 4px;
  opacity: 0.08;
}

.shell {
  position: relative; z-index: 2;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 22px 20px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100svh;
}

/* masthead -------------------------------------------------------- */
.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 30px;
  line-height: 0.94;
  letter-spacing: -0.01em;
}
.wordmark em {
  font-style: normal;
  color: var(--orange);
}

.icon-btn {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: var(--card);
  color: var(--ink);
  border: var(--edge) solid var(--ink);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }

/* mode toggle ----------------------------------------------------- */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: var(--card);
  border: var(--edge) solid var(--ink);
  border-radius: 999px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 5px;
}

.mode {
  font-family: var(--ui);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 12px 8px;
  min-height: 46px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
}
.mode[aria-checked="true"] {
  background: var(--cobalt);
  color: var(--paper);
}
.mode:focus-visible,
.icon-btn:focus-visible,
.btn:focus-visible,
.lever:focus-visible,
.step:focus-visible,
.scholar:focus-visible {
  outline: 3px solid var(--mustard);
  outline-offset: 2px;
}

/* topic-area dropdown — a native <select> on purpose: on iOS this opens
   the system wheel picker, which beats any custom menu on a phone and is
   accessible for free. */
.areawrap { margin-top: -6px; }
.areawrap[hidden] { display: none; }

.area {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-family: var(--ui);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background-color: var(--card);
  border: var(--edge) solid var(--ink);
  border-radius: 999px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 13px 44px 13px 20px;
  min-height: 50px;
  cursor: pointer;
  /* chevron, inline so it survives the offline cache */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231A1A18' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 17px 17px;
}
.area:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; }
.area:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }

.blurb {
  margin: -8px 0 0;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  opacity: 0.72;
}

/* the topic ticket ------------------------------------------------ */
.ticket {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  display: flex;
}

/* riso misregistration — an orange plate printed slightly off */
.ticket::before {
  content: '';
  position: absolute;
  inset: 0;
  transform: translate(-7px, -7px);
  background: var(--orange);
  border: var(--edge) solid var(--ink);
  border-radius: var(--r);
  opacity: 0.9;
}

.ticket-body {
  position: relative;
  z-index: 1;
  flex: 1;
  background: var(--card);
  border: var(--edge) solid var(--ink);
  border-radius: var(--r);
  box-shadow: var(--drop) var(--drop) 0 var(--ink);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.stage {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange-d);
}
.stage[data-tone="deep"]  { color: var(--oxblood); }
.stage[data-tone="speak"] { color: var(--cobalt); }

.topic {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(30px, 9.2vw, 46px);
  line-height: 1.04;
  letter-spacing: -0.015em;
  overflow-wrap: break-word;
  hyphens: auto;
}

.topic.stamp { animation: stamp .34s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes stamp {
  0%   { transform: scale(1.14) rotate(-1.4deg); opacity: 0; }
  60%  { transform: scale(0.985) rotate(0.4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* each tick of the reel: the next topic slides up into place, blurred
   and dimmed, so a fast cycle reads as one moving strip rather than
   twelve separate words */
.topic.reeling { animation: reel-step 95ms ease-out both; }
@keyframes reel-step {
  from { transform: translateY(34%) scale(.95); opacity: .18; filter: blur(2px); }
  to   { transform: translateY(0)   scale(1);   opacity: .9;  filter: blur(0); }
}

.scholar {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--paper);
  background: var(--cobalt);
  text-decoration: none;
  padding: 9px 14px;
  min-height: 40px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
}
.scholar svg {
  width: 15px; height: 15px;
  fill: none; stroke: currentColor; stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
}
.scholar:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
/* display:inline-flex would otherwise beat the [hidden] default */
.scholar[hidden] { display: none; }

/* split-flap clock ------------------------------------------------ */
.clockwrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.clock {
  display: flex;
  align-items: center;
  gap: 7px;
  filter: drop-shadow(5px 5px 0 var(--ink));
}

/* two square pips rather than a typographic colon — reads mechanical */
.colon {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  height: var(--tile-h);
  padding: 0 1px;
}
.colon i { width: 9px; height: 9px; background: var(--ink); display: block; }

.flip {
  position: relative;
  width: var(--tile-w);
  height: var(--tile-h);
  perspective: 420px;
  border: var(--edge) solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  overflow: hidden;
}

/* the hinge line across the middle */
.flip::after {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--paper);
  opacity: 0.28;
  z-index: 6;
  pointer-events: none;
}

.flap {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flap span {
  font-family: var(--ui);
  font-weight: 700;
  font-size: var(--tile-fs);
  line-height: var(--tile-inner);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.flap.top    { top: 0; align-items: flex-start; }
/* the lower flap shows the BOTTOM half of the glyph: same full-height line
   box, pulled up by half of it, then clipped by overflow */
.flap.bottom { bottom: 0; align-items: flex-start; }
.flap.bottom span { transform: translateY(-50%); }

.fold, .unfold { visibility: hidden; z-index: 4; }
.fold   { transform-origin: 50% 100%; }
.unfold { transform-origin: 50% 0%; transform: rotateX(90deg); }

.flip.go .fold,
.flip.go .unfold { visibility: visible; }
.flip.go .fold   { animation: fold   .13s ease-in    forwards; }
.flip.go .unfold { animation: unfold .13s .13s ease-out forwards; }

@keyframes fold   { from { transform: rotateX(0deg); }   to { transform: rotateX(-90deg); } }
@keyframes unfold { from { transform: rotateX(90deg); }  to { transform: rotateX(0deg); } }

/* the last ten seconds turn the tiles orange */
.clock.urgent .flap { background: var(--orange); }
.clock.urgent .flip  { background: var(--orange); }

/* progress bar ---------------------------------------------------- */
.bar {
  width: 100%;
  height: 22px;
  background: var(--card);
  border: var(--edge) solid var(--ink);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--ink);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--orange);
  border-right: var(--edge) solid var(--ink);
  transition: width .25s linear;
}
.bar-fill[data-empty="1"] { border-right-width: 0; }

/* controls -------------------------------------------------------- */
.controls {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.btn {
  flex: 1 1 auto;
  font-family: var(--ui);
  font-size: 16px;
  font-weight: 700;
  color: var(--paper);
  background: var(--ink);
  border: var(--edge) solid var(--ink);
  border-radius: var(--r);
  box-shadow: var(--drop) var(--drop) 0 var(--ink);
  padding: 15px 18px;
  min-height: 56px;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, opacity .15s ease;
}
.btn:active:not(:disabled) { transform: translate(4px, 4px); box-shadow: 2px 2px 0 var(--ink); }
.btn:disabled {
  opacity: 0.34;
  cursor: not-allowed;
  background: var(--card);
  color: var(--ink);
}
.btn-blue { background: var(--cobalt); color: var(--paper); }

/* the lever, borrowed from the cash register */
.lever {
  position: relative;
  flex: 0 0 auto;
  min-width: 132px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: var(--ui);
  font-size: 17px;
  font-weight: 700;
  color: var(--paper);
  background: var(--orange);
  border: var(--edge) solid var(--ink);
  border-radius: var(--r);
  box-shadow: var(--drop) var(--drop) 0 var(--ink);
  padding: 15px 18px;
  cursor: pointer;
  transition: transform .07s ease, box-shadow .07s ease;
}
.lever-knob {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--mustard);
  border: 2.5px solid var(--ink);
  transition: transform .18s cubic-bezier(.3, 1.6, .5, 1);
}
.lever:active:not(:disabled) {
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0 var(--ink);
}
.lever:active:not(:disabled) .lever-knob { transform: translateY(6px) rotate(-28deg); }

/* held down for the length of the spin */
.lever:disabled {
  cursor: default;
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0 var(--ink);
  background: var(--orange-d);
}
.lever:disabled .lever-knob { transform: translateY(6px) rotate(-28deg); }

.foot {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.45;
}

/* settings -------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(26, 26, 24, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.panel-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 30px;
}
.panel-note { margin: 4px 0 0; font-size: 13px; opacity: 0.7; }

.overlay > .sheet {
  position: static;
  width: 100%;
  max-width: 400px;
  height: auto;
  overflow: visible;
  background: var(--paper);
  color: var(--ink);
  border: var(--edge) solid var(--ink);
  border-radius: 18px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  backface-visibility: visible;
}

.setgroup { display: flex; flex-direction: column; gap: 9px; }
.setgroup h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--orange-d);
}

.stepper {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 7px 10px;
}
.stepper-label { font-size: 15px; font-weight: 600; }
.stepper-val {
  min-width: 62px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.step {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-family: var(--ui);
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  color: var(--paper);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 9px;
  cursor: pointer;
}
.step:active { transform: translateY(2px); }
.step:disabled { opacity: 0.3; cursor: not-allowed; }

.mute {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.mute input {
  width: 22px; height: 22px;
  accent-color: var(--orange);
  cursor: pointer;
}

/* wider screens --------------------------------------------------- */
@media (min-width: 560px) {
  :root { --tile-w: 76px; --tile-h: 112px; --tile-fs: 92px; }
  .wordmark { font-size: 38px; }
  .shell { padding-top: 34px; gap: 22px; }
}

@media (max-width: 359px) {
  :root { --tile-w: 52px; --tile-h: 78px; --tile-fs: 62px; }
  .lever { min-width: 112px; }
}

/* reduced motion — no flips, no stamp ----------------------------- */
@media (prefers-reduced-motion: reduce) {
  .flip.go .fold,
  .flip.go .unfold { animation: none; visibility: hidden; }
  .topic.stamp,
  .topic.reeling { animation: none; }
  .lever-knob { transition: none; }
  .bar-fill { transition: none; }
}
