:root {
  --ink-0: #0b1015;
  --ink-1: #121920;
  --ink-2: #1b242d;
  --text: #ebe7df;
  --muted: #8b97a2;
  --faint: rgba(235, 231, 223, 0.08);
  --mist: #a9c9e5;
  --mist-ink: #0e1924;
  --yes: #5aa882;
  --no: #d06a6c;
  --glow-yes: 125, 219, 176;
  --glow-no: 255, 142, 134;
  --glow-boost: 140, 198, 255;

  --display: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif;
  --ui: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --wheel: clamp(236px, min(100vw - 32px, 100svh - 376px), 620px);

  color-scheme: dark;
}

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

html {
  background: var(--ink-1);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: clip;
  color: var(--text);
  font: 400 15px/1.45 var(--ui);
  background:
    radial-gradient(ellipse 72% 58% at 50% 47%, var(--ink-2) 0%, rgba(27, 36, 45, 0) 70%),
    linear-gradient(var(--ink-1), var(--ink-0));
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

.app {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* ── header ─────────────────────────────────────────────────────────────── */

.bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: default;
}
.brand .mark { width: 22px; height: 22px; color: var(--mist); }
.brand .word {
  font: italic 500 23px/1 var(--display);
  letter-spacing: 0.01em;
}

.tools { display: flex; gap: 2px; }

/* ── wheel switch ───────────────────────────────────────────────────────── */

.switch {
  order: 3;
  flex-basis: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.seg {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px var(--faint);
}
.seg button {
  position: relative;
  z-index: 1;
  height: 32px;
  padding: 0 15px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 500 13.5px/1 var(--ui);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 0.25s;
}
.seg button[aria-checked="true"] { color: var(--text); }
.seg button:hover:not(:disabled) { color: var(--text); }
.seg button:disabled { cursor: default; }
.seg-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: 0;
  border-radius: 999px;
  background: rgba(169, 201, 229, 0.14);
  box-shadow: inset 0 0 0 1px rgba(169, 201, 229, 0.18);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.slices select {
  height: 38px;
  padding: 0 32px 0 15px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238b97a2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center / 12px;
  box-shadow: inset 0 0 0 1px var(--faint);
  color: var(--text);
  font: 500 13.5px/1 var(--ui);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.slices select option { background: #19222a; color: var(--text); }
.switch :disabled { opacity: 0.45; }
.slices select:disabled { cursor: default; }

@media (min-width: 720px) {
  .switch {
    order: 0;
    position: absolute;
    left: 50%;
    top: 50%;
    flex-basis: auto;
    margin: 0;
    transform: translate(-50%, -50%);
  }
}
.ctl { position: relative; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  opacity: 0.74;
  transition: opacity 0.2s, background-color 0.2s;
}
.icon-btn:hover { opacity: 1; background: rgba(255, 255, 255, 0.05); }
.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn svg .fill { fill: currentColor; }
#sound .i-off { display: none; }
#sound[aria-pressed="false"] .i-on { display: none; }
#sound[aria-pressed="false"] .i-off { display: block; }

:focus-visible { outline: 2px solid var(--mist); outline-offset: 3px; }
.brand:focus-visible, .icon-btn:focus-visible { outline-offset: 0; }

/* ── help ───────────────────────────────────────────────────────────────── */

.help {
  position: absolute;
  top: calc(100% + 2px);
  right: max(12px, env(safe-area-inset-right));
  width: min(300px, calc(100vw - 24px));
  padding: 18px 18px 14px;
  border-radius: 14px;
  background: #19222a;
  box-shadow: 0 0 0 1px var(--faint), 0 18px 48px -12px rgba(0, 0, 0, 0.6);
  user-select: text;
  -webkit-user-select: text;
  animation: pop-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-origin: top right;
}
.help h2 {
  margin: 0 0 8px;
  font: italic 500 20px/1.2 var(--display);
}
.help p { margin: 0 0 8px; color: #c7cdd2; }
.help .legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
.help .sw { width: 10px; height: 10px; border-radius: 3px; }
.help .sw.y { background: var(--yes); }
.help .sw.n { background: var(--no); margin-left: 6px; }
.help .kbd { color: var(--muted); font-size: 13.5px; }
.help .bolt { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.help kbd {
  font: 500 12px var(--ui);
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.08);
}
.ghost {
  margin-top: 4px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(169, 201, 229, 0.12);
  color: var(--mist);
  font-weight: 600;
  cursor: pointer;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
}

/* ── stage ──────────────────────────────────────────────────────────────── */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px max(18px, env(safe-area-inset-bottom));
}

.prompt {
  margin: 0 0 20px;
  color: var(--muted);
  letter-spacing: 0.01em;
  transition: opacity 0.6s ease;
}
.is-spinning .prompt { opacity: 0.35; }

.wheel-wrap {
  position: relative;
  width: var(--wheel);
  height: var(--wheel);
  flex: none;
}
.camera {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}
.wheel-shadow {
  position: absolute;
  inset: -7%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(2, 5, 8, 0.62) 76%, rgba(2, 5, 8, 0.25) 88%, rgba(2, 5, 8, 0) 100%);
  transform: translate(1.8%, 2.6%);
}
.wheel-ambient,
.wheel-halo {
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
  --g: var(--glow-yes);
}
.wheel-wrap[data-glow="N"] .wheel-halo,
.wheel-ambient[data-glow="N"] { --g: var(--glow-no); }
.wheel-wrap[data-glow="B"] .wheel-halo,
.wheel-ambient[data-glow="B"] { --g: var(--glow-boost); }
/* the colour the result spills into the room; fixed so it never adds scroll */
.wheel-ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(circle var(--ar, 420px) at var(--ax, 50%) var(--ay, 50%),
    rgba(var(--g), 0.13), rgba(var(--g), 0.05) 45%, rgba(var(--g), 0) 100%);
}
.wheel-halo { position: absolute; border-radius: 50%; }
/* the boost's full-screen effects: streaks behind the page, bolt / flash / vignette over it */
.fx-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.fx-layer.back { z-index: 0; }
.fx-layer.front { z-index: 40; }
/* a ring of light just outside the rim; --edge is the rim's radius as a share of this box */
.wheel-halo {
  --edge: 77.5%;
  inset: -14%;
  background: radial-gradient(closest-side,
    rgba(var(--g), 0) calc(var(--edge) - 3%),
    rgba(var(--g), 0.5) calc(var(--edge) + 0.6%),
    rgba(var(--g), 0.15) calc(var(--edge) + 8%),
    rgba(var(--g), 0) 100%);
}
.wheel-wrap[data-kind="simple"] .wheel-halo { --edge: 62.5%; }
.wheel-wrap[data-kind="simple"] .wheel-shadow { inset: 4.5%; transform: translate(1%, 2%); }

.camera canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.result {
  display: grid;
  place-items: center;
  height: 62px;
  margin-top: 18px;
}
#result {
  font: 500 44px/1 var(--display);
  letter-spacing: 0.1em;
  padding-left: 0.1em;
  opacity: 0;
  transform: translateY(8px);
  filter: blur(4px);
  transition: opacity 0.7s cubic-bezier(0.2, 0.7, 0.2, 1), transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1), filter 0.7s ease;
}
#result.show { opacity: 1; transform: none; filter: none; }
#result.fade { opacity: 0; transform: translateY(-4px); filter: blur(2px); transition-duration: 0.3s; }
#result[data-v="Y"] { color: var(--yes); }
#result[data-v="N"] { color: var(--no); }

