:root {
    --bg: #09061c;
    --panel: #120d30;
    --panel-2: #1a1342;
    --surface: rgba(255, 255, 255, .075);
    --surface-strong: rgba(255, 255, 255, .12);
    --text: #f8f7ff;
    --muted: #b7b2d1;
    --primary: #f6c945;
    --primary-2: #ff8f3f;
    --danger: #ff5b76;
    --success: #59dca4;
    --border: rgba(255, 255, 255, .13);
    --shadow: 0 24px 60px rgba(0, 0, 0, .33);
    --radius: 22px;
    --team-1: #47c8ff;
    --team-2: #ff6687;
    --team-3: #6de2a5;
    --team-4: #b996ff;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    color-scheme: dark;
}

body {
    margin: 0;
    min-width: 320px;
    color: var(--text);
    background:
        radial-gradient(circle at 15% 0%, rgba(84, 63, 204, .34), transparent 34rem),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(1.5rem, 3vw, 2.45rem);
    line-height: 1.05;
}

h2 {
    margin-bottom: .55rem;
}

.eyebrow {
    margin-bottom: .38rem;
    color: var(--primary);
    font-size: .75rem;
    font-weight: 850;
    letter-spacing: .13em;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    border: 1px solid transparent;
    border-radius: 13px;
    padding: .68rem 1rem;
    color: var(--text);
    background: var(--surface);
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s ease, background .15s ease, opacity .15s ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button:disabled {
    cursor: not-allowed;
    opacity: .42;
}

.button-primary {
    color: #211703;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 12px 30px rgba(255, 168, 58, .18);
}

.button-ghost {
    border-color: var(--border);
    background: var(--surface);
}

.button-danger-outline {
    border-color: rgba(255, 91, 118, .55);
    color: #ffb2c0;
    background: rgba(255, 91, 118, .08);
}

.button-zero {
    width: 100%;
    border-color: rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .09);
}

.button-large {
    min-height: 52px;
    padding: .85rem 1.35rem;
    font-size: 1rem;
}

.button-small {
    min-height: 36px;
    padding: .45rem .75rem;
    font-size: .82rem;
}

.game-layout {
    display: grid;
    min-height: 100vh;
    grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr);
}

.control-panel {
    min-width: 0;
    padding: clamp(1rem, 2.4vw, 2.25rem);
}

.player-panel {
    position: sticky;
    top: 0;
    display: grid;
    height: 100vh;
    min-width: 0;
    min-height: 0;
    grid-template-rows: auto 1fr;
    border-left: 1px solid var(--border);
    background: #05040e;
    overflow: hidden;
}

.player-toolbar,
.topbar,
.section-heading,
.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar {
    margin-bottom: 1.2rem;
}

.topbar-actions,
.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
}

.player-toolbar {
    min-height: 64px;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #100d20;
}

.live-dot {
    display: inline-block;
    width: .7rem;
    height: .7rem;
    margin-right: .4rem;
    border-radius: 999px;
    background: #ff4b69;
    box-shadow: 0 0 0 .28rem rgba(255, 75, 105, .13);
}

#theme-frame {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    border: 0;
    background: #fff;
}

.iframe-placeholder {
    display: grid;
    place-content: center;
    padding: 2rem;
    color: var(--muted);
    text-align: center;
}

.iframe-placeholder[hidden] {
    display: none !important;
}

.iframe-placeholder h2 {
    color: var(--text);
}

.music-note {
    margin-bottom: 1rem;
    color: var(--primary);
    font-size: 5rem;
    line-height: 1;
}

.theme-stage {
    position: relative;
    overflow: hidden;
    min-height: 160px;
    margin-bottom: 1rem;
    border: 1px solid rgba(246, 201, 69, .28);
    border-radius: var(--radius);
    padding: clamp(1.2rem, 3vw, 2rem);
    background:
        linear-gradient(110deg, rgba(246, 201, 69, .16), rgba(255, 143, 63, .07)),
        var(--panel);
    box-shadow: var(--shadow);
}

.theme-stage::after {
    content: "♪";
    position: absolute;
    right: 3%;
    bottom: -45%;
    color: rgba(255, 255, 255, .045);
    font-size: 13rem;
    font-weight: 900;
    transform: rotate(-10deg);
}

