:root {
    --bg-color: #0b0e14;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #7c3aed;
    --accent-glow: rgba(124, 58, 237, 0.5);
    --color-a: #0ea5e9; /* Cyan */
    --color-b: #8b5cf6; /* Purple */
    --color-c: #ec4899; /* Pink */
    --color-d: #f59e0b; /* Amber */
    --success-color: #10b981;
    --font-family: 'Outfit', sans-serif;
    --radius: 24px;
    --transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.background-glow {
    position: fixed;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    background: radial-gradient(circle at 50% 50%, rgba(124, 58, 237, 0.15) 0%, rgba(11, 14, 20, 1) 70%);
    z-index: -1;
    pointer-events: none;
}

.app-layout {
    width: 100vw;
    height: 100vh;
    display: flex;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.iframe-area {
    flex: 1;
    height: 100%;
    background: #000;
}

#main-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.sidebar {
    width: 400px;
    height: 100%;
    background: rgba(11, 14, 20, 0.8);
    backdrop-filter: blur(40px);
    border-left: 1px solid var(--card-border);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    /* The sidebar is the scroll container — never let its contents bleed
       into the iframe pane. Manual scrolling is disabled because the JS
       autoscroller drives scrollTop while no poll is open. */
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar.locked { overflow-y: hidden; }

header {
    text-align: center;
    margin-bottom: 2rem;
}

.status-badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-color);
    margin-bottom: 1rem;
    backdrop-filter: blur(10px);
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sub-title {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    font-weight: 600;
    text-align: center;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: var(--transition);
}

.card.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* Phase 0: Idle */
.empty-state {
    text-align: center;
    padding: 3rem 0;
}

.pulse-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.8; }
}

/* Phase 1: Ongoing */
.options-list {
    display: grid;
    gap: 1rem;
}

.option-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--card-border);
    padding: 1.25rem 1.5rem;
    border-radius: 16px;
    transition: var(--transition);
}

.option-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-color);
}

.option-label {
    width: 32px;
    height: 32px;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    font-weight: 700;
    margin-right: 1.25rem;
}

#opt-A .option-label { background: var(--color-a); box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4); }
#opt-B .option-label { background: var(--color-b); box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4); }
#opt-C .option-label { background: var(--color-c); box-shadow: 0 4px 12px rgba(236, 72, 153, 0.4); }
#opt-D .option-label { background: var(--color-d); box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4); }

.option-text {
    font-size: 1.1rem;
    font-weight: 400;
}

/* Hide a result row when its slot isn't offered (e.g. D off this round). */
.result-item.hidden { display: none; }

/* Phase 2: Results */
.results-list {
    display: grid;
    gap: 2rem;
}

.result-item {
    width: 100%;
}

.result-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.result-label {
    flex: 1;
    min-width: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.result-percent {
    flex-shrink: 0;
    font-size: 1rem;
    font-weight: 700;
    display: inline-flex;
    gap: 0.5rem;
    align-items: baseline;
}

.result-votes {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
}

#live-perc-A, #res-perc-A { color: var(--color-a); }
#live-perc-B, #res-perc-B { color: var(--color-b); }
#live-perc-C, #res-perc-C { color: var(--color-c); }
#live-perc-D, #res-perc-D { color: var(--color-d); }

.progress-bar-bg {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 100px;
    overflow: hidden;
    border: 1px solid var(--card-border);
}

.progress-bar-fill {
    height: 100%;
    border-radius: 100px;
    width: 0;
    transition: width 1.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#live-fill-A, #res-fill-A { background: linear-gradient(90deg, var(--color-a) 0%, #38bdf8 100%); box-shadow: 0 0 20px rgba(14, 165, 233, 0.3); }
#live-fill-B, #res-fill-B { background: linear-gradient(90deg, var(--color-b) 0%, #a78bfa 100%); box-shadow: 0 0 20px rgba(139, 92, 246, 0.3); }
#live-fill-C, #res-fill-C { background: linear-gradient(90deg, var(--color-c) 0%, #f472b6 100%); box-shadow: 0 0 20px rgba(236, 72, 153, 0.3); }
#live-fill-D, #res-fill-D { background: linear-gradient(90deg, var(--color-d) 0%, #fbbf24 100%); box-shadow: 0 0 20px rgba(245, 158, 11, 0.3); }



.countdown {
    margin: 0.5rem 0 1rem;
    padding: 0.7rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
}
.countdown.hidden { display: none; }
.countdown-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}
.countdown-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    font-weight: 600;
}
.countdown-time {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.countdown-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.04);
    border-radius: 100px;
    overflow: hidden;
    border: 1px solid var(--card-border);
}
.countdown-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent-color) 0%, #a78bfa 100%);
    border-radius: 100px;
    box-shadow: 0 0 12px var(--accent-glow);
    /* width is set inline by JS; transition keeps the local tick smooth */
    transition: width 0.18s linear;
}

.history {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
}

.history.hidden { display: none; }

.history-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.history-item {
    /* Two-row layout so long titles / winners can wrap onto multiple lines
       without truncation. The pill sits in column 1, spanning both rows. */
    display: grid;
    grid-template-columns: 1.25rem 1fr auto;
    grid-template-areas:
        "slot title    meta"
        "slot winner   meta";
    column-gap: 0.6rem;
    row-gap: 0.15rem;
    font-size: 0.85rem;
    line-height: 1.3;
    padding: 0.25rem 0;
}

