:root {
    font-family: Inter, system-ui, sans-serif;
    color: #eee;
    background: #090707;
    --red: #b81818;
    --panel: #171111e8;
    --line: #5d2929;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 50% 10%, #2b1717, #080606 55%);
    color: #eee;
}

header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5vw;
    background: #090707ee;
    border-bottom: 1px solid #421b1b;
    position: sticky;
    top: 0;
    z-index: 20;
}

header b {
    letter-spacing: .16em;
    color: #e6d8c4;
}

nav {
    display: flex;
    gap: 20px;
}

a {
    color: #ddd;
    text-decoration: none;
}

main {
    max-width: 1180px;
    margin: auto;
    padding: 36px 24px;
}

.hero {
    text-align: center;
    padding: 45px 0 30px;
}

.hero h1 {
    font-size: 48px;
    margin: 0;
    color: #f2e6d4;
}

.grid {
    display: grid;
    gap: 20px;
}

.g2 {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 22px;
    box-shadow: 0 18px 50px #0007;
}

.panel h2,
.panel h3 {
    margin-top: 0;
}

label {
    display: block;
    margin: 12px 0 5px;
    color: #cdbcbc;
}

input,
select,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    padding: 11px;
    border-radius: 9px;
    border: 1px solid #563333;
    background: #0e0a0a;
    color: #fff;
}

/* BUTTONS */

button {
    width: auto;
    min-width: 0;
    border: 1px solid #713333;
    background: #311414;
    color: #fff;
    padding: 8px 13px;
    border-radius: 9px;
    cursor: pointer;
}

button.primary {
    background: #8f1717;
}

button.danger {
    background: #651010;
}

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

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

.action-row {
    gap: 12px;
    margin-top: 16px;
    margin-bottom: 16px;
}

.muted {
    color: #a99696;
}

.ok {
    color: #75d596;
}

.bad {
    color: #ff8585;
}

.settings {
    margin-bottom: 18px;
}

.playerbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.pill {
    background: #251818;
    border: 1px solid #563333;
    padding: 7px 10px;
    border-radius: 999px;
}

.story {
    border-color: #548f73;
    box-shadow: 0 0 10px rgba(79, 139, 108, .32);
}

.cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.cardpick {
    background: #0b0808;
    padding: 10px;
    border: 1px solid #573333;
    border-radius: 12px;
}

.cardpick img,
.active-card img {
    width: 100%;
    max-height: 430px;
    object-fit: contain;
}