.theme-stage-toolbar {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.round-label {
    position: relative;
    z-index: 1;
    color: var(--primary);
    font-size: .8rem;
    font-weight: 900;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.theme-stage h2 {
    position: relative;
    z-index: 1;
    margin: .45rem 0;
    max-width: 90%;
    font-size: clamp(2rem, 5.1vw, 4.8rem);
    line-height: .98;
    text-wrap: balance;
}

.theme-stage p {
    position: relative;
    z-index: 1;
    margin-bottom: 0;
    color: var(--muted);
}

.play-grid {
    display: grid;
    margin-bottom: 1rem;
    gap: 1rem;
    grid-template-columns: minmax(280px, .9fr) minmax(300px, 1.1fr);
}

.play-grid.single-panel > :not([hidden]) {
    grid-column: 1 / -1;
}

.wheel-column,
.scoring-column,
.score-section,
.history-section,
.round-result {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1rem, 2vw, 1.35rem);
    background: var(--panel);
}

.wheel-column {
    display: grid;
    place-items: center;
    gap: 1.2rem;
}

.wheel-wrap {
    position: relative;
    width: min(100%, 320px);
    aspect-ratio: 1;
    filter: drop-shadow(0 22px 28px rgba(0, 0, 0, .32));
}

.wheel {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border: 9px solid #f6d875;
    border-radius: 50%;
    background: repeating-conic-gradient(
        from -8deg,
        #ff5b76 0deg 18deg,
        #785fee 18deg 36deg,
        #38c9ae 36deg 54deg,
        #ffad3f 54deg 72deg
    );
    box-shadow: inset 0 0 0 4px rgba(39, 23, 73, .55);
    transition: transform 3.5s cubic-bezier(.12, .63, .05, 1);
}

.wheel::before {
    content: "";
    position: absolute;
    inset: 11%;
    border: 2px solid rgba(255, 255, 255, .4);
    border-radius: 50%;
}

.wheel-center {
    position: relative;
    z-index: 2;
    display: grid;
    width: 42%;
    aspect-ratio: 1;
    place-content: center;
    border: 6px solid #f7db75;
    border-radius: 50%;
    color: #241833;
    background: #fff5c7;
    text-align: center;
    transform: rotate(var(--counter-rotation, 0deg));
}

.wheel-center span {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 950;
    line-height: 1;
}

.wheel-center small {
    max-width: 6rem;
    font-size: .68rem;
    font-weight: 850;
    line-height: 1.05;
}

.wheel-pointer {
    position: absolute;
    z-index: 4;
    top: -6px;
    left: 50%;
    width: 0;
    height: 0;
    border-right: 20px solid transparent;
    border-left: 20px solid transparent;
    border-top: 46px solid #fff4bd;
    filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .45));
    transform: translateX(-50%);
}

.scoring-column {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .9rem;
}

