/* Layout: a home screen to create or join an event, then an event screen with the wheel beside the controls.
   Felt-green neutrals with a brass accent. System fonts only, so the page makes no third-party requests. */
:root {
  --bg: #f4f3fc;
  --surface: #ffffff;
  --fg: #1b1740;
  --muted: #5b5883;
  --line: #dcd9f0;
  --accent: #d9304a;
  --accent-fg: #ffffff;
  --focus: #4f46e5;
  --danger: #b42318;
  --ok: #15803d;
  --font-display: ui-rounded, "Segoe UI Variable Display", "Trebuchet MS", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0d24;
    --surface: #1a1740;
    --fg: #eceaff;
    --muted: #aaa7d2;
    --line: #2d2965;
    --accent: #ff7a8a;
    --accent-fg: #2b0710;
    --focus: #a5b4fc;
    --danger: #f97066;
    --ok: #4ade80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f0d24;
    --surface: #1a1740;
    --fg: #eceaff;
    --muted: #aaa7d2;
    --line: #2d2965;
    --accent: #ff7a8a;
    --accent-fg: #2b0710;
    --focus: #a5b4fc;
    --danger: #f97066;
    --ok: #4ade80;
    color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  padding-inline: 16px;
  padding-block: max(24px, env(safe-area-inset-top)) max(40px, env(safe-area-inset-bottom));
}
main { max-width: 980px; margin-inline: auto; }
header { margin-bottom: 20px; }
h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(2rem, 6vw, 3rem); line-height: 1.05; letter-spacing: -0.02em;
  margin: 0 0 6px; text-wrap: balance;
}
h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; margin: 0; letter-spacing: -0.01em; overflow-wrap: anywhere; }
header p { margin: 0; color: var(--muted); max-width: 58ch; }