.spin-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  margin-top: 6px;
}
.spin {
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 196px;
  height: 54px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: var(--mist);
  color: var(--mist-ink);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 10px 26px -12px rgba(169, 201, 229, 0.55);
  transition: transform 0.14s ease, background-color 0.35s, color 0.35s, box-shadow 0.35s;
  user-select: none;
  -webkit-user-select: none;
}
.spin svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.spin:hover:not(:disabled) { background: #b6d3ec; }
.spin:hover:not(:disabled) svg { transform: rotate(40deg); }
.spin:active:not(:disabled) { transform: scale(0.975); }
.spin:disabled {
  background: rgba(169, 201, 229, 0.1);
  color: var(--mist);
  box-shadow: none;
  cursor: default;
}
.spin:disabled svg { animation: turn 1.4s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

/* ⚡ — shows up beside the button while a spin can still be boosted */
.boost {
  grid-column: 3;
  justify-self: start;
  position: relative;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-left: 14px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, rgba(169, 201, 229, 0.24), rgba(169, 201, 229, 0.07) 70%);
  box-shadow: inset 0 0 0 1px rgba(169, 201, 229, 0.38), 0 0 24px -6px rgba(var(--glow-boost), 0.7);
  font: 23px/1 "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.55) rotate(-20deg);
  transition: opacity 0.22s, transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.35), visibility 0s 0.4s;
  user-select: none;
  -webkit-user-select: none;
}
.boost::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px rgba(var(--glow-boost), 0.7);
  opacity: 0;
}
.boost.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition: opacity 0.22s, transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.35), visibility 0s;
}
.boost.show::after { animation: boost-ring 1.3s ease-out infinite; }
.boost:hover { background: radial-gradient(circle at 50% 38%, rgba(169, 201, 229, 0.34), rgba(169, 201, 229, 0.1) 70%); }
.boost:active { transform: scale(0.94); }
.boost.used {
  visibility: visible;
  pointer-events: none;
  animation: boost-burst 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
.boost.used::after { animation: none; }
@keyframes boost-ring {
  from { opacity: 0.9; transform: scale(1); }
  to { opacity: 0; transform: scale(1.55); }
}
@keyframes boost-burst {
  0% { opacity: 1; transform: scale(1); filter: brightness(1); }
  35% { opacity: 1; transform: scale(1.45); filter: brightness(1.9) drop-shadow(0 0 14px rgba(140, 198, 255, 0.9)); }
  100% { opacity: 0; transform: scale(1.9); filter: brightness(1.4); }
}

.history {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(var(--wheel), 100%);
  justify-content: center;
  min-height: 28px;
  margin-top: 18px;
}
.history .label {
  flex: none;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  font: 500 11px/1 var(--ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.history .empty { color: rgba(139, 151, 162, 0.6); font-size: 13px; }
#history {
  display: flex;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
}
#history.overflow {
  -webkit-mask-image: linear-gradient(90deg, #000 78%, transparent);
  mask-image: linear-gradient(90deg, #000 78%, transparent);
}
#history:empty { display: none; }
#history li {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font: 600 11.5px/1 var(--ui);
}
#history li.y { color: var(--yes); background: rgba(90, 168, 130, 0.12); box-shadow: inset 0 0 0 1px rgba(90, 168, 130, 0.2); }
#history li.n { color: var(--no); background: rgba(208, 106, 108, 0.12); box-shadow: inset 0 0 0 1px rgba(208, 106, 108, 0.2); }
#history li.new { animation: chip-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1); }
#history.clearing li { animation: chip-out 0.28s cubic-bezier(0.4, 0, 0.8, 0.4) forwards; }
#history.clearing li:nth-child(2) { animation-delay: 0.02s; }
#history.clearing li:nth-child(3) { animation-delay: 0.04s; }
#history.clearing li:nth-child(n+4) { animation-delay: 0.06s; }
@keyframes chip-out {
  to { opacity: 0; transform: translateX(-8px) scale(0.7); }
}
/* reset the row of chips */
.history .clear {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-left: -4px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  opacity: 0.7;
  cursor: pointer;
  transition: opacity 0.2s, background-color 0.2s, color 0.2s;
}
.history .clear:hover { opacity: 1; color: var(--text); background: rgba(255, 255, 255, 0.05); }
.history .clear:active svg { transform: rotate(-60deg); }
.history .clear svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes chip-in {
  from { opacity: 0; transform: translateX(-10px) scale(0.8); }
}

/* ── wheel chooser ──────────────────────────────────────────────────────── */

.chooser {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow-y: auto;
  background: rgba(9, 13, 17, 0.72);
  -webkit-backdrop-filter: blur(14px) saturate(0.9);
  backdrop-filter: blur(14px) saturate(0.9);
  animation: fade-in 0.4s ease;
}
.chooser.leaving { opacity: 0; transition: opacity 0.3s ease; }
.chooser-inner { width: min(560px, 100%); text-align: center; }
.chooser h1 {
  margin: 0 0 22px;
  font: italic 500 30px/1.15 var(--display);
  letter-spacing: 0.005em;
}
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 18px 20px;
  border: 0;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 0 0 1px var(--faint);
  cursor: pointer;
  transition: background-color 0.25s, box-shadow 0.25s, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.choice svg { width: 96px; height: 96px; margin-bottom: 8px; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.choice .txt { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.choice .t { font: italic 500 22px/1.2 var(--display); }
.choice .d { color: var(--muted); font-size: 13.5px; line-height: 1.4; max-width: 22ch; }
.choice:hover {
  background: rgba(169, 201, 229, 0.06);
  box-shadow: inset 0 0 0 1px rgba(169, 201, 229, 0.3);
}
.choice:hover svg { transform: rotate(-24deg); }
.choice:active { transform: scale(0.985); }
.choice:focus-visible { outline-offset: 2px; }
.chooser-note { margin: 18px 0 0; color: rgba(139, 151, 162, 0.75); font-size: 13px; }
@keyframes fade-in { from { opacity: 0; } }

@media (max-width: 460px) {
  .choices { grid-template-columns: 1fr; }
  .choice { flex-direction: row; text-align: left; align-items: center; gap: 16px; padding: 16px 18px; }
  .choice svg { width: 72px; height: 72px; margin: 0; flex: none; }
  .choice .txt { align-items: flex-start; gap: 3px; }
  .chooser h1 { font-size: 26px; }
}

/* ── larger screens ─────────────────────────────────────────────────────── */

@media (min-width: 720px) {
  :root { --wheel: clamp(236px, min(100vw - 32px, 100svh - 332px), 620px); }
  .bar { padding: 18px 26px 6px; }
  .brand .word { font-size: 25px; }
  #result { font-size: 52px; }
  .result { height: 70px; margin-top: 20px; }
  .prompt { font-size: 16px; margin-bottom: 22px; }
}

@media (max-height: 640px) {
  .prompt { margin-bottom: 12px; }
  .result { height: 54px; margin-top: 14px; }
  #result { font-size: 38px; }
  .history { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #result, .spin, .spin svg, .prompt { transition-duration: 0.01s; }
  .spin:disabled svg { animation: none; }
  .boost, .boost.show { transition-duration: 0.01s; }
  .boost.show::after, .boost.used { animation: none; }
  .boost.used { opacity: 0; }
  #history li.new, #history.clearing li, .help, .chooser { animation: none; }
  .choice:hover svg { transform: none; }
}
