:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6d6c66;
  --border: #e3e1da;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --highlight: rgba(47, 111, 94, 0.08);
  --radius: 16px;

  /* Layout scale (mobile first). --chrome is the vertical space used by
     everything except the reel, so the reel takes what is left. */
  --max-w: 560px;
  --pad-x: 16px;
  --gap: 24px;
  --chrome: 386px;
  --item-h: clamp(64px, calc((100dvh - var(--chrome)) / 3), 120px);
  --topic-size: clamp(1.05rem, 5vw, 1.4rem);
  --card-w: 96px;
  --card-h: 92px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1f1f1d;
    --text: #efeee9;
    --muted: #9a9890;
    --border: #2f2f2c;
    --accent: #6cc3a8;
    --accent-text: #0f1f1a;
    --highlight: rgba(108, 195, 168, 0.10);
  }
}

/* Tablet */
@media (min-width: 700px) {
  :root {
    --max-w: 820px;
    --pad-x: 32px;
    --gap: 28px;
    --chrome: 416px;
    --item-h: clamp(84px, calc((100dvh - var(--chrome)) / 3), 200px);
    --topic-size: 2.5rem;
    --card-w: 104px;
    --card-h: 96px;
  }
}

/* Desktop */
@media (min-width: 1100px) {
  :root {
    --max-w: 1040px;
    --pad-x: 40px;
    --gap: 32px;
    --chrome: 436px;
    --item-h: clamp(90px, calc((100dvh - var(--chrome)) / 3), 170px);
    --topic-size: 2.5rem;
    --card-w: 112px;
    --card-h: 100px;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* Pinned to the viewport: the page itself can never scroll or bounce. */
.app {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  /* The extra 16px at the bottom holds the support line (.support). */
  padding: max(24px, env(safe-area-inset-top)) var(--pad-x) calc(max(20px, env(safe-area-inset-bottom)) + 16px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
}

.header { text-align: center; }

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (min-width: 700px) {
  h1 { font-size: 1.75rem; }
  .subtitle { font-size: 1rem; }
}

/* ---- Slot machine ---- */
.machine {
  display: grid;
  align-content: center;
  min-height: 0;
}

.window {
  position: relative;
  height: calc(var(--item-h) * 3);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 70%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 70%, transparent 100%);
}

@media (min-width: 700px) {
  .window { border-radius: 24px; }
}

.highlight {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--item-h);
  height: var(--item-h);
  background: var(--highlight);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  pointer-events: none;
}

.reel {
  list-style: none;
  margin: 0;
  padding: 0;
  will-change: transform;
}

.reel li {
  height: var(--item-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 max(20px, 5%);
  text-align: center;
  font-size: min(var(--topic-size), calc(var(--item-h) * 0.27));
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: -0.01em;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* At rest the neighbors fade back so the chosen topic is the only focus. */
.reel:not(.spinning) li:not(:nth-child(2)) { opacity: 0.4; }

.reel li.placeholder { color: var(--muted); font-weight: 400; }

.reel.spinning li { filter: blur(0.6px); }

.reel li.landed { animation: pop 320ms ease-out; }

@keyframes pop {
  0% { transform: scale(0.96); }
  60% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* ---- Controls ---- */
.controls {
  min-width: 0;
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 820px;
  justify-self: center;
}

.field { display: grid; gap: 8px; min-width: 0; }

.field-head {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 28px;
}

.field-label,
.field-value {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-value {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

/* Arrow buttons: only on devices with a mouse */
.nav {
  display: none;
  gap: 6px;
}

@media (hover: hover) and (pointer: fine) {
  .nav { display: flex; }
}

.nav button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.nav button:hover { color: var(--text); border-color: var(--muted); }

/* Category cards: one swipeable row */
.cards {
  --fade: 24px;
  position: relative; /* offsetParent for cards, so centering math is local */
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 var(--fade);
  padding: 6px var(--fade) 8px;
  margin: 0 calc(var(--pad-x) * -1);
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
}

@media (min-width: 700px) {
  .cards { --fade: 40px; margin: 0 -40px; }
}

.cards::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 auto;
  width: var(--card-w);
  height: var(--card-h);
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: center;
  align-items: center;
  gap: 4px;
  padding: 12px 8px 8px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  scroll-snap-align: start;
  transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.card-icon {
  font-size: 1.6rem;
  line-height: 1;
  transition: transform 200ms ease;
}

.card-name {
  font-size: 0.75rem;
  line-height: 1.2;
  text-align: center;
  color: var(--muted);
}

@media (min-width: 700px) {
  .card-icon { font-size: 1.75rem; }
  .card-name { font-size: 0.8rem; }
}

.card:hover { border-color: var(--muted); }

.card[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--highlight);
  box-shadow: 0 0 0 1px var(--accent) inset;
  transform: translateY(-3px);
}

.card[aria-checked="true"] .card-name { color: var(--text); font-weight: 600; }
.card[aria-checked="true"] .card-icon { transform: scale(1.15); }

.card:disabled { cursor: default; }

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.spin {
  height: 56px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

@media (min-width: 700px) {
  .spin { height: 60px; font-size: 1.15rem; width: min(100%, 360px); justify-self: center; }
}

.spin:active { transform: scale(0.98); }
.spin:disabled { opacity: 0.6; cursor: default; }

.spin:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* Support link: sits in the bottom padding of .app (outside the grid, counted in
   --chrome), so it never shifts the reel or the controls. */
.support {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(max(20px, env(safe-area-inset-bottom)) - 8px);
  margin: 0;
  text-align: center;
  font-size: 11px;
  line-height: 14px;
  color: var(--muted);
}

.support a {
  color: inherit;
  text-underline-offset: 2px;
}

.support a:hover { color: var(--accent); }

/* Short screens (landscape phones, small laptops) */
@media (max-height: 640px) {
  :root { --gap: 14px; --chrome: 316px; --card-h: 76px; }
  .subtitle { display: none; }
  .card { padding-top: 8px; }
  .card-icon { font-size: 1.4rem; }
}

/* Landscape phones: not enough height for a column, so reel left, controls right. */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --max-w: 100%;
    --pad-x: 24px;
    --gap: 20px;
    --item-h: clamp(56px, calc((100dvh - 48px) / 3), 120px);
    --topic-size: 1.3rem;
    --card-h: 76px;
  }
  .app {
    padding: 16px max(var(--pad-x), env(safe-area-inset-right)) 16px max(var(--pad-x), env(safe-area-inset-left));
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  }
  .header { display: none; }
  .support { display: none; }
  .controls { align-content: center; }
  .cards { --fade: 16px; margin: 0; }
  .spin { width: 100%; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .reel li.landed { animation: none; }
  .card, .card-icon { transition: none; }
}
