:root {
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #f1eadf;
  --ink: #221c17;
  --muted: #6e645b;
  --line: #e4dacb;
  --accent: #d9480f;
  --accent-hover: #bf3d0a;
  --accent-ink: #ffffff;
  --accent-soft: #fce6d9;
  --gold: #a87a05;
  --gold-bright: #f2c230;
  --gold-soft: #fff3cf;
  --ok: #2b8a3e;
  --ok-soft: #e1f3e5;
  --warn: #9c6500;
  --warn-soft: #fdf0d5;
  --danger: #c92a2a;
  --danger-soft: #fde2e2;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120f;
    --surface: #201b17;
    --surface-2: #2b241f;
    --ink: #f4ede4;
    --muted: #a89d92;
    --line: #3a322b;
    --accent: #ff7b3a;
    --accent-hover: #ff915a;
    --accent-ink: #1a0f08;
    --accent-soft: #3b2416;
    --gold: #f2c94c;
    --gold-bright: #e9b921;
    --gold-soft: #3a3013;
    --ok: #6fd98a;
    --ok-soft: #1a3322;
    --warn: #f0b44c;
    --warn-soft: #3a2d12;
    --danger: #ff6b6b;
    --danger-soft: #3d1c1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font-body); }
body.rating { padding-bottom: 110px; }
.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-top: 28px; padding-bottom: 56px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.15; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); }
h2 { font-size: 1.3rem; }
a { color: var(--accent); }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }
.small { font-size: .82rem; }
.spaced { margin-top: 16px; }
.note { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 10px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.big-emoji { font-size: 3rem; line-height: 1; margin-bottom: 12px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; color: var(--ink); text-decoration: none; }
.brand svg { width: 30px; height: 30px; }
.nav { display: flex; align-items: center; gap: 2px; }
.nav form { margin: 0; }
.nav a, .nav button { font: inherit; font-size: .92rem; color: var(--muted); text-decoration: none; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.nav a:hover, .nav button:hover { color: var(--ink); background: var(--surface-2); }

/* Building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 .95rem/1 var(--font-body); padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 7px 11px; font-size: .84rem; border-radius: 8px; }
.btn-lg { padding: 16px 28px; font-size: 1.1rem; border-radius: 14px; }
.btn-block { width: 100%; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: .85rem; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=password], textarea, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select:disabled { opacity: .6; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field em { font-style: normal; font-weight: 400; }

.pill, .badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-open { background: var(--accent-soft); color: var(--accent); }
.pill-revealed { background: var(--gold-soft); color: var(--gold); }
.badge { font-size: .74rem; padding: 3px 8px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-progress { background: var(--warn-soft); color: var(--warn); }

.alert { padding: 12px 16px; border-radius: 10px; margin: 0 0 20px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s ease; }

/* Login / small centred pages */
.auth-card { max-width: 400px; margin: 8vh auto 0; }
.center-card { max-width: 520px; margin: 4vh auto 0; text-align: center; }
.center-card .progress { margin: 16px 0; }

/* Dashboard */
.dash-head { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; }
.dash-head p { margin: 0; }
.new-contest { display: flex; gap: 8px; flex: 1 1 320px; max-width: 460px; }
.contest-list { display: grid; gap: 12px; }
.contest-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; color: inherit; text-decoration: none; transition: border-color .15s; }
.contest-card:hover { border-color: var(--accent); }
.contest-card h3 { font-size: 1.2rem; margin: 0 0 4px; }
.contest-card .meta { color: var(--muted); font-size: .9rem; margin: 0; }
.contest-card .side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; font-size: .9rem; }
.winner-line { font-weight: 600; }
.empty { text-align: center; padding: 48px 20px; }