.history-slot {
    grid-area: slot;
    align-self: start;
    margin-top: 0.1rem;     /* baseline alignment with the title row */
    font-weight: 700;
    font-size: 0.75rem;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #0b0e14;
}
.history-slot.slot-A { background: var(--color-a); }
.history-slot.slot-B { background: var(--color-b); }
.history-slot.slot-C { background: var(--color-c); }
.history-slot.slot-D { background: var(--color-d); }

.history-title-text {
    grid-area: title;
    color: var(--text-secondary);
    overflow-wrap: anywhere;     /* break very long unbroken tokens */
    word-break: break-word;
}

.history-winner {
    grid-area: winner;
    font-weight: 600;
    color: var(--text-primary);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.history-meta {
    grid-area: meta;
    align-self: center;
    color: var(--text-secondary);
    font-size: 0.7rem;
    white-space: nowrap;         /* "37% · 12/32" stays on one line */
}

.howto {
    margin-top: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
}
.howto-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}
.howto-line {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--text-primary);
    margin: 0;
}
.howto-line + .howto-line {
    margin-top: 0.4rem;
}
.howto-line.muted {
    color: var(--text-secondary);
    font-size: 0.72rem;
}
.howto code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--card-border);
}

@media (max-width: 640px) {
    .container { padding: 1rem; }
    h1 { font-size: 2rem; }
}

.poll-question {
    margin: 0 0 1rem;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
}
.poll-question.hidden { display: none; }

.pick {
    margin-top: 1.5rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: rgba(120, 220, 150, 0.10);
    border: 1px solid rgba(120, 220, 150, 0.35);
}
.pick.hidden { display: none; }
.pick-title { margin: 0 0 0.4rem; font-size: 0.95rem; font-weight: 700; }
.pick-decision { margin: 0; line-height: 1.4; font-weight: 600; }

.scold {
    margin-top: 1.5rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: rgba(255, 120, 80, 0.10);
    border: 1px solid rgba(255, 120, 80, 0.35);
}
.scold.hidden { display: none; }
.scold-title { margin: 0 0 0.4rem; font-size: 0.95rem; font-weight: 700; }
.scold-target { margin: 0 0 0.25rem; font-style: italic; opacity: 0.8; }
.scold-message { margin: 0; line-height: 1.4; }

/* Working glow — a slowly pulsing orange border hugging the inside edge of the
   whole viewport while Claude is actively working (no poll awaiting votes).
   A dedicated fixed overlay so it sits on top of everything (incl. the iframe);
   pointer-events: none so it never intercepts clicks. The inset glow reaches at
   most ~20px in from the border (max blur + spread = 16 + 4). Toggled via the
   `is-working` class on <body> from script.js. */
.working-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2147483647;     /* above all app content */
    opacity: 0;
    transition: opacity 0.6s ease;
}

body.is-working .working-overlay {
    opacity: 1;
    animation: working-glow 2.6s ease-in-out infinite;
}

@keyframes working-glow {
    0%, 100% {
        box-shadow:
            inset 0 0 12px 2px rgba(255, 140, 0, 0.35),
            inset 0 0 18px 2px rgba(255, 140, 0, 0.20);
    }
    50% {
        box-shadow:
            inset 0 0 14px 4px rgba(255, 140, 0, 0.60),
            inset 0 0 16px 4px rgba(255, 140, 0, 0.35);
    }
}

/* ---- Phase 2: poll closed / winner highlight (applied via JS classes) ---- */

/* "Poll closed" cue, shown only when the results list is marked closed. */
.results-list.is-closed::before {
    content: "🔒 Poll closed — final results";
    display: block;
    margin-bottom: 0.5rem;
    padding: 0.4rem 0.9rem;
    border-radius: 100px;
    background: rgba(124, 58, 237, 0.16);
    border: 1px solid rgba(124, 58, 237, 0.4);
    color: #a78bfa;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-align: center;
}

/* Reinforce the status badge while results are closed. */
.status-badge.is-closed {
    background: rgba(124, 58, 237, 0.16);
    border-color: rgba(124, 58, 237, 0.5);
    box-shadow: 0 0 14px rgba(124, 58, 237, 0.35);
}

/* Dim the losing options so the winner stands out. */
.results-list.is-closed .result-item {
    opacity: 0.4;
    transition: opacity 0.4s ease;
}

/* Highlight the winning option. */
.results-list.is-closed .result-item.winner {
    opacity: 1;
    padding: 1rem 1.1rem;
    margin: 0 -1.1rem;
    background: rgba(124, 58, 237, 0.12);
    border: 1px solid rgba(124, 58, 237, 0.45);
    border-radius: 16px;
    box-shadow: 0 0 22px rgba(124, 58, 237, 0.3);
}
.results-list.is-closed .result-item.winner .result-label {
    color: var(--text-primary);
    font-weight: 700;
}
.results-list.is-closed .result-item.winner .result-label::after {
    content: "🏆 WINNER";
    margin-left: 0.6rem;
    padding: 0.1rem 0.5rem;
    border-radius: 100px;
    background: var(--accent-color);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    vertical-align: middle;
}
.results-list.is-closed .result-item.winner .result-percent {
    font-size: 1.15rem;
}
.results-list.is-closed .result-item.winner .progress-bar-fill {
    filter: brightness(1.25);
}