.active-card {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table td,
.admin-table th {
    padding: 8px;
    border-bottom: 1px solid #3a2525;
    text-align: left;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    background: #211;
    padding: 14px;
    border: 1px solid #833;
    border-radius: 10px;
    z-index: 99;
}

.preview-wrap {
    width: min(520px, 100%);
    aspect-ratio: 16 / 9;
    margin-top: 14px;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid #563333;
    background: #050303;
}

.preview-wrap video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

body.game-page header,
body.join-page header,
body.overlay header {
    display: none;
}

body.game-page main,
body.join-page main {
    padding-top: 36px;
}

body.overlay main {
    max-width: none;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
}

body.overlay {
    overflow: hidden;
    background: #000;
}

.stage {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: #000;
}

.bgvid {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* =========================================================
   KAMERAS
   ========================================================= */

body.overlay .cam {
    position: absolute;
    width: 29%;
    height: auto;
    aspect-ratio: 16 / 9;
    z-index: 4;
}

body.overlay .cam video,
body.overlay .cam .fallback {
    position: absolute;
    left: 8.5%;
    top: 12.5%;
    width: 83%;
    height: 69.5%;
    object-fit: cover;
    background: #050505;
    z-index: 1;
}

body.overlay .cam .fallback {
    object-fit: cover;
}

body.overlay .cam .frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    z-index: 3;
    pointer-events: none;
}

/* =========================================================
   NAME IN DER BANDEROLE
   ========================================================= */

body.overlay .cam .name {
    position: absolute;
    left: 18%;
    right: 18%;
    bottom: 9%;
    height: 8%;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;
    margin: 0;

    z-index: 4;

    font-family: Georgia, serif;
    font-size: clamp(14px, 1.25vw, 24px);
    font-weight: 700;
    line-height: 1;

    text-align: center;
    color: #eee;

    text-shadow:
        0 2px 4px #000,
        0 0 3px #000;

    white-space: nowrap;
    overflow: visible;
}

/* =========================================================
   KAMERAPOSITIONEN – ROLLENBASIERT
   ========================================================= */

/*
 * STORYTELLER
 * Immer links oben und unverändert groß.
 */
body.overlay .storyteller-position {
    left: 1.5%;
    top: 2%;
    width: 29%;
}


/*
 * RATENDE
 * Die Größe richtet sich nach der Anzahl der Ratenden.
 */
body.overlay .guesser-position {
    right: 1.5%;
}


/* 1 RATENDER: groß wie der Storyteller, mittig rechts */
body.overlay .guesser-1-1 {
    width: 29%;
    top: 50%;
    transform: translateY(-50%);
}


/* 2 RATENDE: beide so groß wie die Storyteller-Cam */
body.overlay .guesser-2-1,
body.overlay .guesser-2-2 {
    width: 29%;
}

body.overlay .guesser-2-1 {
    top: 2%;
}

body.overlay .guesser-2-2 {
    bottom: 2%;
}


/* 3 RATENDE: etwas kleiner, damit alle sauber untereinander passen */
body.overlay .guesser-3-1,
body.overlay .guesser-3-2,
body.overlay .guesser-3-3 {
    width: 26%;
}

body.overlay .guesser-3-1 {
    top: 1%;
}

body.overlay .guesser-3-2 {
    top: 50%;
    transform: translateY(-50%);
}

body.overlay .guesser-3-3 {
    bottom: 1%;
}


/*
 * Namen der kleineren 3er-Variante etwas kompakter.
 */
body.overlay .guesser-3-1 .name,
body.overlay .guesser-3-2 .name,
body.overlay .guesser-3-3 .name {
    font-size: clamp(12px, 1.08vw, 21px);
}


/* =========================================================
   STORYTELLER GLOW
   ========================================================= */

body.overlay .cam.storycam {
    animation: storytellerGreenGlow 3.6s ease-in-out infinite;
}

@keyframes storytellerGreenGlow {
    0%,
    100% {
        filter:
            drop-shadow(0 0 3px rgba(73, 130, 103, .30))
            drop-shadow(0 0 8px rgba(38, 86, 69, .18));
    }

    50% {
        filter:
            drop-shadow(0 0 6px rgba(102, 163, 132, .50))
            drop-shadow(0 0 14px rgba(49, 108, 86, .28));
    }
}

/* =========================================================
   KARTE
   ========================================================= */

.obs-card {
    position: absolute;
    z-index: 5;
    left: 50%;
    top: 5%;
    transform: translateX(-50%);
    width: 23%;
    height: 56%;
    perspective: 1200px;
}

.obs-card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 10px 16px #000b);
}

.obs-card.flip {
    animation: flip .9s ease;
}

@keyframes flip {
    0% {
        transform: translateX(-50%) rotateY(0);
    }

    50% {
        transform: translateX(-50%) rotateY(90deg);
    }

    100% {
        transform: translateX(-50%) rotateY(0);
    }
}

/* =========================================================
   TWITCH CHAT
   ========================================================= */

/*
 * Der Chat sitzt IMMER direkt unter dem Storyteller.
 * Er hat dieselbe Gesamtbreite wie dessen Kamerarahmen
 * und reicht bis fast an den unteren Bildschirmrand.
 */
.chatbox {
    position: absolute;
    z-index: 6;

    left: 3%;
    top: 36%;
    bottom: 6%;
    width: 26%;

    display: flex;
    flex-direction: column;
    justify-content: flex-end;

    background: #080707b8;
    border: 1px solid #6d3636;
    border-radius: 14px;
    padding: 12px 15px;
    overflow: hidden;

    box-shadow:
        0 10px 30px rgba(0, 0, 0, .45),
        inset 0 0 20px rgba(100, 25, 25, .05);
}

.chatmsg {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 8px;
    margin: 6px 0;
    font-size: clamp(13px, 1.05vw, 20px);
    line-height: 1.25;
}

.chatmsg img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.chattext {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}


/* =========================================================
   ALLE FÄLLE GELÖST
   ========================================================= */

/*
 * Der Banner sitzt in der freien Mitte.
 *
 * Wichtig:
 * Er endet deutlich oberhalb des Chats.
 * Dadurch überlagert er weder die Nachrichten
 * noch die unteren Kamerarahmen.
 */

.finish {
    position: absolute;
    z-index: 8;

    left: 50%;
    top: 50%;

    transform: translate(-50%, -50%);

    width: 31%;
    min-width: 400px;
    max-width: 600px;

    height: auto;
    min-height: 88px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 15px 34px 18px;

    background:
        linear-gradient(
            180deg,
            rgba(24, 18, 17, .96) 0%,
            rgba(8, 8, 8, .97) 55%,
            rgba(17, 10, 10, .97) 100%
        );

    border:
        1px solid rgba(143, 70, 59, .82);

    border-radius: 8px;

    box-shadow:
        0 14px 34px rgba(0, 0, 0, .72),
        0 0 18px rgba(130, 20, 20, .16),
        inset 0 1px 0 rgba(255, 220, 190, .09),
        inset 0 0 25px rgba(90, 15, 15, .12);

    text-align: center;

    pointer-events: none;

    animation:
        finishAppear .7s ease both;
}