/* Contest management */
.back { display: inline-block; color: var(--muted); text-decoration: none; font-size: .9rem; margin-bottom: 12px; }
.back:hover { color: var(--ink); }
.contest-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.contest-head h1 { margin-top: 10px; }
.contest-head p { margin: 0; }
.steps { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.steps li { display: flex; align-items: center; gap: 8px; font-size: .85rem; padding: 5px 12px 5px 5px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.steps b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); font-size: .75rem; }
.steps li.done { color: var(--ok); }
.steps li.done b { background: var(--ok-soft); }
.progress-card { margin-bottom: 16px; }
.progress-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.span-all { grid-column: 1 / -1; }
.card h2 { display: flex; align-items: baseline; gap: 8px; }
.count { font: 600 .85rem var(--font-body); color: var(--muted); }
.rows { list-style: none; margin: 0 0 14px; padding: 0; }
.rows > li { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 46px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.rows > li:last-child { border-bottom: 0; }
.rows form { margin: 0; }
.rows .empty-row { color: var(--muted); font-style: italic; justify-content: flex-start; }
.row-tools { display: flex; align-items: center; gap: 6px; }
.row-tools select { width: auto; padding: 4px 8px; font-size: .85rem; border-radius: 8px; }
.add-form { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.add-form textarea { min-height: 46px; resize: vertical; }
.add-form .btn { height: 46px; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.suggest button { font: inherit; font-size: .8rem; padding: 4px 10px; border-radius: 999px; border: 1px dashed var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.suggest button:hover { border-color: var(--accent); color: var(--accent); }
.suggest button.used { display: none; }
.rater { flex-wrap: wrap; }
.rater-main { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.rater-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rater-actions .link-input { width: 190px; font-size: .78rem; padding: 6px 8px; color: var(--muted); border-radius: 8px; }
@media (max-width: 700px) { .rater-actions .link-input { display: none; } }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 25%, var(--line)); }

/* Rating */
.rate-head { margin-bottom: 20px; }
.item-card { margin-bottom: 16px; }
.item-card h2 { display: flex; align-items: center; gap: 10px; font-size: 1.45rem; margin-bottom: 12px; }
.item-num { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 700 .9rem var(--font-body); }
.crit { padding: 12px 0; border-top: 1px solid var(--line); transition: background .2s; }
.crit-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.crit-name { font-weight: 600; }
.crit output { min-width: 2ch; text-align: right; font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; line-height: 1; color: var(--line); }
.crit.done output { color: var(--accent); }
.crit.missing { background: var(--danger-soft); margin: 0 -20px; padding: 12px 20px; }
.crit.missing .crit-name::after { content: " — still to score"; color: var(--danger); font-weight: 500; font-size: .85rem; }
.chips { display: grid; grid-template-columns: repeat(var(--n, 10), minmax(0, 1fr)); gap: 5px; }
.chips label { position: relative; }
.chips input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.chips span { display: grid; place-items: center; height: 44px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-weight: 600; user-select: none; transition: background .12s, color .12s, border-color .12s, transform .12s; }
.chips label:hover span { border-color: var(--accent); color: var(--ink); }
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); transform: scale(1.07); }
.chips input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 440px) {
  .item-card { padding: 16px; }
  .crit.missing { margin: 0 -16px; padding: 12px 16px; }
  .chips { gap: 3px; }
  .chips span { height: 40px; border-radius: 7px; font-size: .88rem; }
}
.sticky-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.sticky-inner { display: flex; align-items: center; gap: 16px; }
.sticky-progress { flex: 1; font-size: .9rem; }
.sticky-progress .progress { margin-top: 6px; }
.save-state { margin-left: 6px; color: var(--muted); font-size: .8rem; }
#submit-btn:not(.ready) { background: var(--surface-2); border-color: var(--line); color: var(--muted); }

