:root {
  --bg: #0e1226; --bg-2: #171d3a; --card: #1b2242; --ink: #f4f1e8; --muted: #a9aecb;
  --line: #2f3866; --field: #10152d; --ok: #5fd0a0; --bad: #ff8a8a;
  --accent: #e0a526; --on-accent: #111427; --shadow: 0 10px 30px rgb(0 0 0 / .28);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f4ee; --bg-2: #ffffff; --card: #ffffff; --ink: #171b33; --muted: #565c7a;
  --line: #dcd8cb; --field: #ffffff; --ok: #0f7a52; --bad: #b3261e;
  --shadow: 0 8px 24px rgb(40 36 20 / .1);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { line-height: 1.15; margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); color: var(--ink);
  font: inherit; font-size: .92rem; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 650; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- public page ---------- */
.public {
  display: flex; flex-direction: column; padding: 0 16px;
  background: radial-gradient(ellipse 90% 55% at 50% -5%, var(--bg-2), var(--bg) 75%) fixed, var(--bg);
}
.toolbar { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding-top: max(12px, env(safe-area-inset-top)); }
.public main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 24px 0; }
.foot { text-align: center; color: var(--muted); font-size: .78rem; padding: 12px 0 max(16px, env(safe-area-inset-bottom)); }

/* ---------- winners stage (sizes follow the stage width) ---------- */
.stage { container-type: inline-size; --name: 1.3rem; }
.stage.size-small { --name: 1.05rem; }
.stage.size-large { --name: 1.75rem; }
.stage.size-xlarge { --name: 2.3rem; }
.stage-head { text-align: center; margin-bottom: 32px; }
.title { font-family: var(--serif); font-size: clamp(2rem, 7cqi, 4.5rem); overflow-wrap: anywhere; }
.title::after { content: ""; display: block; width: 72px; height: 4px; margin: 16px auto 0; border-radius: 4px; background: var(--accent); }
.subtitle { color: var(--muted); font-size: clamp(1rem, 2.4cqi, 1.35rem); margin: 14px 0 0; }
.empty { text-align: center; color: var(--muted); font-size: 1.15rem; padding: 40px 12px; }
.stage ol { list-style: none; margin: 0; padding: 0; }
.winner {
  display: flex; align-items: center; gap: 14px; min-width: 0; padding: 14px 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  animation: rise .5s ease both; animation-delay: calc(var(--i, 0) * 60ms);
}
.rank {
  flex: none; display: grid; place-items: center; min-width: 2.4em; height: 2.4em; padding: 0 .4em; border-radius: 99px;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-variant-numeric: tabular-nums;
}
.who { display: flex; flex-direction: column; min-width: 0; }
.name { font-size: var(--name); font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.detail { color: var(--muted); font-size: calc(var(--name) * .68); overflow-wrap: anywhere; }
.winners.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(var(--name) * 12)), 1fr)); }
.winners.grid.fixed { grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
.winners.list { display: flex; flex-direction: column; gap: 10px; max-width: 760px; margin: 0 auto !important; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 14px; margin-bottom: 24px !important; }
.podium .winner { flex-direction: column; justify-content: center; text-align: center; border-top: 5px solid var(--accent); }
.podium .who { align-items: center; }
.podium .place-1 { grid-column: 2; grid-row: 1; min-height: 230px; }
.podium .place-2 { grid-column: 1; grid-row: 1; min-height: 180px; }
.podium .place-3 { grid-column: 3; grid-row: 1; min-height: 150px; }
.podium .place-1 .name { font-size: calc(var(--name) * 1.3); }
.spotlight { display: grid; place-items: center; min-height: 220px; margin-bottom: 20px; }
.spotlight .winner {
  flex-direction: column; text-align: center; width: min(100%, 720px); padding: 32px 20px;
  border: 3px solid var(--accent); animation: pop .6s cubic-bezier(.2, 1.4, .4, 1) both;
}
.spotlight .who { align-items: center; }
.spotlight .name { font-family: var(--serif); font-size: clamp(1.8rem, 8cqi, calc(var(--name) * 2.6)); }
.hint { color: var(--muted); font-size: 1.2rem; }
.stage.layout-reveal { user-select: none; }
.stage.layout-reveal:not(.finished), .public:has(.layout-reveal:not(.finished)) { cursor: pointer; }
.progress { text-align: center; color: var(--muted); font-size: .9rem; }
.compact .winner { animation: none; box-shadow: none; }
.compact .name { font-size: calc(var(--name) * .85); }
.roll { height: 60vh; overflow: hidden; mask-image: linear-gradient(transparent, #000 8%, #000 92%, transparent); }
.roll:not(:has(.moving)) { overflow: auto; mask-image: none; }
.roll-track .winners { padding-bottom: 10px !important; }
.roll .winner { animation: none; }
.roll-track.moving { animation: roll var(--duration) linear infinite; }
.roll:hover .moving, .roll:focus .moving { animation-play-state: paused; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes pop { from { opacity: 0; transform: scale(.6); } }
@keyframes roll { to { transform: translateY(-50%); } }
@container (max-width: 560px) {
  .winners.grid.fixed { grid-template-columns: 1fr; }
  .podium { grid-template-columns: 1fr; }
  .podium .winner { grid-column: 1 !important; grid-row: auto !important; min-height: 0 !important; }
}

/* ---------- admin ---------- */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 16px; background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.bar nav { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: .75rem; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 2px 8px; }
.login { display: grid; place-items: start center; padding: 10vh 16px; }
.login form { width: min(100%, 380px); }
.panel { display: flex; flex-direction: column; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel h2, .preview h2 { font-size: 1.05rem; }
.app { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 20px; max-width: 1500px; margin: 0 auto; padding: 20px 16px; align-items: start; }
.settings { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .9rem; font-weight: 550; min-width: 0; }
input, select {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--field); color: var(--ink); font: inherit; font-size: 16px; font-weight: 400;
}
input[type=color] { padding: 4px; }
.check { flex-direction: row; align-items: center; gap: 10px; min-height: 32px; font-weight: 400; }
.check input { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.help { margin: -6px 0 0; color: var(--muted); font-size: .8rem; font-weight: 400; }
label .help { margin: 0; }
.msg { margin: 0; font-size: .88rem; color: var(--muted); }
.msg:empty { display: none; }
.msg.ok { color: var(--ok); }
.msg.error { color: var(--bad); }
.savebar {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom)); background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.savebar .msg { width: 100%; }
.preview { position: sticky; top: 76px; min-width: 0; max-height: calc(100vh - 96px); overflow: auto; border: 1px dashed var(--line); border-radius: 14px; padding: 16px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 10px; }
.preview .title { font-size: clamp(1.6rem, 7cqi, 3rem); }
.preview .roll { height: 360px; }
.idle {
  position: fixed; z-index: 20; left: 16px; right: 16px; bottom: 16px; max-width: 480px; margin: 0 auto;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--card); border: 2px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow);
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; max-height: none; }
}
@media (max-width: 480px) {
  .two { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