/*
 * Äußerer feiner Rahmen
 */

.finish::before {
    content: '';

    position: absolute;

    inset: 5px;

    border:
        1px solid rgba(109, 47, 42, .46);

    border-radius: 5px;

    pointer-events: none;
}

/*
 * Kleine dekorative Spitze unten
 */

.finish::after {
    content: '';

    position: absolute;

    left: 50%;
    bottom: -7px;

    width: 13px;
    height: 13px;

    transform:
        translateX(-50%)
        rotate(45deg);

    background:
        #100b0b;

    border-right:
        1px solid rgba(143, 70, 59, .72);

    border-bottom:
        1px solid rgba(143, 70, 59, .72);

    box-shadow:
        4px 4px 8px rgba(0, 0, 0, .28);
}

/*
 * Diamant / Ornament über dem Banner
 */

.finish-ornament {
    position: absolute;

    top: -15px;
    left: 50%;

    transform:
        translateX(-50%);

    width: 31px;
    height: 31px;

    display: flex;
    align-items: center;
    justify-content: center;

    background:
        #100b0b;

    border:
        1px solid rgba(151, 65, 57, .75);

    transform-origin: center;

    color:
        #9c302a;

    font-size:
        11px;

    text-shadow:
        0 0 8px rgba(185, 31, 31, .5);

    clip-path:
        polygon(
            50% 0%,
            100% 50%,
            50% 100%,
            0% 50%
        );
}

/*
 * Textbereich
 */

.finish-content {
    position: relative;
    z-index: 2;

    display: flex;
    align-items: baseline;
    justify-content: center;

    flex-wrap: wrap;

    column-gap: 8px;
    row-gap: 1px;

    font-family:
        Georgia,
        'Times New Roman',
        serif;

    line-height: 1.05;
}

/*
 * Heller Haupttext
 */

.finish-main {
    color:
        #eee4d5;

    font-size:
        clamp(19px, 1.45vw, 29px);

    font-weight:
        700;

    letter-spacing:
        .02em;

    text-shadow:
        0 2px 3px #000,
        0 0 8px rgba(255, 230, 205, .08);
}

/*
 * Roter Akzent
 */

.finish-red {
    color:
        #c8322d;

    font-size:
        clamp(21px, 1.65vw, 32px);

    font-weight:
        700;

    font-style:
        italic;

    letter-spacing:
        .02em;

    text-shadow:
        0 2px 3px #000,
        0 0 9px rgba(190, 28, 28, .32);
}

/*
 * Dünne rote Linie am unteren Rand
 */

.finish-line {
    position: absolute;

    left: 17%;
    right: 17%;
    bottom: 9px;

    height: 1px;

    background:
        linear-gradient(
            90deg,
            transparent,
            rgba(153, 38, 33, .5),
            rgba(200, 53, 46, .85),
            rgba(153, 38, 33, .5),
            transparent
        );
}

/*
 * Sanftes Einblenden
 */

@keyframes finishAppear {
    from {
        opacity: 0;

        transform:
            translate(-50%, calc(-50% + 14px))
            scale(.96);

        filter:
            blur(2px);
    }

    to {
        opacity: 1;

        transform:
            translate(-50%, -50%)
            scale(1);

        filter:
            blur(0);
    }
}

/* =========================================================
   KARTEN-ZOOM
   ========================================================= */

.zoomable {
    cursor: zoom-in;

    transition:
        transform .18s ease,
        filter .18s ease;
}

.zoomable:hover {
    transform: scale(1.015);
    filter: brightness(1.06);
}

.zoom-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 4vh 4vw;

    background:
        rgba(0, 0, 0, .90);

    backdrop-filter:
        blur(5px);

    cursor: zoom-out;
}

.zoom-modal[hidden] {
    display: none;
}

.zoom-modal img {
    display: block;

    max-width: 92vw;
    max-height: 92vh;

    width: auto;
    height: auto;

    object-fit: contain;

    border-radius: 10px;

    box-shadow:
        0 20px 80px #000;

    cursor: default;
}

.zoom-close {
    position: fixed;

    top: 20px;
    right: 24px;

    z-index: 10001;

    width: 48px;
    height: 48px;

    padding: 0;

    border-radius: 50%;

    font-size: 32px;
    line-height: 1;

    background:
        rgba(40, 10, 10, .9);
}

body.zoom-open {
    overflow: hidden;
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 650px) {

    header nav {
        display: none;
    }

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

    .hero h1 {
        font-size: 34px;
    }

    .finish {
        width: 70%;
        min-width: 0;
    }
}