/* Waiting */
.people { list-style: none; padding: 0; margin: 20px 0; text-align: left; }
.people li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; margin-bottom: 6px; border-radius: 10px; background: var(--surface-2); }
.people .done { color: var(--ok); font-weight: 600; }
.people .pending { color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* Results */
.results-head { text-align: center; margin: 12px 0 28px; }
.results-head p { margin-bottom: 20px; }
.drumroll { text-align: center; font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; margin: 8px 0 24px; animation: throb .5s ease-in-out infinite alternate; }
.winner-card { text-align: center; padding: 32px 20px; margin-bottom: 24px; border-radius: 20px; border: 2px solid var(--gold-bright); background: radial-gradient(circle at 50% 0%, var(--gold-soft), var(--surface) 75%); box-shadow: 0 10px 40px color-mix(in srgb, var(--gold-bright) 25%, transparent); }
.trophy { font-size: 3.5rem; line-height: 1; margin-bottom: 8px; }
.winner-card h2 { display: block; font-size: clamp(2rem, 7vw, 3.2rem); margin: 4px 0 8px; }
.big-score { margin: 0; font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; color: var(--gold); }
.big-score span { font-size: 1rem; font-weight: 600; color: var(--muted); }
.leaderboard { list-style: none; padding: 0; margin: 0 0 32px; display: grid; gap: 8px; }
.lb-row { display: grid; grid-template-columns: 58px 1fr auto; grid-template-areas: "rank name score" "rank bar bar"; column-gap: 12px; row-gap: 6px; align-items: center; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.lb-rank { grid-area: rank; font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; color: var(--muted); line-height: 1; }
.lb-rank small { display: block; margin-top: 3px; font: 600 .66rem var(--font-body); text-transform: uppercase; letter-spacing: .06em; }
.lb-name { grid-area: name; font-weight: 600; font-size: 1.05rem; }
.lb-score { grid-area: score; font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.lb-bar { grid-area: bar; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.lb-bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.lb-row.rank-1 { border-color: var(--gold-bright); background: var(--gold-soft); }
.lb-row.rank-1 .lb-rank { color: var(--gold); }
.lb-row.rank-1 .lb-bar span { background: var(--gold-bright); }

#reveal-btn { display: none; }
.results.pre-reveal #reveal-btn { display: inline-flex; }
.results.pre-reveal .winner-card,
.results.pre-reveal .leaderboard,
.results.pre-reveal .after-reveal,
.results.revealing .after-reveal { display: none; }
.results.revealing .reveal-step:not(.shown) { visibility: hidden; }
.results.revealing .winner-card:not(.shown) { display: none; }
.results.revealing .reveal-step.shown { animation: rise .55s cubic-bezier(.2, .8, .2, 1.15) both; }
.results.revealing .winner-card.shown { animation: burst .8s cubic-bezier(.2, .8, .2, 1.15) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes burst { 0% { opacity: 0; transform: scale(.6); } 60% { opacity: 1; transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes throb { from { transform: scale(1); } to { transform: scale(1.06); } }

.after-reveal { display: grid; gap: 16px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.cat { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); }
.cat .eyebrow { margin-bottom: 4px; }
.cat strong { display: block; font-size: 1.05rem; }
.cat span { color: var(--muted); font-size: .85rem; }
.table-scroll { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table.breakdown { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.breakdown th, .breakdown td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.breakdown th:first-child, .breakdown td:first-child { text-align: left; white-space: normal; min-width: 110px; padding-left: 0; }
.breakdown thead th { font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.breakdown tbody tr:last-child td { border-bottom: 0; }
.breakdown .overall { font-weight: 700; }
.breakdown td.best { color: var(--gold); font-weight: 700; }
details.card summary { cursor: pointer; list-style: none; font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "+"; float: right; color: var(--muted); }
details.card[open] summary::after { content: "−"; }
.scorecard { margin-top: 20px; }
.scorecard h3 { font-size: 1.05rem; }
.scorecard h3 .muted { font-family: var(--font-body); font-weight: 500; font-size: .9rem; }
.replay-row { text-align: center; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

@media (max-width: 560px) {
  main.wrap { padding-top: 20px; }
  .contest-card { flex-direction: column; align-items: flex-start; }
  .contest-card .side { align-items: flex-start; text-align: left; flex-direction: row; flex-wrap: wrap; }
  .new-contest { max-width: none; }
  .lb-row { grid-template-columns: 46px 1fr auto; padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
