:root {
    --bg: #e8e8e8;
    --surface: #f6f6f6;
    --text: #222;
    --muted: #666;
    --line: #ccc;
    --shadow: rgba(0, 0, 0, .2);
    --accent: #e4572e;
    --gold: #f2b705;
    --silver: #a8b0b8;
    --danger: #c0392b;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1e1e;
        --surface: #2a2a2a;
        --text: #eee;
        --muted: #aaa;
        --line: #444;
        --shadow: rgba(0, 0, 0, .6);
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; }
a { color: inherit; }
h1, h2 { margin: 0 0 .5em; }
button, .button { padding: 6px 14px; font: inherit; font-size: 14px; cursor: pointer; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: wait; }
input[type=text] { padding: 6px 8px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); }

header.site { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 16px; flex-wrap: wrap; }
.logo { font-weight: 800; font-size: 18px; text-decoration: none; }
nav { display: flex; gap: 16px; }
nav a { text-decoration: none; color: var(--muted); }
nav a:hover { color: var(--text); }
main { max-width: 1200px; margin: 0 auto; padding: 8px 16px 48px; }

.flash { padding: 8px 12px; border-radius: 6px; background: var(--surface); border-left: 4px solid var(--muted); }
.flash.success { border-color: #2e9e5b; }
.flash.error { border-color: var(--danger); }
.status { margin: 0; color: var(--muted); }
.animal { font-size: clamp(28px, 6vw, 48px); text-transform: capitalize; letter-spacing: -.02em; }
.hint { color: var(--muted); font-size: 14px; }
.prose { max-width: 640px; }

/* Drawing page */
.draw { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.headline { text-align: center; }
.headline .animal { margin: 0; }
.stage { position: relative; width: 100%; max-width: 800px; }
.stage canvas { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 2px 8px var(--shadow); touch-action: none; cursor: crosshair; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px;
    font-size: clamp(20px, 4vw, 32px); font-weight: 700; color: #222; background: rgba(255, 255, 255, .85); }
.draw[data-phase=drawing] .overlay { display: none; }
.draw[data-phase=over] .overlay { background: transparent; color: transparent; pointer-events: none; }
.draw:not([data-phase=drawing]) canvas { cursor: not-allowed; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; }
/* Tools fade out when you can't draw; Copy PNG stays usable after time's up */
.draw:not([data-phase=drawing]) .toolbar > :not(.copy) { opacity: .5; }
.timer { font-size: 20px; font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; font-weight: 700; }
.timer.hurry { color: var(--accent); }
input[type=color] { width: 40px; height: 32px; padding: 0; border: none; cursor: pointer; background: none; }
.fill { display: inline-flex; align-items: center; gap: 6px; }
.fill button { padding: 4px 8px; }
.swatch { position: relative; display: inline-flex; }
/* Transparent fill: checkerboard with a red slash over the swatch, ∅ button pressed */
.fill.none .swatch::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: 4px;
    background: linear-gradient(to top right, transparent 46%, #e00 46%, #e00 54%, transparent 54%),
                repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
.fill.none button { box-shadow: inset 0 2px 4px rgba(0, 0, 0, .35); }
.artist { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.saved { margin: 0; min-height: 1.4em; color: var(--muted); }
.saved a { color: var(--accent); font-weight: 700; }

.latest { max-width: 420px; margin: 48px auto 0; text-align: center; }
.latest h2 { font-size: 18px; }
.latest-winner { display: block; text-decoration: none; color: var(--muted); }
.latest-winner .paper { margin-bottom: 6px; }

/* Galleries */
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card { margin: 0; display: flex; flex-direction: column; gap: 6px; text-decoration: none; }
.paper { background: #fff; box-shadow: 0 2px 8px var(--shadow); aspect-ratio: 4 / 3; overflow: hidden; }
.paper svg, .paper canvas, .card .replay-canvas { display: block; width: 100%; height: auto; }
.card .replay-canvas { background: #fff; box-shadow: 0 2px 8px var(--shadow); }
.card figcaption, .card .caption { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.card .caption { display: block; color: var(--muted); }
.card .caption strong { color: var(--text); text-transform: capitalize; }
.author { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.winner .paper, .card.winner .replay-canvas { outline: 4px solid var(--gold); }
.card.runner-up .paper, .card.runner-up .replay-canvas { outline: 4px solid var(--silver); }
.medal { font-size: 20px; }
@media (min-width: 700px) {
    .grid .card.winner { grid-column: span 2; grid-row: span 2; }
}

.leaderboard, .rounds { border-collapse: collapse; margin-bottom: 32px; min-width: min(100%, 360px); }
.leaderboard th, .leaderboard td, .rounds th, .rounds td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.leaderboard td + td, .leaderboard th + th { text-align: center; }

/* Referee */
.panel { background: var(--surface); padding: 16px; border-radius: 8px; margin-bottom: 32px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.live-bar { font-size: 18px; }
.dot-live { color: var(--danger); font-size: 14px; animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.live-card.active .paper { outline: 3px solid var(--accent); }
.judge-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 8px 0; }
.judge-bar p { flex: 1; margin: 0; }
.pick { display: flex; gap: 12px; align-items: center; font-size: 14px; flex-wrap: wrap; }
.pick label { cursor: pointer; }
.pick .danger { margin-left: auto; }
.rounds { width: 100%; }

/* Replays: timeline, timer, speed */
.scrubber { display: flex; align-items: center; gap: 8px; }
.scrubber input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.scrubber .play { width: 32px; }
.replay-time { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 700; white-space: nowrap; min-width: 9ch; text-align: right; }
.scrubber.shared { flex-basis: 100%; margin-top: 8px; order: 10; } /* below the bar, after Publish */
.scrubber.shared .replay-time { font-size: 18px; }
.replay-all { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.speed { display: inline-flex; }
.speed button { border-radius: 0; margin-left: -1px; }
.speed button:first-child { border-radius: 6px 0 0 6px; }
.speed button:last-child { border-radius: 0 6px 6px 0; }
.speed button[aria-pressed=true] { background: var(--text); color: var(--bg); border-color: var(--text); }
.section-head .inline-form { font-size: 14px; }

/* Results slide */
.slide-page { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.slide-preview { width: 100%; max-width: 960px; height: auto; aspect-ratio: 16 / 9; box-shadow: 0 2px 12px var(--shadow); background: #fff; }
.slide-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }
.slide-actions progress { width: 200px; }

/* Disqualified drawings */
.paper { position: relative; }
.card.disqualified .paper svg { opacity: .45; filter: grayscale(.7); }
.dq-stamp { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-14deg); padding: 4px 14px;
    border: 4px solid #d62828; border-radius: 6px; color: #d62828; font-weight: 900; font-size: clamp(16px, 4vw, 30px);
    letter-spacing: .08em; text-transform: uppercase; background: rgba(255, 255, 255, .7); pointer-events: none; }
.dq-reason { margin: 0; color: #d62828; font-size: 13px; }
.dq-input { flex: 1; min-width: 0; padding: 3px 6px !important; font-size: 12px !important; }

/* Name prompt */
.name-dialog { border: none; border-radius: 12px; padding: 24px; width: min(360px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.name-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.name-dialog form { display: flex; flex-direction: column; gap: 10px; }
.name-dialog h2 { margin: 0; }
.name-dialog .hint { margin: 0; }
.name-dialog input { font-size: 18px; padding: 10px 12px; }