button, .link-btn { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input[type="text"], input[type="url"] {
  min-width: 0; width: 100%;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font: inherit;
}
label.title { font-weight: 600; display: block; margin-bottom: 4px; }
.check { display: flex; gap: 10px; align-items: center; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; text-decoration: none; display: inline-block; }
.ghost:hover:not(:disabled) { border-color: var(--fg); }
.ghost:disabled { opacity: .5; cursor: not-allowed; }
.solid { background: var(--fg); color: var(--bg); border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.solid:disabled { opacity: .5; cursor: not-allowed; }
.note { margin: 0; color: var(--muted); font-size: .875rem; min-height: 1.3em; overflow-wrap: anywhere; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* home */
.home-grid { display: grid; grid-template-columns: 1fr; gap: 20px; margin-top: 20px; }
@media (min-width: 720px) { .home-grid { grid-template-columns: 1fr 1fr; } }
#recent { margin-top: 20px; }

/* event */
.event-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 8px; }
.event-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.event-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: .875rem; color: var(--muted); }
.chip strong { color: var(--fg); letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip.off .dot { background: var(--danger); }
.badge { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; border-radius: 6px; padding: 2px 8px; background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.badge.view { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.layout { display: grid; grid-template-columns: 1fr; gap: 28px; align-items: start; }
@media (min-width: 780px) { .layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 40px; } }
.stage, .panel { min-width: 0; }
.stage { display: flex; flex-direction: column; gap: 18px; padding-top: 18px; }
.wheel-wrap { position: relative; width: min(100%, 460px); aspect-ratio: 1; margin-inline: auto; }
.wheel-wrap canvas { display: block; width: 100%; height: 100%; }
.pointer {
  position: absolute; left: 50%; top: -14px; transform: translateX(-50%); z-index: 2;
  width: 0; height: 0;
  border-left: 15px solid transparent; border-right: 15px solid transparent;
  border-top: 32px solid var(--accent);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .35));
}
.spin {
  width: min(100%, 460px); margin-inline: auto;
  background: var(--accent); color: var(--accent-fg);
  border: 0; border-radius: 10px; padding: 14px 20px;
  font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; letter-spacing: 0.01em;
}
.spin:hover:not(:disabled) { filter: brightness(1.06); }
.spin:disabled { opacity: .55; cursor: not-allowed; }
.watch { width: min(100%, 460px); margin-inline: auto; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; padding: 12px 16px; }

.panel { display: flex; flex-direction: column; gap: 16px; }
.result { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-height: 5.5rem; }
.result .label { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.result .value { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.5rem, 5vw, 2.25rem); line-height: 1.15; overflow-wrap: anywhere; margin-top: 2px; }
.result .value.idle { color: var(--muted); font-size: 1.15rem; font-family: var(--font-body); font-weight: 400; }

.head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
#count, #logCount { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.add-form { display: flex; gap: 8px; }
.host-tools { display: flex; flex-direction: column; gap: 8px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px 6px 12px; }
.list li span { min-width: 0; overflow-wrap: anywhere; }
.list button { flex: none; background: transparent; border: 0; color: var(--danger); border-radius: 6px; padding: 2px 10px; font-size: 1.15rem; line-height: 1.3; }
.list button:hover { background: var(--bg); }

.qr-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.qr-tile { background: #ffffff; padding: 8px; border-radius: 8px; line-height: 0; flex: none; }
.qr-tile img { width: 168px; height: 168px; max-width: 100%; image-rendering: pixelated; }
.qr-text { flex: 1 1 190px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.qr-text p { margin: 0; }
.code-big { font-family: var(--font-display); font-weight: 800; font-size: 2rem; letter-spacing: .14em; line-height: 1; overflow-wrap: anywhere; }
.link-row { display: flex; gap: 8px; }

.log { list-style: none; margin: 0; padding: 0; max-height: 20rem; overflow-y: auto; display: flex; flex-direction: column; }
.log li { display: grid; grid-template-columns: 6rem 1fr; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.log li:first-child { border-top: 0; }
.log li.empty { display: block; color: var(--muted); }
.log .when { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; padding-top: 2px; }
.log .what { min-width: 0; overflow-wrap: anywhere; }
.log .who { color: var(--muted); }
.log .t-spin .what { font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* roles */
.narrow { max-width: 420px; }
input[type="password"] {
  min-width: 0; width: 100%;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font: inherit;
}
.add-form { flex-wrap: wrap; }
.add-form input { flex: 1 1 140px; }
.codes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.codes li { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.codes .info { min-width: 0; display: flex; flex-direction: column; }
.codes .c { font-family: var(--font-display); font-weight: 800; letter-spacing: .12em; }
.codes .l { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.codes li.revoked .c { text-decoration: line-through; color: var(--muted); }
.codes .acts { display: flex; gap: 6px; }
.codes .acts button { background: transparent; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; font-size: .85rem; }
.codes .acts button.danger { color: var(--danger); }
.list li.pick { cursor: pointer; }
.list li .go { background: transparent; border: 0; color: var(--fg); font: inherit; text-align: left; flex: 1; min-width: 0; padding: 4px 0; }
.list li small { color: var(--muted); }

/* ---------- landing ---------- */
h1 { display: flex; align-items: center; gap: 12px; }
.mark { width: .7em; height: .7em; flex: none; border-radius: 50%;
  background: conic-gradient(#c2410c 0 12.5%, #0f766e 0 25%, #6d28d9 0 37.5%, #be123c 0 50%, #1d4ed8 0 62.5%, #a16207 0 75%, #15803d 0 87.5%, #9d174d 0);
  box-shadow: 0 0 0 3px var(--accent); }
#landing { display: flex; flex-direction: column; gap: 22px; }

.hero {
  display: grid; grid-template-columns: 1fr; gap: 28px; align-items: center;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(255, 122, 138, .22), transparent 55%),
    linear-gradient(160deg, #2b2070, #120f2e);
  color: #efedff; border-radius: 20px; padding: clamp(22px, 5vw, 44px);
  border: 1px solid rgba(255, 122, 138, .25); overflow: hidden;
}
@media (min-width: 760px) { .hero { grid-template-columns: 1fr 240px; padding-block: 28px; } .hero-wheel { width: 220px; } }
.hero-text { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .16em; font-size: .75rem; font-weight: 700; color: #ff7a8a; }
.hero-title { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.9rem, 5.5vw, 3rem); line-height: 1.05; letter-spacing: -0.02em; margin: 0; text-wrap: balance; }
.hero-sub { margin: 0; color: #c8c5ea; max-width: 46ch; font-size: 1.05rem; }
.points { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.points li { border: 1px solid rgba(255, 122, 138, .4); color: #ffd3d9; border-radius: 999px; padding: 4px 12px; font-size: .85rem; }

.hero-wheel { position: relative; width: min(100%, 260px); aspect-ratio: 1; margin-inline: auto; }
.hero-pointer {
  position: absolute; left: 50%; top: -10px; transform: translateX(-50%); z-index: 2; width: 0; height: 0;
  border-left: 12px solid transparent; border-right: 12px solid transparent; border-top: 26px solid #ff7a8a;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5));
}
.wheel-art { display: block; width: 100%; height: 100%; filter: drop-shadow(0 14px 28px rgba(0, 0, 0, .45)); }
.spin-slow { transform-origin: 100px 100px; animation: wheel-turn 36s linear infinite; }
@keyframes wheel-turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin-slow { animation: none; } }

.mine { gap: 10px; }
.start { padding: 0; gap: 0; overflow: hidden; max-width: 640px; width: 100%; margin-inline: auto; }
.tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--bg); }
.tab { flex: 1 0 auto; white-space: nowrap; background: transparent; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 14px 8px; font-weight: 700; font-size: .95rem; }
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); background: var(--surface); }
.tab-panel { display: flex; flex-direction: column; gap: 14px; padding: clamp(16px, 4vw, 26px); }
.tab-panel .lead { margin: 0; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 520px) { .two { grid-template-columns: 1fr 1fr; } }
.code-input { font-family: var(--font-display); font-weight: 800; letter-spacing: .18em; font-size: 1.2rem; text-transform: uppercase; }
.solid.big { width: 100%; padding: 13px 18px; font-size: 1.05rem; background: var(--accent); color: var(--accent-fg); }
.solid.big:hover:not(:disabled) { filter: brightness(1.06); }
@media (min-width: 520px) { .solid.big { width: auto; min-width: 12rem; } }

/* theme toggle */
header { position: relative; }
.theme-btn { position: absolute; top: 0; right: 0; padding: 6px 12px; font-size: .85rem; border-radius: 999px; background: var(--surface); }
h1 { padding-right: 7.5rem; }
@media (max-width: 519px) {
  .theme-btn { position: static; display: block; margin: 0 0 10px auto; }
  h1 { padding-right: 0; }
}

/* last result */
.last { gap: 8px; }
.last .head { align-items: baseline; }
#lastWhen { color: var(--muted); font-size: .85rem; }
.last-winner { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: clamp(1.4rem, 4.5vw, 2rem); line-height: 1.15; overflow-wrap: anywhere; color: var(--accent); }
.last-winner.empty { color: var(--muted); font-family: var(--font-body); font-weight: 400; font-size: 1.05rem; }
.label { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 6px 0 4px; }
.earlier { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.earlier li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.earlier li span { min-width: 0; overflow-wrap: anywhere; }
.earlier small { color: var(--muted); white-space: nowrap; }

/* reveal pop-up */
body.modal-open { overflow: hidden; }
.reveal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(90% 70% at 50% 40%, rgba(60, 40, 150, 1), rgba(8, 6, 24, 1));
  animation: reveal-in .35s ease-out both;
}
.reveal.shown { background: radial-gradient(90% 70% at 50% 40%, rgba(60, 40, 150, .94), rgba(8, 6, 24, .97)); }
.reveal canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.reveal-card { position: relative; text-align: center; color: #efedff; max-width: min(92vw, 720px); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.reveal-kicker { margin: 0; text-transform: uppercase; letter-spacing: .22em; font-weight: 700; font-size: clamp(.9rem, 2.6vw, 1.15rem); color: #ff9aa8; }
.reveal-winner { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: clamp(2.2rem, 9vw, 4.5rem); line-height: 1.05; overflow-wrap: anywhere; text-wrap: balance; text-shadow: 0 0 36px rgba(255, 122, 138, .65); }
.reveal-kicker { animation: kicker-in 1s ease-out both; }
.reveal.shown .reveal-kicker { animation: none; }
.reveal.shown .reveal-winner { animation: ease-in-up 1.1s cubic-bezier(.22, .61, .36, 1) both; }
.reveal .solid.big { margin-top: 10px; }
@keyframes reveal-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes kicker-in { from { opacity: 0; letter-spacing: .5em; } to { opacity: 1; } }
@keyframes ease-in-up { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .reveal, .reveal-kicker, .reveal.shown .reveal-winner { animation: none; } }

/* add-by-QR page, admin */
.addbox { padding: clamp(16px, 4vw, 26px); gap: 12px; }
.addbox .lead { margin: 0; color: var(--muted); }
.tab-panel.flush { padding: 0; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: .9rem; overflow-wrap: anywhere; }
.chips li.new { border-color: var(--accent); color: var(--accent); }
#viewerCount { color: var(--muted); font-size: .85rem; }
.opt { color: var(--muted); font-weight: 400; }
.viewers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.viewers li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; gap: 2px; min-width: 0; }
.viewers strong { overflow-wrap: anywhere; }
.viewers small { color: var(--muted); overflow-wrap: anywhere; }
.viewers li.none { border-style: dashed; color: var(--muted); }
#adminCount { color: var(--muted); font-size: .85rem; }
#gsiBtn { min-height: 44px; max-width: 320px; overflow: hidden; }
#gsiBtn iframe, #gsiBtn > div { max-width: 100%; }
#gsiBtn svg, #gsiBtn img { max-width: 24px; max-height: 24px; }
.admin-card { gap: 10px; }
.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.admin-row { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; min-width: 0; }
.admin-row .top { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.admin-row .top strong { overflow-wrap: anywhere; }
.admin-row .meta { margin: 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.admin-row .acts { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-row .acts button { padding: 6px 12px; }
.admin-row .acts .danger, .admin-row .confirm .danger { color: var(--danger); }
.admin-row .confirm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin-row .confirm input { flex: 1 1 180px; min-width: 0; }
.badge.locked { background: var(--danger); color: var(--bg); }
.lockbar { margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--danger); border-radius: 10px; color: var(--danger); font-weight: 600; }
.host-tools[inert] { opacity: .55; }
@media (max-width: 519px) { .tab { padding: 14px 6px; font-size: .82rem; } }

.ver { margin-top: 28px; padding-bottom: 8px; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 8px; text-align: center; color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }

.closed { border: 1px dashed var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 6px; }
.closed p { margin: 0; color: var(--muted); }
.closed .closed-title { color: var(--fg); font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }
#pendingCount { color: var(--muted); font-size: .85rem; }
.pendingbar { display: block; width: 100%; margin: 0 0 12px; padding: 10px 14px; text-align: left; font: inherit; font-weight: 600; cursor: pointer; background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; }
.pending { border-color: var(--accent); }
.pending-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pending-list li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-width: 0; }
.pending-list .t { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.pending-list .t small { display: block; color: var(--muted); font-weight: 400; }
.pending-list .acts { display: flex; gap: 8px; }
.pending-list .acts .danger { color: var(--danger); }
#optList { max-height: 30rem; overflow-y: auto; padding-right: 2px; }
/* ---- desktop / landscape: use the full width ---- */
.small { padding: 4px 10px; font-size: .85rem; }
@media (min-width: 1100px) {
  body[data-view="eventView"] main, body[data-view="adminView"] main { max-width: 1400px; }
  #eventView[data-role="host"] .layout { grid-template-columns: minmax(380px, 480px) minmax(0, 1fr); grid-template-rows: auto auto auto 1fr; gap: 16px 36px; }
  #eventView[data-role="host"] .panel { display: contents; }
  #eventView[data-role="host"] .stage,
  #eventView[data-role="host"] .result,
  #eventView[data-role="host"] .last { grid-column: 1; }
  #eventView[data-role="host"] .host-tools:not([hidden]) { grid-column: 2; grid-row: 1 / -1; display: block; column-count: 2; column-gap: 16px; }
  #eventView[data-role="host"] .host-tools > .card { break-inside: avoid; margin-bottom: 16px; }
  #eventView[data-role="viewer"] .layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  #eventView[data-role="viewer"] .wheel-wrap, #eventView[data-role="viewer"] .spin, #eventView[data-role="viewer"] .watch { width: min(100%, 560px); }
  .admin-list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); align-items: start; }
}
