/* Wheel. The look is tokens on :root (and on :root[data-look]); nothing below hard-codes a color that belongs to a look. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tile-font: "Roboto Condensed", "Arial Narrow", "Helvetica Neue", Roboto, Arial, sans-serif;
  /* the settings page (always dark navy) */
  --bg: #07122e; --panel: #0e1d44; --panel2: #162a5c; --text: #eaf0ff; --muted: #93a4cf; --line: #25397a; --danger: #ff9a8a;
  --accent: #ffcc33; --accent-ink: #2b1a00; --col: 680px;
  /* the stage: default look */
  --stage-a: #0b2a6b; --stage-b: #040c24;
  --frame-a: #ffe27a; --frame-b: #a8700a;
  --board-bg: #05172f;
  --off-a: #0c3f7a; --off-b: #072a55; --off-edge: rgba(120,170,255,.22);
  --lit-a: #ffffff; --lit-b: #cfd8e8; --lit-ink: #0b1020; --blank-a: #fbfcff; --blank-b: #d3dbea;
  --plate-a: #2a6df0; --plate-b: #0a2f85; --plate-ink: #ffffff; --plate-edge: #ffe27a;
  --glow: rgba(255, 214, 90, .55);
  --readout: #ffe27a;
  color-scheme: dark;
}
:root[data-look="classic"] {
  --stage-a: #0b4a2c; --stage-b: #02140b;
  --board-bg: #031a0e;
  --off-a: #0f6a3a; --off-b: #08482a; --off-edge: rgba(150,255,190,.2);
  --plate-a: #168a4c; --plate-b: #07502b;
  --glow: rgba(150, 255, 190, .5);
}
:root[data-look="quiet"] {
  --stage-a: #000; --stage-b: #000;
  --frame-a: #3a3f4a; --frame-b: #1b1e25;
  --board-bg: #05060a;
  --off-a: #0b0e15; --off-b: #080a10; --off-edge: rgba(255,255,255,.04);
  --lit-a: #2a3142; --lit-b: #1e2432; --lit-ink: #d4dcf0; --blank-a: #161b27; --blank-b: #111520;
  --plate-a: #151a26; --plate-b: #0d111a; --plate-ink: #9aa7c4; --plate-edge: #2a3142;
  --glow: rgba(150, 170, 220, .25);
  --readout: #8f9bb8;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
body.is-stage { position: fixed; inset: 0; overflow: hidden; background: #000; overscroll-behavior: none; touch-action: manipulation; }
body.is-stage #app { position: fixed; inset: 0; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-boot { padding: 2rem; color: var(--muted); }
.app-icon { flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- the stage ---------- */
.stage { position: absolute; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  background: radial-gradient(120% 90% at 50% 18%, var(--stage-a), var(--stage-b) 70%); }
.stage-inner { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: var(--pad, 12px); padding: var(--pad, 12px); transition: transform 8s ease-in-out; }
.stage[data-orient="portrait"] .stage-inner { flex-direction: column; }
.panel { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
.stage[data-scene="board"] .wheel-panel, .stage[data-scene="clock"] .wheel-panel, .stage[data-scene="wheel"] .board-panel { display: none; }
.stage.night-minimal .panel { visibility: hidden; }

/* the board */
.board-wrap { display: flex; flex-direction: column; align-items: center; }
.board { display: grid; gap: calc(var(--tile) * .09); padding: calc(var(--tile) * .3); border-radius: calc(var(--tile) * .3);
  background: var(--board-bg); border: calc(var(--tile) * .08) solid transparent;
  background-image: linear-gradient(var(--board-bg), var(--board-bg)), linear-gradient(135deg, var(--frame-a), var(--frame-b) 50%, var(--frame-a));
  background-origin: border-box; background-clip: padding-box, border-box;
  box-shadow: 0 0 calc(var(--tile) * 1.2) rgba(0,0,0,.65), 0 0 calc(var(--tile) * .5) var(--glow); transition: box-shadow .8s; }
.board-row { display: flex; justify-content: center; gap: calc(var(--tile) * .09); }
.tile { position: relative; display: grid; place-items: center; width: var(--tile); height: calc(var(--tile) * 1.25); border-radius: calc(var(--tile) * .12);
  font-family: var(--tile-font); font-weight: 800; font-size: calc(var(--tile) * .84); line-height: 1; color: var(--lit-ink); backface-visibility: hidden; }
.tile-ch { transform: translateY(.02em); }
.tile.off { background: linear-gradient(var(--off-a), var(--off-b)); box-shadow: inset 0 0 0 1px var(--off-edge); }
.tile.off .tile-ch { visibility: hidden; }
.tile.letter, .tile.blank { box-shadow: inset 0 calc(var(--tile) * .05) calc(var(--tile) * .06) rgba(255,255,255,.9), inset 0 calc(var(--tile) * -.06) calc(var(--tile) * .08) rgba(60,80,120,.35), 0 calc(var(--tile) * .03) calc(var(--tile) * .05) rgba(0,0,0,.5); }
.tile.letter { background: linear-gradient(var(--lit-a), var(--lit-b)); }
.tile.blank { background: linear-gradient(var(--blank-a), var(--blank-b)); }
.tile.blank .tile-ch { visibility: hidden; }
.tile.flipping { animation: flip .52s ease-in-out; }
.tile.wave { animation: wave 1s ease-in-out both; }
@keyframes flip { 0% { transform: perspective(600px) rotateY(0); } 50% { transform: perspective(600px) rotateY(90deg); } 100% { transform: perspective(600px) rotateY(0); } }
@keyframes wave { 0% { transform: perspective(600px) rotateY(0); filter: none; } 50% { transform: perspective(600px) rotateY(180deg); filter: brightness(1.35); } 100% { transform: perspective(600px) rotateY(360deg); filter: none; } }

.plate { margin-top: calc(var(--tile) * .45); padding: calc(var(--tile) * .12) calc(var(--tile) * 1.1); border-radius: calc(var(--tile) * .22); text-align: center;
  font-family: var(--tile-font); font-weight: 800; font-size: calc(var(--tile) * .56); letter-spacing: .14em; white-space: nowrap;
  color: var(--plate-ink); background: linear-gradient(var(--plate-a), var(--plate-b)); border: calc(var(--tile) * .05) solid var(--plate-edge);
  box-shadow: 0 calc(var(--tile) * .1) calc(var(--tile) * .3) rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.35); }
.stage.no-plate .plate { display: none; }

/* the big countdown under the board when the screen is held upright */
.readout { display: none; text-align: center; margin-top: calc(var(--pad, 12px) * 1.5); color: var(--readout); }
.stage[data-orient="portrait"][data-readout="1"] .readout { display: block; }
.stage[data-orient="portrait"][data-readout="1"][data-scene="both"] .readout { display: none; }
.readout-main { font-family: var(--tile-font); font-weight: 800; font-size: var(--ro, 64px); line-height: 1.05; font-variant-numeric: tabular-nums; text-shadow: 0 0 .4em var(--glow); }
.readout-sub { font-size: calc(var(--ro, 64px) * .24); letter-spacing: .12em; text-transform: uppercase; opacity: .85; margin-top: .3em; }

/* the wheel */
.wheel-svg { width: var(--wheel, 300px); height: var(--wheel, 300px); display: block; filter: drop-shadow(0 8px 24px rgba(0,0,0,.6)); }
.wheel-face { transform-origin: 200px 200px; transform-box: view-box; will-change: transform; }
.flapper { transform-box: view-box; }
.bulb { fill: #ffe9a0; opacity: .85; }
.wedge-label { font: 800 15px var(--tile-font); fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 2px; }
.wedge-label.dark { fill: #161616; stroke: none; }
.wedge-label.star { font-size: 20px; fill: #fff4c0; }
.wedge-event { font: 800 12px var(--tile-font); fill: #2b1a00; letter-spacing: .04em; }
.hub-time { font: 800 27px var(--tile-font); fill: #3a2400; }
.hub-sub { font: 800 14px var(--tile-font); fill: #5a3a05; letter-spacing: .1em; }
.stage[data-scene="wheel"] .readout { margin-top: 0; }
.stage[data-scene="wheel"] .readout-main { font-size: calc(var(--ro, 64px) * .8); }

/* effects */
.stage.chase .bulb { animation: bulb .72s steps(1, end) infinite; }
@keyframes bulb { 0% { opacity: 1; } 50% { opacity: .18; } }
.stage.fx-glow .board { animation: glow 1.7s ease-in-out 3; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 calc(var(--tile) * 1.2) rgba(0,0,0,.65), 0 0 calc(var(--tile) * .5) var(--glow); } 50% { box-shadow: 0 0 calc(var(--tile) * 1.2) rgba(0,0,0,.4), 0 0 calc(var(--tile) * 2.2) var(--glow); } }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.stage.fx-zero .flash { animation: flash 1.2s ease-out 2; }
@keyframes flash { 0% { opacity: .0; } 12% { opacity: .35; } 100% { opacity: 0; } }
.stage[data-motion="calm"] .flash { display: none; }

/* night */
.dim { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 2.5s; }
.minimal { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: #000; color: #8f9bb8;
  font-family: var(--tile-font); font-weight: 700; font-size: min(26vw, 30vh); font-variant-numeric: tabular-nums; }
.stage.night-minimal .minimal { display: flex; }

/* the control strip: hidden until the screen is tapped, hides itself again */
.controls { position: absolute; top: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 14px max(12px, env(safe-area-inset-left));
  background: linear-gradient(rgba(2,8,24,.92), rgba(2,8,24,0)); transform: translateY(-110%); transition: transform .25s; z-index: 5; }
.stage.show-controls .controls { transform: none; }
.segs { display: flex; flex-wrap: wrap; gap: 4px; }
.seg { border: 1px solid var(--line); background: rgba(14,29,68,.85); border-radius: 999px; padding: .35em .85em; cursor: pointer; font-size: .9rem; min-height: 2.25rem; }
.seg[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.ctl-right { display: flex; align-items: center; gap: 6px; }
.wake-note { font-size: .78rem; color: var(--muted); margin-right: 4px; }
.ctl { display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 50%; border: 1px solid var(--line); background: rgba(14,29,68,.85); color: var(--text); cursor: pointer; text-decoration: none; }
.ctl[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.sound-hint { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); white-space: nowrap; display: inline-flex; align-items: center; gap: .5em;
  border: 1px solid var(--line); background: rgba(14,29,68,.9); color: var(--text); border-radius: 999px; padding: .5em 1em; cursor: pointer; z-index: 4; opacity: .85; }

/* ---------- the settings page ---------- */
.app-page { max-width: var(--col); margin: 0 auto; padding: 0 16px 48px; padding-bottom: max(48px, env(safe-area-inset-bottom)); }
.app-bar { display: flex; align-items: center; gap: .75rem; min-height: 3.25rem; padding-top: max(.5rem, env(safe-area-inset-top)); }
.app-bar h1 { flex: 1; margin: 0; font-size: 1.15rem; }
.app-bar .app-back { display: inline-flex; align-items: center; gap: .3em; color: var(--muted); text-decoration: none; }
.app-bar .app-back:hover { color: var(--text); }
.app-btn { display: inline-flex; align-items: center; gap: .4em; border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: .45em .8em; cursor: pointer; min-height: 2.4rem; }
.app-btn:hover { filter: brightness(1.15); }
.app-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.app-btn.danger { color: var(--danger); }
.app-btn:disabled { opacity: .4; cursor: default; }
.app-btn.icon-only { padding: .4em; width: 2.4rem; justify-content: center; }
.field { margin: .8rem 0; min-width: 0; }
.field-label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field select, .field input[type=text], .field input[type=number], .field input[type=time], .field input[type=date], .event-name {
  width: 100%; max-width: 100%; padding: .5em .65em; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--text); }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex: none; }
.hint { margin: .3rem 0 0; color: var(--muted); font-size: .85rem; }
.app-section { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .25rem 1rem 1rem; margin: 1rem 0; }
.app-section h2 { font-size: 1rem; margin: .9rem 0 .25rem; color: var(--accent); }
.app-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.app-version { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 1.5rem; }
.app-empty { color: var(--muted); text-align: center; padding: 1.5rem 1rem; border: 1px dashed var(--line); border-radius: 10px; }
.events { display: grid; gap: .75rem; margin-top: .6rem; }
.event { border: 1px solid var(--line); background: rgba(255,255,255,.03); border-radius: 10px; padding: .6rem .8rem .8rem; }
.event-head { display: flex; gap: .5rem; align-items: center; }
.event-name { flex: 1; font-weight: 700; }
.event-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 .8rem; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { width: 2.4rem; height: 2.4rem; border-radius: 50%; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 700; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#app-toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translate(-50%, 140%); display: flex; align-items: center; gap: .75rem; max-width: calc(100% - 32px); padding: .6rem .9rem; background: var(--text); color: var(--bg); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.35); transition: transform .2s; z-index: 10; }
#app-toast.show { transform: translate(-50%, 0); }
#app-toast button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }

/* A device set to reduce motion gets no flips, waves, flashes or slides. */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
