@font-face { font-family: 'Cinzel Decorative'; src: url(/fonts/cinzel-decorative-latin-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Cinzel'; src: url(/fonts/cinzel-latin-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Cinzel'; src: url(/fonts/cinzel-latin-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-latin-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-cyrillic-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-latin-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-cyrillic-700-normal.woff2) format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-latin-500-italic.woff2) format('woff2'); font-weight: 500; font-style: italic; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-cyrillic-500-italic.woff2) format('woff2'); font-weight: 500; font-style: italic; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'IM Fell English'; src: url(/fonts/im-fell-english-latin-400-italic.woff2) format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }

:root
{
    --night-0: #04060f;
    --night-1: #0a1028;
    --night-2: #151d47;
    --gold-1: #fff1b8;
    --gold-2: #e9c766;
    --gold-3: #b8862b;
    --gold-4: #7a5418;
    --ink: #f2e6c8;
    --ink-dim: #b8ad92;
    --parchment: #f1e3bf;
    --parchment-ink: #2e2010;
    --panel: rgba(12, 17, 42, 0.8);
    --panel-border: rgba(233, 199, 102, 0.36);
    --danger: #ef8a73;
    --radius: 18px;
    --house: #e9c766;
    --house-accent: #fff1b8;
    --house-deep: #0a1028;
    --title: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
    --caps: 'Cinzel', Georgia, serif;
    --body: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
    --script: 'IM Fell English', 'Cormorant Garamond', Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

html, body { margin: 0; min-height: 100%; }

body
{
    background: var(--night-0);
    color: var(--ink);
    font-family: var(--body);
    font-weight: 500;
    font-size: 19px;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ---------- sky, candles, sparkles ---------- */

.sky-bg
{
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(70% 45% at 20% 10%, rgba(88, 76, 170, 0.28), transparent 70%),
        radial-gradient(60% 40% at 85% 25%, rgba(40, 110, 150, 0.18), transparent 70%),
        radial-gradient(120% 80% at 50% -10%, #25306b 0%, #0d1333 45%, #05070f 100%);
}

#sky, #sparkles
{
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#sky { z-index: 1; }

#sparkles { z-index: 90; }

.candles
{
    position: fixed;
    inset: 0 0 auto 0;
    height: 46vh;
    z-index: 2;
    pointer-events: none;
    overflow: hidden;
}

.candle
{
    position: absolute;
    width: 9px;
    height: 44px;
    animation: candle-float var(--float, 7s) ease-in-out var(--delay, 0s) infinite alternate;
    will-change: transform;
}

.candle .wax
{
    position: absolute;
    inset: 0;
    border-radius: 3px 3px 2px 2px;
    background: linear-gradient(90deg, #b9ab8c 0%, #fff8e6 35%, #efe4c9 65%, #a99a7a 100%);
    box-shadow: 0 0 10px rgba(255, 210, 120, 0.25);
}

.candle .wax::before
{
    content: '';
    position: absolute;
    left: 1px;
    top: 0;
    width: 4px;
    height: 12px;
    border-radius: 0 0 3px 3px;
    background: #fff8e6;
}

.candle .flame
{
    position: absolute;
    left: 50%;
    top: -15px;
    width: 8px;
    height: 15px;
    margin-left: -4px;
    border-radius: 50% 50% 40% 40% / 65% 65% 35% 35%;
    background: radial-gradient(circle at 50% 72%, #ffffff 0%, #fff0a8 28%, #ffb23a 58%, rgba(255, 120, 0, 0) 76%);
    transform-origin: 50% 100%;
    animation: flame-flicker 0.14s ease-in-out infinite alternate;
}

.candle .glow
{
    position: absolute;
    left: 50%;
    top: -42px;
    width: 96px;
    height: 96px;
    margin-left: -48px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 196, 90, 0.34) 0%, rgba(255, 170, 60, 0.08) 42%, transparent 70%);
    animation: glow-breathe 2.6s ease-in-out infinite alternate;
}

@keyframes candle-float
{
    from { transform: translateY(-7px) scale(var(--s, 1)); }
    to { transform: translateY(9px) scale(var(--s, 1)); }
}

@keyframes flame-flicker
{
    from { transform: scale(1, 1) rotate(-2deg); opacity: 0.92; }
    to { transform: scale(0.9, 1.12) rotate(2deg); opacity: 1; }
}

@keyframes glow-breathe
{
    from { opacity: 0.7; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1.06); }
}

/* ---------- layout ---------- */

.page
{
    position: relative;
    z-index: 5;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.wrap { width: 100%; max-width: 560px; }

.wrap.wide { max-width: 1240px; }

.center { text-align: center; }

.stack > * + * { margin-top: 14px; }

.row { display: flex; gap: 10px; align-items: center; }

.row.wrap-row { flex-wrap: wrap; }

.grow { flex: 1 1 auto; min-width: 0; }

/* ---------- typography ---------- */

.eyebrow
{
    font-family: var(--caps);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--gold-2);
    opacity: 0.85;
}

.title
{
    font-family: var(--title);
    font-weight: 700;
    font-size: clamp(34px, 9vw, 64px);
    line-height: 1.05;
    margin: 6px 0 4px;
    letter-spacing: 0.01em;
}

.gilded
{
    background: linear-gradient(180deg, #fff6c8 0%, #f1d27a 38%, #b98a2c 52%, #f7dc86 70%, #c9962f 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 2px 0 rgba(60, 35, 5, 0.9)) drop-shadow(0 0 18px rgba(233, 199, 102, 0.35));
}

h2.section
{
    font-family: var(--caps);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gold-2);
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

h2.section .count
{
    font-family: var(--body);
    letter-spacing: 0;
    color: var(--ink-dim);
    font-size: 17px;
    text-transform: none;
}

.muted { color: var(--ink-dim); }

.small { font-size: 15px; }

.lead { font-size: 21px; }

.lead, .muted, .eyebrow { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 12px rgba(5, 7, 15, 0.9); }

.divider
{
    height: 14px;
    margin: 18px auto;
    width: 70%;
    background:
        radial-gradient(circle, var(--gold-2) 0 3px, transparent 4px) center / 14px 14px no-repeat,
        linear-gradient(90deg, transparent, rgba(233, 199, 102, 0.6) 30%, transparent 48%, transparent 52%, rgba(233, 199, 102, 0.6) 70%, transparent) center / 100% 1px no-repeat;
}

/* ---------- panels and controls ---------- */

.panel
{
    position: relative;
    background: linear-gradient(180deg, rgba(20, 27, 64, 0.84), rgba(9, 12, 32, 0.9));
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow:
        inset 0 0 0 5px rgba(8, 11, 28, 0.85),
        inset 0 0 0 6px rgba(233, 199, 102, 0.16),
        0 22px 50px rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.btn
{
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 52px;
    padding: 12px 24px;
    border-radius: 999px;
    border: 1px solid #f8e3a0;
    color: #2a1a05;
    background: linear-gradient(180deg, #fff0b3 0%, #e7c25d 46%, #c4922f 54%, #e8c76a 100%);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35), 0 8px 26px rgba(233, 199, 102, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.7);
    font-family: var(--caps);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    overflow: hidden;
    user-select: none;
    transition: transform 0.12s ease, filter 0.2s ease;
}

.btn::after
{
    content: '';
    position: absolute;
    top: -50%;
    left: -60%;
    width: 40%;
    height: 200%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
    transform: rotate(20deg);
    animation: btn-shine 4.5s ease-in-out infinite;
}

.btn:active { transform: translateY(1px) scale(0.985); }

.btn:focus-visible { outline: 3px solid var(--gold-1); outline-offset: 3px; }

.btn.block { width: 100%; }

.btn.big { min-height: 62px; font-size: 17px; }

.btn.ghost
{
    color: var(--gold-2);
    background: rgba(10, 14, 34, 0.55);
    border-color: var(--panel-border);
    box-shadow: none;
}

.btn.ghost::after, .btn[disabled]::after { display: none; }

.btn.small-btn { min-height: 40px; padding: 8px 16px; font-size: 13px; }

.btn[disabled] { filter: grayscale(0.75) brightness(0.7); cursor: default; transform: none; }

@keyframes btn-shine
{
    0%, 70% { left: -60%; }
    100% { left: 130%; }
}

.icon-btn
{
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: rgba(10, 14, 34, 0.65);
    color: var(--gold-2);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    flex: none;
}

.icon-btn svg { width: 22px; height: 22px; }

.icon-btn.off { color: var(--ink-dim); opacity: 0.6; }

.icon-btn.off svg .wave { display: none; }

.icon-btn.off::after
{
    content: '';
    position: absolute;
    width: 26px;
    height: 2px;
    background: currentColor;
    transform: rotate(-45deg);
}

.icon-btn { position: relative; }

.field
{
    width: 100%;
    min-height: 56px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid #c9a75a;
    background: linear-gradient(180deg, #f8eed4, #eadbb3);
    color: var(--parchment-ink);
    font-family: var(--body);
    font-weight: 700;
    font-size: 22px;
    box-shadow: inset 0 2px 6px rgba(80, 50, 10, 0.25);
    outline: none;
    transition: box-shadow 0.2s ease;
}

.field::placeholder { color: rgba(46, 32, 16, 0.45); font-weight: 500; font-style: italic; }

.field:focus { box-shadow: inset 0 2px 6px rgba(80, 50, 10, 0.25), 0 0 0 3px rgba(233, 199, 102, 0.55), 0 0 28px rgba(233, 199, 102, 0.4); }

.field.code { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-family: var(--caps); }

label.label
{
    display: block;
    font-family: var(--caps);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--gold-2);
    margin-bottom: 8px;
}

.code-chip
{
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px dashed var(--panel-border);
    font-family: var(--caps);
    font-weight: 700;
    letter-spacing: 0.22em;
    color: var(--gold-1);
    background: rgba(10, 14, 34, 0.55);
    font-size: 15px;
}

.top-tools
{
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    z-index: 60;
    display: flex;
    gap: 8px;
}

/* ---------- toast ---------- */

.toasts
{
    position: fixed;
    left: 50%;
    top: max(14px, env(safe-area-inset-top));
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(92vw, 440px);
    pointer-events: none;
}

.toast
{
    padding: 12px 16px;
    border-radius: 12px;
    background: linear-gradient(180deg, #f8eed4, #e7d6aa);
    color: var(--parchment-ink);
    font-weight: 700;
    font-size: 17px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid #c9a75a;
    animation: toast-in 0.35s cubic-bezier(.2, 1.4, .4, 1) both;
    text-align: center;
}

.toast.error { background: linear-gradient(180deg, #ffd9cc, #f2b6a3); border-color: #c0634d; }

.toast.out { animation: toast-out 0.3s ease both; }

@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.96); } to { opacity: 1; transform: none; } }

@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ---------- the hat ---------- */

.hat
{
    position: relative;
    width: min(64vw, 300px);
    aspect-ratio: 900 / 881;
    margin: 0 auto;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.hat .hat-shadow
{
    position: absolute;
    left: 10%;
    right: 10%;
    bottom: -3%;
    height: 12%;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), transparent);
    animation: shadow-breathe 4.5s ease-in-out infinite;
}

.hat .hat-aura
{
    position: absolute;
    inset: -12%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 214, 120, 0.22), transparent 62%);
    opacity: 0;
    transition: opacity 0.8s ease;
}

.hat .hat-jump, .hat .hat-sway, .hat .hat-jitter, .hat .hat-squash
{
    position: absolute;
    inset: 0;
    transform-origin: 50% 92%;
}

.hat .hat-squash { will-change: transform; }

.hat img
{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
    -webkit-user-drag: none;
    filter: drop-shadow(0 16px 22px rgba(0, 0, 0, 0.55));
    will-change: transform;
}

.hat svg.hat-face { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }

.hat .eye-glow { opacity: 0; transition: opacity 0.6s ease; mix-blend-mode: screen; }

.hat .hat-sway { animation: hat-idle 4.8s ease-in-out infinite; }

.hat[data-state="sleep"] .hat-sway { animation: hat-sleep 4.2s ease-in-out infinite; }

.hat[data-state="think"] .hat-sway { animation: hat-think 1.9s ease-in-out infinite; }

.hat[data-state="think"] .eye-glow, .hat[data-state="drum"] .eye-glow { opacity: 1; animation: eye-pulse 1.2s ease-in-out infinite alternate; }

.hat[data-state="think"] .hat-aura, .hat[data-state="drum"] .hat-aura { opacity: 1; }

.hat[data-state="drum"] .hat-sway { animation: hat-think 0.9s ease-in-out infinite; }

.hat[data-state="drum"] .hat-jitter { animation: hat-tremble 0.11s linear infinite; }

.hat.shout .hat-jump { animation: hat-shout 1.1s cubic-bezier(.2, 1.3, .35, 1) both; }

.hat .hat-zzz
{
    position: absolute;
    right: 4%;
    top: 4%;
    font-family: var(--script);
    font-style: italic;
    color: var(--gold-1);
    font-size: clamp(18px, 5vw, 28px);
    pointer-events: none;
    opacity: 0;
}

.hat[data-state="sleep"] .hat-zzz { opacity: 1; }

.hat .hat-zzz span
{
    position: absolute;
    right: 0;
    top: 0;
    opacity: 0;
    text-shadow: 0 0 12px rgba(255, 230, 150, 0.8);
}

.hat[data-state="sleep"] .hat-zzz span { animation: zzz 3.6s ease-out infinite; }

.hat .hat-zzz span:nth-child(2) { animation-delay: 1.2s !important; font-size: 1.25em; }

.hat .hat-zzz span:nth-child(3) { animation-delay: 2.4s !important; font-size: 1.5em; }

@keyframes hat-idle
{
    0%, 100% { transform: rotate(-2.2deg); }
    50% { transform: rotate(2.4deg); }
}

@keyframes hat-sleep
{
    0%, 100% { transform: rotate(-1.2deg) scale(1, 1); }
    50% { transform: rotate(1deg) scale(1.012, 0.985); }
}

@keyframes hat-think
{
    0%, 100% { transform: rotate(-5deg) skewX(2deg); }
    25% { transform: rotate(2deg) skewX(-1deg) translateY(-1.5%); }
    50% { transform: rotate(6deg) skewX(-2.5deg); }
    75% { transform: rotate(-1deg) skewX(1deg) translateY(-1%); }
}

@keyframes hat-tremble
{
    0% { transform: translate(0, 0) rotate(0); }
    25% { transform: translate(0.6%, -0.4%) rotate(0.8deg); }
    50% { transform: translate(-0.5%, 0.3%) rotate(-0.7deg); }
    75% { transform: translate(0.4%, 0.5%) rotate(0.5deg); }
    100% { transform: translate(0, 0) rotate(0); }
}

@keyframes hat-shout
{
    0% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-12%) scale(1.12, 1.08); }
    55% { transform: translateY(0) scale(1.06, 0.94); }
    75% { transform: translateY(-3%) scale(0.98, 1.03); }
    100% { transform: translateY(0) scale(1); }
}

@keyframes eye-pulse
{
    from { opacity: 0.55; }
    to { opacity: 1; }
}

@keyframes shadow-breathe
{
    0%, 100% { transform: scaleX(1); opacity: 0.9; }
    50% { transform: scaleX(0.94); opacity: 0.75; }
}

@keyframes zzz
{
    0% { opacity: 0; transform: translate(0, 0) scale(0.6); }
    20% { opacity: 1; }
    100% { opacity: 0; transform: translate(26px, -60px) scale(1.1); }
}

/* ---------- speech bubble ---------- */

.bubble
{
    position: relative;
    max-width: min(88vw, 460px);
    margin: 0 auto;
    padding: 14px 20px;
    border-radius: 22px;
    background: linear-gradient(180deg, #fbf3dc, #eadab0);
    color: #2c1d0c;
    font-family: var(--script);
    font-style: italic;
    font-size: clamp(20px, 5.4vw, 28px);
    line-height: 1.25;
    text-align: center;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(150, 110, 40, 0.5);
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(.2, 1.4, .4, 1);
    min-height: 2.6em;
    display: grid;
    place-items: center;
}

.bubble.show { opacity: 1; transform: none; }

.bubble::after
{
    content: '';
    position: absolute;
    left: 50%;
    bottom: -12px;
    width: 24px;
    height: 24px;
    margin-left: -12px;
    background: #eadab0;
    transform: rotate(45deg);
    box-shadow: 1px 1px 0 rgba(150, 110, 40, 0.5);
    border-radius: 0 0 6px 0;
}

/* ---------- house bits ---------- */

.house-g { --house: #ae0001; --house-accent: #eeba30; --house-deep: #3a0505; }
.house-h { --house: #e5b52e; --house-accent: #2b2420; --house-deep: #2e2408; }
.house-r { --house: #2a4ea8; --house-accent: #c99a5b; --house-deep: #071233; }
.house-s { --house: #1f7a42; --house-accent: #c8ced4; --house-deep: #04200f; }

.chip
{
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(233, 199, 102, 0.25);
    background: rgba(255, 255, 255, 0.06);
    font-weight: 700;
    font-size: 18px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chip.sorted
{
    background: linear-gradient(180deg, color-mix(in srgb, var(--house) 75%, #000 0%), color-mix(in srgb, var(--house) 70%, #000 30%));
    border-color: var(--house-accent);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.chip.house-h.sorted { color: #241c08; text-shadow: none; }

.chip.me { box-shadow: 0 0 0 2px var(--gold-1), 0 0 18px rgba(255, 230, 150, 0.6); }

.chip.pop { animation: chip-pop 0.6s cubic-bezier(.2, 1.6, .4, 1) both; }

.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-dim); flex: none; }

.chip.sorted .dot { background: var(--house-accent); }

@keyframes chip-pop { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: none; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.houses
{
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.house-tile
{
    position: relative;
    border-radius: 14px;
    padding: 10px 4px 10px;
    text-align: center;
    background: linear-gradient(180deg, color-mix(in srgb, var(--house) 55%, transparent), color-mix(in srgb, var(--house-deep) 85%, transparent));
    border: 1px solid color-mix(in srgb, var(--house-accent) 60%, transparent);
    overflow: hidden;
}

.house-tile img { width: 72%; max-width: 90px; display: block; margin: 0 auto 4px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5)); }

.house-tile .hname { font-family: var(--caps); font-weight: 700; font-size: clamp(9px, 2.6vw, 14px); letter-spacing: 0.04em; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }

.house-tile .hcount { font-weight: 700; font-size: 18px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }

.house-tile .hcount small { opacity: 0.7; font-size: 14px; }

.house-tile.bump { animation: tile-bump 0.7s cubic-bezier(.2, 1.6, .4, 1); }

@keyframes tile-bump { 0% { transform: scale(1); } 40% { transform: scale(1.12); box-shadow: 0 0 30px var(--house-accent); } 100% { transform: scale(1); } }

/* ---------- the sorting stage ---------- */

.stage
{
    position: fixed;
    inset: 0;
    z-index: 85;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease, visibility 0s linear 0.6s;
    overflow: hidden;
}

.stage.open { opacity: 1; visibility: visible; transition: opacity 0.6s ease; }

.stage .stage-bg
{
    position: absolute;
    inset: 0;
    background: radial-gradient(60% 50% at 50% 42%, rgba(34, 30, 78, 0.94), rgba(4, 6, 15, 0.985) 75%);
    transition: background 0.8s ease;
}

.stage .stage-bg::after
{
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(55% 45% at 50% 40%, color-mix(in srgb, var(--house) 85%, transparent), color-mix(in srgb, var(--house-deep) 92%, transparent) 70%, rgba(3, 4, 10, 0.98));
    opacity: 0;
    transition: opacity 0.5s ease;
}

.stage[data-phase="reveal"] .stage-bg::after { opacity: 1; }

/* Leaving the reveal, the house colour goes at once: fading out, it would already wear the next student's house. */
.stage:not([data-phase="reveal"]) .stage-bg::after { transition: none; }

.stage .spotlight
{
    position: absolute;
    left: 50%;
    top: -10%;
    width: 120vmin;
    height: 120vh;
    transform: translateX(-50%);
    background: conic-gradient(from 180deg at 50% 0%, transparent 160deg, rgba(255, 236, 180, 0.12) 172deg, rgba(255, 236, 180, 0.2) 180deg, rgba(255, 236, 180, 0.12) 188deg, transparent 200deg);
    pointer-events: none;
    opacity: 0.9;
}

.stage[data-phase="reveal"] .spotlight { opacity: 0; transition: opacity 0.5s; }

.stage .rays
{
    position: absolute;
    left: 50%;
    top: 46%;
    width: 170vmax;
    height: 170vmax;
    margin: -85vmax 0 0 -85vmax;
    background: repeating-conic-gradient(from 0deg, rgba(255, 245, 210, 0.16) 0deg 5deg, transparent 5deg 15deg);
    -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 45%);
    mask-image: radial-gradient(circle, #000 0%, transparent 45%);
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.6s ease, transform 1.2s cubic-bezier(.2, 1, .3, 1);
    pointer-events: none;
}

.stage[data-phase="reveal"] .rays { opacity: 1; transform: scale(1); animation: rays-spin 30s linear infinite; }

@keyframes rays-spin { to { rotate: 360deg; } }

.stage .flash
{
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 45%, #fff, rgba(255, 245, 210, 0.6) 40%, transparent 75%);
    opacity: 0;
    pointer-events: none;
}

.stage .flash.go { animation: flash 1.1s ease-out both; }

@keyframes flash { 0% { opacity: 0; } 8% { opacity: 1; } 100% { opacity: 0; } }

.stage .stage-inner
{
    position: relative;
    width: 100%;
    max-width: 720px;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.stage .call { transition: opacity 0.5s ease, transform 0.5s ease; }

.stage .call .stage-name
{
    font-family: var(--title);
    font-weight: 700;
    font-size: clamp(34px, 10vw, 84px);
    line-height: 1.05;
    word-break: break-word;
    animation: name-in 0.9s cubic-bezier(.2, 1.4, .4, 1) both;
}

.stage .call .stage-sub { font-family: var(--caps); font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; font-size: clamp(13px, 3.4vw, 18px); color: var(--gold-1); margin-top: 4px; }

.stage.me .call .stage-sub { color: #fff; text-shadow: 0 0 16px rgba(255, 230, 150, 0.9); }

@keyframes name-in { from { opacity: 0; transform: translateY(20px) scale(0.85); letter-spacing: 0.2em; } to { opacity: 1; transform: none; } }

.stage .hat { width: min(62vw, 42vh, 360px); transition: width 0.8s cubic-bezier(.2, 1, .3, 1), transform 0.8s ease; }

.stage[data-phase="reveal"] .hat { width: min(34vw, 20vh, 190px); }

.stage .bubble { min-width: min(80vw, 320px); }

.stage[data-phase="reveal"] .bubble { display: none; }

.stage .reveal { display: none; flex-direction: column; align-items: center; gap: 6px; }

.stage[data-phase="reveal"] .reveal { display: flex; }

.stage[data-phase="reveal"] .call { display: none; }

.stage .reveal .crest
{
    width: min(46vw, 28vh, 230px);
    filter: drop-shadow(0 0 30px color-mix(in srgb, var(--house-accent) 70%, transparent)) drop-shadow(0 12px 20px rgba(0, 0, 0, 0.6));
    animation: crest-in 1.2s cubic-bezier(.15, 1.5, .35, 1) both;
}

.stage .reveal .house-name
{
    font-family: var(--title);
    font-weight: 700;
    font-size: clamp(42px, 12.5vw, 110px);
    line-height: 1;
    letter-spacing: 0.02em;
    color: #fff;
    text-shadow: 0 0 24px color-mix(in srgb, var(--house-accent) 85%, transparent), 0 4px 0 rgba(0, 0, 0, 0.45), 0 0 60px var(--house);
    animation: house-in 0.9s cubic-bezier(.2, 1.5, .35, 1) 0.15s both;
}

.stage .reveal .traits { font-family: var(--caps); font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; font-size: clamp(12px, 3.3vw, 17px); color: var(--house-accent); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9); animation: fade-up 0.7s ease 0.9s both; }

.stage.house-h .reveal .traits { color: #fff3c4; }

.stage .reveal .welcome { font-size: clamp(22px, 6vw, 34px); font-weight: 700; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8); animation: fade-up 0.7s ease 1.3s both; }

.stage .reveal .quip
{
    font-family: var(--script);
    font-style: italic;
    font-size: clamp(19px, 5vw, 28px);
    color: var(--gold-1);
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
    max-width: 560px;
    animation: fade-up 0.7s ease 2.2s both;
}

.stage .reveal .mates { animation: fade-up 0.7s ease 3s both; max-width: 560px; }

.stage .reveal .mates .label { margin: 8px 0 6px; color: #fff; opacity: 0.85; }

.stage .reveal .tap-hint { font-size: 15px; color: rgba(255, 255, 255, 0.6); animation: fade-up 0.7s ease 4s both; }

@keyframes crest-in { 0% { opacity: 0; transform: scale(0.2) rotate(-25deg); } 60% { opacity: 1; } 100% { opacity: 1; transform: none; } }

@keyframes house-in { from { opacity: 0; transform: scale(2.2); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }

@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.stage .stage-close
{
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: 14px;
    z-index: 2;
}

.stage .drum-ring
{
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    pointer-events: none;
}

.stage[data-phase="drum"] .stage-inner { animation: drum-pulse 0.45s ease-in-out infinite; }

@keyframes drum-pulse { 50% { transform: scale(1.012); } }

/* ---------- unlock overlay (screens that start without a tap) ---------- */

.unlock
{
    position: fixed;
    inset: 0;
    z-index: 95;
    display: grid;
    place-items: center;
    background: rgba(3, 5, 12, 0.72);
    cursor: pointer;
    text-align: center;
    padding: 20px;
}

.unlock .wand { font-size: 64px; animation: wand-wave 1.6s ease-in-out infinite; display: inline-block; }

@keyframes wand-wave { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(14deg); } }

/* ---------- modal ---------- */

.modal
{
    position: fixed;
    inset: 0;
    z-index: 75;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(3, 5, 12, 0.7);
    overflow-y: auto;
}

.modal .panel { width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); overflow-y: auto; }

.modal .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }

.qr
{
    background: #f6ecd2;
    border-radius: 16px;
    padding: 14px;
    display: inline-block;
    box-shadow: 0 0 0 4px rgba(233, 199, 102, 0.55), 0 0 40px rgba(233, 199, 102, 0.35);
    line-height: 0;
}

.qr svg { width: 100%; height: auto; display: block; }

.link-box
{
    font-family: var(--body);
    font-weight: 700;
    font-size: 18px;
    word-break: break-all;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(233, 199, 102, 0.25);
    user-select: all;
}

@media (prefers-reduced-motion: reduce)
{
    .candle, .candle .flame, .candle .glow, .hat .hat-sway, .btn::after, .stage .rays { animation: none !important; }
}

.bubble > span { grid-area: 1 / 1; }

.bubble .bubble-size { visibility: hidden; }