.card-now {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    border-radius: 18px;
    padding: 1rem 1.15rem;
    color: #211703;
    background: linear-gradient(135deg, #fff4b1, #ffb549);
}

.card-now > span {
    font-weight: 900;
    text-transform: uppercase;
}

.card-now strong {
    grid-row: span 2;
    font-size: 4rem;
    line-height: .8;
}

.card-now small {
    color: #65490e;
    font-weight: 750;
}

.team-award-grid {
    display: grid;
    gap: .7rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.team-award {
    display: grid;
    min-height: 92px;
    grid-template-columns: 1fr auto;
    align-items: center;
    border: 1px solid color-mix(in srgb, var(--team-color) 58%, transparent);
    border-radius: 17px;
    padding: .85rem;
    color: var(--text);
    background: color-mix(in srgb, var(--team-color) 13%, var(--panel-2));
    text-align: left;
    cursor: pointer;
}

.team-award:disabled {
    cursor: not-allowed;
    opacity: .4;
}

.team-award span {
    overflow: hidden;
    font-weight: 900;
    text-overflow: ellipsis;
}

.team-award strong {
    color: var(--team-color);
    font-size: 2rem;
}

.team-award small {
    grid-column: 1 / -1;
    color: var(--muted);
}

.team-color-1 { --team-color: var(--team-1); }
.team-color-2 { --team-color: var(--team-2); }
.team-color-3 { --team-color: var(--team-3); }
.team-color-4 { --team-color: var(--team-4); }

.score-section,
.history-section {
    margin-bottom: 1rem;
}

.section-heading {
    margin-bottom: 1rem;
}

.section-heading.compact {
    align-items: flex-end;
}

.section-heading h2 {
    margin-bottom: 0;
}

.section-heading > p,
.helper {
    margin-bottom: 0;
    color: var(--muted);
}

.scoreboard {
    display: grid;
    gap: .75rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.team-score {
    min-width: 0;
    border: 1px solid color-mix(in srgb, var(--team-color) 40%, transparent);
    border-radius: 18px;
    padding: 1rem;
    background: color-mix(in srgb, var(--team-color) 9%, var(--panel-2));
}

.team-score.round-winner {
    box-shadow: inset 0 0 0 2px var(--primary);
}

.team-score-head {
    display: flex;
    min-height: 2.2rem;
    align-items: start;
    justify-content: space-between;
    gap: .5rem;
}

.team-score h3 {
    overflow: hidden;
    margin-bottom: .5rem;
    color: var(--team-color);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.winner-badge {
    border-radius: 999px;
    padding: .25rem .5rem;
    color: #2a1d00;
    background: var(--primary);
    font-size: .65rem;
    font-weight: 900;
    white-space: nowrap;
}

.score-numbers {
    display: grid;
    gap: .65rem;
    grid-template-columns: 1fr 1fr;
}

.score-numbers > div {
    display: flex;
    flex-direction: column;
    border-radius: 13px;
    padding: .65rem;
    background: rgba(0, 0, 0, .18);
}

.score-numbers strong {
    font-size: 2rem;
    line-height: 1;
}

.score-numbers span {
    margin-top: .3rem;
    color: var(--muted);
    font-size: .7rem;
}

.won-cards {
    display: flex;
    min-height: 2rem;
    align-items: center;
    flex-wrap: wrap;
    gap: .35rem;
    margin-top: .7rem;
}

.won-cards > span {
    display: grid;
    width: 1.8rem;
    height: 1.8rem;
    place-items: center;
    border-radius: 50%;
    color: #161022;
    background: var(--team-color);
    font-size: .75rem;
    font-weight: 950;
}

.won-cards small {
    color: var(--muted);
}

.history-section .helper {
    margin: -.45rem 0 .85rem;
    font-size: .82rem;
}

.round-history {
    display: grid;
    gap: .55rem;
    grid-template-columns: repeat(7, minmax(82px, 1fr));
}

.history-card {
    display: grid;
    min-width: 0;
    min-height: 100px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: .5rem;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}

.history-card strong {
    display: grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border-radius: 50%;
    color: #211703;
    background: var(--primary);
}

.history-card span {
    overflow: hidden;
    max-width: 100%;
    font-size: .75rem;
    font-weight: 800;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-card small {
    color: var(--muted);
    font-size: .62rem;
}

.history-card.pending {
    opacity: .46;
    cursor: default;
}

.history-card.nobody strong {
    color: var(--text);
    background: #67627a;
}

.round-result {
    margin-bottom: 1rem;
    border-color: rgba(89, 220, 164, .45);
    background: linear-gradient(135deg, rgba(89, 220, 164, .14), var(--panel));
    text-align: center;
}

.round-result h2 {
    font-size: clamp(1.6rem, 3.3vw, 2.7rem);
}

.notice {
    position: sticky;
    z-index: 20;
    top: .75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: .9rem 1rem;
    background: #25203b;
    box-shadow: var(--shadow);
    font-weight: 750;
}

.notice-success {
    border-color: rgba(89, 220, 164, .55);
    color: #b9f7dc;
}

.notice-error {
    border-color: rgba(255, 91, 118, .55);
    color: #ffc0ca;
}

.winner-overlay {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1.2rem;
    background: rgba(5, 3, 16, .9);
    backdrop-filter: blur(12px);
}

.winner-overlay[hidden] {
    display: none;
}

.winner-card {
    position: relative;
    z-index: 2;
    width: min(680px, 100%);
    border: 2px solid var(--primary);
    border-radius: 30px;
    padding: clamp(2rem, 7vw, 5rem);
    background:
        radial-gradient(circle at 50% 0%, rgba(246, 201, 69, .25), transparent 55%),
        var(--panel);
    box-shadow: 0 0 100px rgba(246, 201, 69, .25);
    text-align: center;
}

.winner-card p {
    margin-bottom: .25rem;
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 950;
    letter-spacing: .15em;
    text-transform: uppercase;
}

.winner-card h2 {
    margin-bottom: .65rem;
    font-size: clamp(3rem, 11vw, 7rem);
    line-height: .95;
    text-wrap: balance;
}

.winner-card span {
    display: block;
    margin-bottom: 2rem;
    color: var(--muted);
    font-size: 1.1rem;
}

.correction-dialog {
    width: min(520px, calc(100% - 2rem));
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 1.4rem;
    color: var(--text);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.correction-dialog::backdrop {
    background: rgba(3, 2, 10, .76);
    backdrop-filter: blur(5px);
}

.dialog-close {
    position: absolute;
    top: .7rem;
    right: .7rem;
    width: 2.3rem;
    height: 2.3rem;
    border: 0;
    border-radius: 50%;
    color: var(--text);
    background: var(--surface);
    font-size: 1.5rem;
    cursor: pointer;
}

.correction-options {
    display: grid;
    gap: .7rem;
    grid-template-columns: 1fr 1fr;
}

.correction-team {
    border-color: color-mix(in srgb, var(--team-color) 58%, transparent);
    background: color-mix(in srgb, var(--team-color) 16%, var(--panel-2));
}

/* Écran public en lecture seule */
.public-display-page {
    min-height: 100vh;
}

.public-display {
    width: min(1500px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: clamp(1rem, 2.4vw, 2rem);
}

.public-topbar {
    display: flex;
    min-height: 72px;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.sync-badge {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .55rem .9rem;
    color: #c8f9e4;
    background: rgba(89, 220, 164, .09);
    font-size: .82rem;
}

.sync-badge .live-dot {
    background: var(--success);
    box-shadow: 0 0 0 .28rem rgba(89, 220, 164, .13);
}

.sync-badge-offline {
    color: #ffd0d8;
    background: rgba(255, 91, 118, .09);
}

.sync-badge-offline .live-dot {
    background: var(--danger);
    box-shadow: 0 0 0 .28rem rgba(255, 91, 118, .13);
}

.public-display-page .theme-stage {
    min-height: 150px;
}

.public-display-page .theme-stage h2 {
    max-width: 100%;
    font-size: clamp(2.4rem, 5vw, 5rem);
}

.public-card-panel {
    min-height: 150px;
    margin-bottom: 1rem;
}

.public-card-panel .card-now {
    width: 100%;
}

.public-card-panel .card-now strong {
    font-size: clamp(4rem, 8vw, 6rem);
}

.public-display-page .history-card {
    min-height: 88px;
    cursor: default;
}

.public-display-page .winner-card span {
    margin-bottom: 0;
}

/* Backend */
.admin-page {
    min-height: 100vh;
}

.admin-topbar {
    padding: 1.25rem clamp(1rem, 4vw, 3rem);
    border-bottom: 1px solid var(--border);
    background: rgba(9, 6, 28, .86);
    backdrop-filter: blur(15px);
}

.admin-container {
    width: min(1180px, calc(100% - 2rem));
    margin: 2rem auto 4rem;
}

.admin-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-card,
.admin-savebar {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1rem, 2.5vw, 1.6rem);
    background: var(--panel);
}

.admin-card-wide,
.admin-savebar {
    grid-column: 1 / -1;
}

.auth-card {
    width: min(520px, 100%);
    margin: 5vh auto 0;
}

.form-stack {
    display: grid;
    gap: 1rem;
}

label {
    display: grid;
    gap: .42rem;
    color: #e4e1ef;
    font-size: .9rem;
    font-weight: 800;
}

label small {
    color: var(--muted);
    font-size: .75rem;
    font-weight: 500;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;
    padding: .75rem .85rem;
    color: var(--text);
    background: rgba(0, 0, 0, .2);
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(246, 201, 69, .1);
}

textarea {
    min-height: 250px;
    resize: vertical;
    line-height: 1.48;
}

.theme-counter {
    border-radius: 999px;
    padding: .45rem .75rem;
    background: var(--surface);
}

.url-preview {
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.url-preview summary {
    color: var(--primary);
    font-weight: 800;
    cursor: pointer;
}

.table-scroll {
    overflow-x: auto;
    margin-top: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: .65rem;
    text-align: left;
}

th {
    color: var(--primary);
}

code {
    color: #b7ebff;
}

.admin-savebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-color: rgba(246, 201, 69, .35);
    background: linear-gradient(135deg, rgba(246, 201, 69, .09), var(--panel));
}

.admin-savebar p {
    margin-bottom: 0;
    color: var(--muted);
}

.secondary-settings {
    margin-top: 1rem;
}

.logout-form {
    margin-top: 2rem;
}

.text-button {
    border: 0;
    padding: 0;
    color: #ff9bac;
    background: transparent;
    text-decoration: underline;
    cursor: pointer;
}

@media (max-width: 1120px) {
    .play-grid {
        grid-template-columns: 1fr;
    }

    .wheel-wrap {
        max-width: 270px;
    }

    .round-history {
        overflow-x: auto;
        grid-template-columns: repeat(7, minmax(92px, 1fr));
        padding-bottom: .35rem;
    }
}

@media (max-width: 820px) {
    .game-layout {
        display: block;
    }

    .player-panel {
        position: relative;
        height: 58vh;
        min-height: 430px;
        border-top: 1px solid var(--border);
        border-left: 0;
    }

    .topbar,
    .section-heading.compact,
    .admin-savebar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions .button {
        flex: 1;
    }

    .admin-grid {
        grid-template-columns: 1fr;
    }

    .admin-card-wide,
    .admin-savebar {
        grid-column: auto;
    }

    .public-topbar {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 560px) {
    .control-panel {
        padding: .75rem;
    }

    .theme-stage {
        min-height: 140px;
    }

    .theme-stage h2 {
        max-width: 100%;
    }

    .theme-stage-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .team-award-grid,
    .scoreboard,
    .correction-options {
        grid-template-columns: 1fr;
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .inline-actions {
        width: 100%;
    }

    .inline-actions .button {
        flex: 1 1 160px;
    }

    .admin-topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .public-display {
        padding: .75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
