@font-face { font-family: "Cormorant Garamond"; src: url(../assets/fonts/cormorant-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Cormorant Garamond"; src: url(../assets/fonts/cormorant-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --bg: #04070f;
  --card: #0a1120;
  --card-2: #101a2e;
  --line: rgba(186, 208, 245, .16);
  --ink: #e8eef9;
  --muted: #8f9db7;
  --accent: #c6daff;
  --serif: "Cormorant Garamond", "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --sans: -apple-system, "PingFang HK", "PingFang TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans) }
button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
button:hover:not(:disabled) { border-color: rgba(198, 218, 255, .5); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #07101f; border-color: transparent; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #dfeaff; }
button.quiet { background: transparent; color: var(--muted); padding: 5px 9px; }
button.quiet:hover:not(:disabled) { color: var(--ink); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input, select, textarea { background: #060c18; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
.grow { flex: 1; min-width: 0; }
.meta { color: var(--muted); font-size: 12.5px; font-weight: 400; }

/* operator page: the real stage on top, everything else in tabs below it */
#app { height: 100%; display: flex; flex-direction: column; }

.top { display: flex; align-items: center; gap: 18px; padding: 7px 16px; flex-wrap: wrap; }
.top h1 { font: 600 21px/1 var(--serif); letter-spacing: .02em; margin: 0; }
.field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.field select { padding: 4px 6px; color: var(--ink); }
.top-stage { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.top-stage .label { font-size: 12.5px; }
.top-stage input[type=number] { width: 72px; padding: 4px 6px; color: var(--ink); }
.top-sound { display: flex; align-items: center; gap: 4px; }
#volume { width: 86px; padding: 0; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 5px; margin-left: 6px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

#stageZone { position: relative; flex: none; height: min(56vh, calc(100vw * var(--ar, .2865))); background: #000; }
.board-note { display: none; position: absolute; left: 14px; top: 10px; z-index: 5; padding: 5px 10px; border-radius: 7px; background: rgba(8, 14, 28, .82); color: var(--ink); font-size: 12.5px; pointer-events: none; }
body.linked .board-note { display: block; }

.bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.now-text { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.now-text strong { font: 600 22px/1.15 var(--serif); white-space: nowrap; }
.now-text .meta { white-space: nowrap; }
.status { flex: 1; min-width: 0; margin: 0; color: var(--accent); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btnDraw { min-width: 100px; }

#console { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 12px; color: var(--muted); }
.tabs button:hover:not(:disabled) { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 14px; }
.row { display: flex; align-items: center; gap: 7px; }
.row select { flex: 0 1 260px; min-width: 0; }
#names { flex: 1; min-height: 90px; resize: none; line-height: 1.6; }

#prizeList { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(640px, 1fr)); gap: 3px 18px; align-content: start; }
.prize-row { display: grid; grid-template-columns: 68px 50px 50px minmax(90px, 1fr) 158px 106px; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 8px; border: 1px solid transparent; }
.prize-row.current { background: var(--card-2); border-color: rgba(198, 218, 255, .45); }
.pick { padding: 5px 0; font: 600 15px/1.2 var(--serif); background: transparent; }
.prize-row.current .pick { background: var(--accent); color: #07101f; }
.thumb { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; color: var(--muted); font-size: 11px; white-space: nowrap; }
.thumb:hover { color: var(--ink); }
.thumb-img { width: 38px; height: 38px; border-radius: 50%; overflow: hidden; background: #0c2052; border: 1px solid var(--line); }
.thumb:hover .thumb-img { border-color: rgba(198, 218, 255, .6); }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb-x { position: absolute; right: 0; top: -3px; width: 16px; height: 16px; padding: 0; border-radius: 50%; font-size: 11px; line-height: 1; }
.p-name { width: 100%; min-width: 0; }
.p-qty-wrap { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.p-qty { width: 44px; padding: 5px 4px; color: var(--ink); text-align: center; -moz-appearance: textfield; }
.p-qty::-webkit-inner-spin-button { display: none; }
.p-step { width: 26px; padding: 4px 0; }
.p-actions { display: flex; justify-content: flex-end; }
.p-del { padding: 5px 7px; }

#resultList { flex: 1; min-height: 0; overflow: auto; column-width: 300px; column-gap: 28px; }
.empty { color: var(--muted); margin: 6px 0; }
.result-group { break-inside: avoid; padding-bottom: 8px; }
.result-group h4 { margin: 0 0 3px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.result { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 15px; }
.result span { flex: 1; min-width: 0; }
.result small { color: var(--muted); font-size: 12px; }
.result.void span { color: var(--muted); text-decoration: line-through; }

.toast { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); z-index: 90; background: #e9f0ff; color: #07101f; padding: 9px 16px; border-radius: 8px; font-size: 14px; }

.ask-veil { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: rgba(2, 5, 12, .62); font-size: 14px; }
.ask { width: min(31em, calc(100vw - 32px)); padding: 1.1em; border-radius: .85em; background: var(--card); border: 1px solid var(--line); color: var(--ink); }
.ask h3 { margin: 0 0 .4em; font: 600 1.55em/1.2 var(--serif); }
.ask p { margin: 0 0 .5em; color: var(--muted); }
.ask-pick { display: flex; flex-direction: column; gap: .25em; margin: .4em 0; }
.ask-actions { display: flex; flex-wrap: wrap; gap: .55em; margin-top: .9em; }
.ask-actions button { padding: .5em .85em; border-radius: .5em; }
/* in single-window Present the audience sees this screen too, so it stays out of the way */
body.presenting .ask-veil { inset: auto 1.2em 1.2em auto; background: none; font-size: max(13px, calc(var(--u, 1px) * 15)); }

@media (max-width: 1080px) {
  .top { gap: 10px; }
  .top-actions { margin-left: 0; }
  .bar { flex-wrap: wrap; }
  #prizeList { grid-template-columns: 1fr; }
}

/* stage */
#stageHost { position: absolute; inset: 0; overflow: hidden; background: #000; }
body.presenting #stageHost { position: fixed; z-index: 10; cursor: none; }
body.presenting #stageHost.awake { cursor: default; }
body.stage-only .top, body.stage-only .bar, body.stage-only #console, body.stage-only .board-note { display: none; }
body.stage-only #stageZone { height: 100%; }
body:not(.presenting) .dock { display: none; }

.stage {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); overflow: hidden; color: #fff; user-select: none;
  background: radial-gradient(ellipse 34% 96% at 50% 58%, #071330 0%, #030914 56%, #01030a 100%);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage.asleep canvas.stars, .stage.asleep canvas.smoke, .stage.asleep canvas.wall { visibility: hidden; }
.stage.asleep * { animation-play-state: paused !important; }

.moon-wrap { position: absolute; pointer-events: none; }
.moon-wrap::before { content: ""; position: absolute; left: 26%; top: 26%; right: 26%; bottom: 26%; border-radius: 50%; box-shadow: 0 0 calc(var(--u) * 26) calc(var(--u) * 7) rgba(170, 203, 255, .5), 0 0 calc(var(--u) * 150) calc(var(--u) * 44) rgba(106, 150, 245, .3); }
.moon { position: absolute; left: 25.61%; top: 25.61%; width: 48.78%; height: 48.78%; display: block; transition: filter .4s; }
.moon-halo {
  position: absolute; inset: 6%; border-radius: 50%; animation: halo 11s ease-in-out infinite;
  background: radial-gradient(closest-side, rgba(128, 170, 255, .34), rgba(96, 146, 255, .13) 58%, transparent 100%);
}
@keyframes halo { 0%, 100% { opacity: .5; transform: scale(.97); } 50% { opacity: 1; transform: scale(1.03); } }

/* the opening: the moon comes up as a phase out of full black */
.night, .moon-shade, .moon-rim { display: none; }
.stage.intro .night, .stage.intro .moon-shade, .stage.intro .moon-rim { display: block; }
.night { position: absolute; inset: 0; background: #000; }
.moon-shade { position: absolute; left: 25.2%; top: 25.2%; width: 49.6%; height: 49.6%; border-radius: 50%; overflow: hidden; }
.stage.intro .shelf { opacity: 0; }
.stage.intro .moon-hit { visibility: hidden; }
.stage.intro .moon { transition: none; }
.stage.intro .moon-wrap::before { opacity: var(--glow, 0); }
.stage.intro .moon-halo { animation: none; transform: scale(.97); opacity: calc(var(--glow, 0) * .5); }

.moon-hit { position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center; pointer-events: none; font-family: var(--serif); font-weight: 500; }
/* a soft shadow settles on the moon first, so the word reads against the craters without a box */
.moon-hit::before { content: ""; position: absolute; inset: 10%; border-radius: 50%; opacity: 0; transition: opacity .6s; background: radial-gradient(closest-side, rgba(5, 13, 34, .66), rgba(5, 13, 34, .42) 48%, transparent 100%); }
.moon-hit span {
  position: relative; opacity: 0; font-size: .74em; text-transform: uppercase; letter-spacing: .14em; text-indent: .14em;
  transition: opacity .6s, letter-spacing 1s cubic-bezier(.2, .8, .3, 1), text-indent 1s cubic-bezier(.2, .8, .3, 1);
  background: linear-gradient(105deg, #bcd2fb 0%, #bcd2fb 30%, #ffffff 44%, #f8dcee 52%, #ffffff 60%, #bcd2fb 74%, #bcd2fb 100%) 0 0 / 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 .1em rgba(160, 198, 255, .8));
}
.stage[data-phase=idle] .moon-hit { pointer-events: auto; cursor: pointer; }
.stage[data-phase=idle].awake .moon-hit::before { opacity: 1; }
.stage[data-phase=idle].awake .moon-hit span { opacity: 1; letter-spacing: .3em; text-indent: .3em; animation: moon-sheen 6s ease-in-out infinite; }
.stage[data-phase=idle] .moon-hit:hover span { letter-spacing: .38em; text-indent: .38em; }
.stage[data-phase=idle].awake .moon { filter: brightness(1.1); }
@keyframes moon-sheen { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
/* the star wall brings the winner's name to the moon, which steps back to let it read */
.stage.winning .moon { filter: brightness(.4) saturate(.8); transition: filter .9s; }

.shelf { position: absolute; inset: 0; pointer-events: none; transition: opacity .6s; }
.stage.revealing .shelf { opacity: .1; }
.stage.walling .shelf { opacity: 0; }
.slot { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; opacity: .64; transition: opacity .9s, transform 1s cubic-bezier(.2, .8, .3, 1); perspective: calc(var(--u) * 1000); }
.slot.has, .slot.current { opacity: 1; }
.stage[data-phase=idle] .slot { pointer-events: auto; cursor: pointer; }
.stage:not(.asleep) .slot:not(.shown) { opacity: 0; transform: translateY(calc(var(--u) * 28)) scale(.84); pointer-events: none; }
.slot::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: calc(var(--b) * 1.7); height: calc(var(--b) * 1.7);
  transform: translate(-50%, -62%); border-radius: 50%; opacity: 0; transition: opacity .7s;
  background: radial-gradient(closest-side, rgba(170, 205, 255, .42), transparent);
}
.slot.current::before { opacity: 1; animation: breathe 3.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.slot-badge { position: relative; flex: none; width: var(--b); height: var(--b); transform-style: preserve-3d; transition: transform 1.1s cubic-bezier(.5, 0, .2, 1), scale .25s; }
.stage[data-phase=idle] .slot:hover .slot-badge { scale: 1.05; }
.slot.revealed .slot-badge { transform: rotateY(180deg); }
.slot.arrive .slot-badge { animation: arrive .8s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes arrive { 0% { scale: 1; } 30% { scale: 1.14; } 100% { scale: 1; } }

.slot-redo { position: absolute; left: 50%; top: 4%; margin-left: calc(var(--b) * .26); display: flex; align-items: center; justify-content: center; width: calc(var(--b) * .3); height: calc(var(--b) * .3); min-width: 22px; min-height: 22px; border-radius: 50%; font-size: calc(var(--b) * .17); line-height: 1; background: rgba(8, 14, 28, .88); border: 1px solid rgba(198, 218, 255, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
.stage[data-phase=idle] .slot.has:hover .slot-redo { opacity: 1; pointer-events: auto; }

.slot-menu { position: absolute; z-index: 40; min-width: 11em; padding: .35em; border-radius: .6em; background: rgba(8, 14, 28, .96); border: 1px solid var(--line); color: var(--ink); font: max(13px, calc(var(--u) * 17))/1.35 var(--sans); }
.slot-menu small { display: block; padding: .2em .55em; color: var(--muted); font-size: .85em; }
.slot-menu div { padding: .35em .55em; border-radius: .4em; cursor: pointer; }
.slot-menu div:hover { background: var(--card-2); }
.slot-menu div.off { color: var(--muted); cursor: default; background: none; }

.face { position: absolute; inset: 0; width: 100%; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: block; }
.face.back { transform: rotateY(180deg); }
.face.back > img { width: 100%; height: 100%; display: block; }
.hole { position: absolute; inset: 15%; display: flex; align-items: center; justify-content: center; }
.hole img { width: 100%; height: 100%; object-fit: contain; display: block; }

.slot-label { position: relative; margin-top: calc(var(--u) * 8); font: 600 var(--label)/1.15 var(--serif); letter-spacing: .1em; color: #b9c9e6; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.slot.revealed .slot-label { letter-spacing: .02em; color: #e8f0ff; }
.slot-names { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 0 calc(var(--u) * 16); min-height: calc(var(--name) * 1.15); max-width: 100%; font: 600 var(--name)/1.14 var(--serif); }
.slot-names span { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.slot-names.n2, .slot-names.n3 { font-size: calc(var(--name) * .7); }
.slot-names.n4, .slot-names.n5, .slot-names.n6 { font-size: calc(var(--name) * .55); }

.dim { position: absolute; inset: 0; opacity: 0; transition: opacity .6s; pointer-events: none; background: radial-gradient(ellipse 70% 120% at 50% 50%, rgba(1, 3, 10, .86), rgba(1, 3, 10, .6)); }
.dim.on { opacity: 1; }

.reveal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: calc(var(--u) * 110); visibility: hidden; pointer-events: none; }
.reveal.on { visibility: visible; }
.stage[data-phase=revealed] .reveal { pointer-events: auto; cursor: pointer; }
.rv-side { flex: 1; min-width: 0; opacity: 0; transform: translateY(calc(var(--u) * 26)); transition: opacity .9s, transform .9s; font-family: var(--serif); }
.rv-side.on { opacity: 1; transform: none; }
.rv-side small { display: block; font: 600 calc(var(--u) * 44)/1.2 var(--serif); color: #b9c9e6; letter-spacing: .1em; margin-bottom: calc(var(--u) * 16); }
.rv-side h2 { margin: 0; font: 600 calc(var(--u) * 118)/1.12 var(--serif); }
.rv-prize { text-align: right; }
.rv-winners { text-align: left; }
.rv-names { display: flex; flex-wrap: wrap; gap: calc(var(--u) * 6) calc(var(--u) * 44); font: 600 calc(var(--u) * 118)/1.12 var(--serif); }
.rv-names.many { font-size: calc(var(--u) * 62); }
.rv-badge { position: relative; flex: none; width: calc(var(--u) * 760); height: calc(var(--u) * 760); perspective: calc(var(--u) * 2600); }
.rv-flip { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }

.cord-host { position: absolute; top: 0; width: 0; height: 100%; pointer-events: none; }
.cord { position: absolute; top: 0; left: 0; transform: translateY(-105%); opacity: 0; transition: transform .9s cubic-bezier(.3, 1.3, .5, 1), opacity .6s; }
.cord.show { transform: none; opacity: 1; }
.cord-sway { position: relative; transform-origin: 0 0; }
.cord-line { position: absolute; left: 0; top: 0; width: calc(var(--u, 1.2px) * 2.4); min-width: 1.5px; transform: translateX(-50%); background: linear-gradient(#7f93b8, #e8efff); }
.cord-knob { position: absolute; left: 0; top: 0; cursor: grab; touch-action: none; pointer-events: auto; filter: drop-shadow(0 0 calc(var(--u, 1px) * 16) rgba(170, 205, 255, .9)); }
.cord-knob:active { cursor: grabbing; }
.cord-knob svg { width: 100%; height: 100%; display: block; }
.cord.hint .cord-knob svg { animation: cord-glow 1.5s ease-in-out infinite; }
@keyframes cord-glow { 0%, 100% { filter: drop-shadow(0 0 calc(var(--u, 1px) * 6) rgba(200, 222, 255, .5)); } 50% { filter: drop-shadow(0 0 calc(var(--u, 1px) * 34) rgba(225, 238, 255, 1)); } }
.cord-hint { position: absolute; left: 50%; top: 100%; margin-top: calc(var(--u, 1px) * 10); transform: translateX(-50%); font: 600 calc(var(--u, 1px) * 34)/1 var(--serif); letter-spacing: .05em; color: #e4eeff; white-space: nowrap; opacity: 0; transition: opacity .4s; pointer-events: none; }
.cord.hint .cord-hint { opacity: 1; }

.dock { position: absolute; left: 50%; bottom: 1em; transform: translate(-50%, .8em); z-index: 30; display: flex; align-items: center; gap: .5em; padding: .55em .7em; border-radius: .8em; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; background: rgba(8, 14, 28, .86); border: 1px solid var(--line); color: var(--ink); font-size: max(14px, calc(var(--u, 1px) * 19)); }
.dock.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.dock button { padding: .4em .85em; border-radius: .5em; }
.dock-prize { min-width: 9em; text-align: center; white-space: nowrap; }

.stage-hint { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 40; padding: 7px 13px; border-radius: 8px; background: rgba(8, 14, 28, .86); color: var(--ink); font-size: 13px; transition: opacity .6s; pointer-events: none; }
.stage-hint.off { opacity: 0; }

/* after every font shorthand, which would otherwise reset it: old-style 0 and 1 read as o and I */
.top h1, .pick, .now-text strong, .ask h3, .slot-label, .slot-names, .rv-side small, .rv-side h2, .rv-names { font-variant-numeric: lining-nums; }
