/* EINS Base Styling */
body {
    overflow-x: hidden;
}

/* The site paints its standard backdrop on body::before (z-index:-9999), so we
   override that pseudo-element rather than `body` itself. UNO-themed felt with
   soft red / blue / green / yellow colour pools in the corners. */
body::before {
    background-image:
        radial-gradient(circle at 12% 16%, rgba(255, 85, 85, 0.22), transparent 40%),
        radial-gradient(circle at 88% 14%, rgba(85, 110, 255, 0.22), transparent 40%),
        radial-gradient(circle at 14% 88%, rgba(85, 175, 85, 0.20), transparent 40%),
        radial-gradient(circle at 88% 86%, rgba(255, 175, 0, 0.20), transparent 42%),
        radial-gradient(circle at 50% 45%, #1c1c33 0%, #111125 55%, #0a0a14 100%) !important;
    background-color: #0a0a14 !important;
}

/* The brand oval inside the menu is the title now — hide the generic page heading
   so "EINS" doesn't appear twice. */
#page-title {
    display: none !important;
}

/* Drop the standard starfield effect on this page for a cleaner UNO look. */
#star-canvas {
    display: none !important;
}

#game-section {
    position: relative;
    width: 100vw;
    height: 100vh;
    left: 0;
    top: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #1a1a2e 0%, #0d0d1a 100%);
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1001;
    pointer-events: none;
    display: none;
}

#game-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to Three.js canvas */
}

/* Make UI elements clickable */
#game-ui>*,
#game-ui .btn {
    pointer-events: auto;
}

.mode-dialog,
.online-dialog {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    max-width: 550px;
    width: 90%;
    margin: 5vh auto;
    position: relative;
    z-index: 100;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    color: white;
}

.invite-flex {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.status-display {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    padding: 10px 20px;
    border-radius: 20px;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transition: all 0.3s ease;
}

.status-display.turn-cue-flash {
    animation: turn-cue 0.45s ease-out;
}

.pass-btn {
    position: absolute;
    bottom: 90px;
    right: 20px;
    font-size: 1.1rem;
    padding: 10px 20px;
    border-radius: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.exit-game-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes pulse-red {
    0% {
        transform: scale(1);
        box-shadow: 0 0 15px rgba(220, 53, 69, 0.8);
    }

    100% {
        transform: scale(1.1);
        box-shadow: 0 0 30px rgba(220, 53, 69, 1);
    }
}

/* Like pulse-red but keeps the translateX(-50%) centering of the EINS button */
@keyframes pulse-eins {
    0% {
        transform: translateX(-50%) scale(1);
        box-shadow: 0 0 20px rgba(220, 53, 69, 0.8);
    }

    100% {
        transform: translateX(-50%) scale(1.08);
        box-shadow: 0 0 34px rgba(220, 53, 69, 1);
    }
}

@keyframes turn-cue {
    0% {
        transform: translateX(-50%) scale(0.96);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    }

    45% {
        transform: translateX(-50%) scale(1.08);
        box-shadow: 0 0 28px rgba(102, 230, 255, 0.72), 0 4px 18px rgba(0, 0, 0, 0.35);
    }

    100% {
        transform: translateX(-50%) scale(1);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    }
}

.color-btn {
    transition: transform 0.2s ease;
}

.color-btn:hover {
    transform: scale(1.1);
}

.solo-btn {
    transition: transform 0.15s ease, background-color 0.15s ease;
    font-weight: 600;
}

.solo-btn:hover {
    transform: translateY(-2px);
}

#uno-button:hover {
    transform: translateX(-50%) scale(1.05);
}

/* ============================================================
   EINS MENU — UNO card-themed redesign
   ============================================================ */
.eins-menu {
    /* Center the main menu in both axes regardless of page-title/navbar flow. */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    max-width: 440px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 1.6rem 1.6rem 1.2rem;
    border: 2px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* Brand wordmark in the signature red oval (mirrors the card back art) */
.eins-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 1.3rem;
}

.eins-brand-oval {
    display: inline-block;
    padding: 0.4rem 2.4rem;
    border-radius: 50% / 60%;
    background: linear-gradient(160deg, #ff7a7a 0%, #ff5555 45%, #d83a3a 100%);
    border: 4px solid #fff;
    color: #fff;
    font-family: "Arial Black", system-ui, sans-serif;
    font-weight: 900;
    font-style: italic;
    font-size: 2.1rem;
    letter-spacing: 2px;
    transform: rotate(-8deg);
    text-shadow: 0 3px 6px rgba(0, 0, 0, 0.45);
    box-shadow: 0 8px 22px rgba(216, 58, 58, 0.45);
}

/* Segmented Solo / Online tabs */
.eins-tabs {
    display: flex;
    gap: 6px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 5px;
    margin-bottom: 1.2rem;
}

.eins-tab {
    flex: 1;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.65);
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.6rem 0.4rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.eins-tab:hover {
    color: #fff;
}

.eins-tab.active {
    background: linear-gradient(160deg, #ff6b6b, #d83a3a);
    color: #fff;
    box-shadow: 0 4px 12px rgba(216, 58, 58, 0.4);
}

.eins-tabpanel {
    animation: eins-fade 0.22s ease;
}

@keyframes eins-fade {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Clip the incoming panel only while it slides, so no horizontal scrollbar flashes. */
.eins-tabpanels.is-switching {
    overflow: hidden;
}

/* Directional slide when switching between the Solo / Online tabs */
.eins-tabpanel.slide-from-right {
    animation: eins-slide-right 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.eins-tabpanel.slide-from-left {
    animation: eins-slide-left 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes eins-slide-right {
    from { opacity: 0; transform: translateX(26px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes eins-slide-left {
    from { opacity: 0; transform: translateX(-26px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Tactile pop on the tab pill that just became active */
.eins-tab.eins-tab-pop {
    animation: eins-tab-pop 0.28s ease;
}

@keyframes eins-tab-pop {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.06); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .eins-tabpanel.slide-from-right,
    .eins-tabpanel.slide-from-left,
    .eins-tab.eins-tab-pop {
        animation: none;
    }
}

/* Opponent count selector */
.eins-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.eins-field-label {
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.05rem;
}

.opponent-select {
    display: flex;
    gap: 8px;
}

.opp-btn {
    width: 48px;
    height: 60px;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-weight: 900;
    font-size: 1.3rem;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.opp-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.5);
}

.opp-btn.active {
    background: linear-gradient(160deg, #5b8bff, #3a5bd8);
    border-color: #fff;
    box-shadow: 0 6px 16px rgba(58, 91, 216, 0.45);
}

/* Rules panel (shared by solo menu + online lobby) */
.eins-rules {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-bottom: 1.2rem;
    overflow: hidden;
}

.eins-rules > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.7rem 1rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.9);
    user-select: none;
}

.eins-rules > summary::-webkit-details-marker { display: none; }

.eins-rules > summary::after {
    content: "\25BE"; /* ▾ down triangle */
    float: right;
    transition: transform 0.2s ease;
    opacity: 0.7;
}

.eins-rules[open] > summary::after {
    transform: rotate(180deg);
}

.eins-rules-body {
    padding: 0.2rem 1rem 0.8rem;
}

/* A single rule toggle row */
.eins-rule {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.55rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.eins-rule:first-child { border-top: none; }

.eins-rule .form-check-input {
    flex: 0 0 auto;
    margin-top: 0.15rem;
    cursor: pointer;
}

.eins-rule .form-check-input:checked {
    background-color: #ff5555;
    border-color: #ff5555;
}

.eins-rule label {
    cursor: pointer;
    line-height: 1.25;
}

.eins-rule .rule-name {
    display: block;
    font-weight: 600;
    color: #fff;
    font-size: 0.95rem;
}

.eins-rule .rule-desc {
    display: block;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
}

/* Lobby reuses the rule rows but without the details wrapper */
#rules-host .eins-rule:first-child { border-top: none; }

/* Primary / secondary menu action buttons */
.eins-start-btn {
    display: block;
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 0.9rem;
    font-weight: 800;
    font-size: 1.1rem;
    color: #fff;
    background: linear-gradient(160deg, #ff6b6b, #d83a3a);
    box-shadow: 0 8px 20px rgba(216, 58, 58, 0.4);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.eins-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(216, 58, 58, 0.55);
}

.eins-join-btn {
    display: block;
    width: 100%;
    margin-top: 0.6rem;
    border-radius: 12px;
    padding: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.25);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease;
}

.eins-join-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.5);
}

.eins-code-input {
    background: rgba(0, 0, 0, 0.35) !important;
    color: #fff !important;
    border: 2px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 12px;
    font-size: 1.3rem;
    letter-spacing: 4px;
    font-weight: 700;
}

.eins-code-input:focus {
    border-color: #ff5555 !important;
    box-shadow: 0 0 0 0.2rem rgba(255, 85, 85, 0.25) !important;
}

.eins-back-link {
    display: block;
    text-align: center;
    margin-top: 1.1rem;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.15s ease;
}

.eins-back-link:hover { color: #fff; }

/* Player picker (7-0 swap) buttons */
.player-pick-btn {
    border-radius: 10px;
    padding: 0.7rem;
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.25);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease;
}

.player-pick-btn:hover {
    transform: translateY(-1px);
    border-color: #ff5555;
}

/* ============================================================
   EINS LOBBY — online waiting room (matches the menu theme)
   ============================================================ */
.eins-lobby {
    /* Normal document flow so the taller lobby scrolls with the page,
       but with the same framed/polished look as the solo menu. */
    max-width: 780px;
    padding: 1.6rem 1.6rem 1.2rem;
    border: 2px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.eins-lobby .eins-brand { margin-bottom: 1.1rem; }

/* Two-column layout: left = sharing/players/actions, right = rules */
.eins-lobby-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.6rem;
    align-items: stretch;
}

.eins-lobby-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Vertical divider between the two columns */
.eins-lobby-col-right {
    padding-left: 1.6rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

/* The first heading in each column shouldn't carry a top divider line */
.eins-lobby-col-right .eins-section-title {
    border-top: none;
    padding-top: 0;
    margin-top: 0.1rem;
}

/* Push the action buttons to the bottom of the left column */
.eins-lobby-col .eins-players { margin-bottom: auto; }
.eins-lobby-col .eins-start-btn { margin-top: 1.2rem; }

/* Collapse to a single column on narrow screens */
@media (max-width: 640px) {
    .eins-lobby-grid {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }
    .eins-lobby-col-right {
        padding-left: 0;
        border-left: none;
    }
    .eins-lobby-col-right .eins-section-title {
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding-top: 1rem;
    }
}

/* Share block: room code is the focal point */
.eins-share {
    margin-bottom: 1.3rem;
}

.eins-share-label {
    display: block;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.eins-code-hero {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 0.6rem;
}

.eins-code-field {
    flex: 1 1 auto;
    min-width: 0;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 0.55rem 0.75rem;
    text-align: center;
    font-family: "Arial Black", system-ui, sans-serif;
    font-weight: 900;
    font-size: 1.7rem;
    letter-spacing: 6px;
    text-indent: 6px; /* offset the trailing letter-spacing so text stays centered */
    cursor: pointer;
}

.eins-code-field:focus {
    outline: none;
    border-color: #ff5555;
    box-shadow: 0 0 0 0.2rem rgba(255, 85, 85, 0.25);
}

.eins-icon-btn {
    flex: 0 0 auto;
    width: 56px;
    border: none;
    border-radius: 12px;
    color: #fff;
    font-size: 1.3rem;
    background: linear-gradient(160deg, #ff6b6b, #d83a3a);
    box-shadow: 0 6px 16px rgba(216, 58, 58, 0.4);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.eins-icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 9px 20px rgba(216, 58, 58, 0.55);
}

.eins-share-actions {
    display: flex;
    gap: 8px;
}

.eins-share-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border-radius: 12px;
    padding: 0.6rem 0.5rem;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.22);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.eins-share-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.12);
}

/* Section headings (Spieler / Regeln) */
.eins-section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    font-size: 1.05rem;
    color: #fff;
    padding-top: 1rem;
    margin-bottom: 0.7rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.eins-section-title i { color: #ff7a7a; }
.eins-section-title .eins-count { color: rgba(255, 255, 255, 0.55); font-weight: 700; }

/* Player list */
.eins-players {
    list-style: none;
    margin: 0 0 1.2rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.eins-player {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
}

.eins-player-avatar {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1rem;
    color: #fff;
    background: linear-gradient(160deg, #5b8bff, #3a5bd8);
    text-transform: uppercase;
}

.eins-player-name {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eins-player-badge {
    flex: 0 0 auto;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(160deg, #ff6b6b, #d83a3a);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

.eins-player-status {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #888;
}

.eins-player-status.is-online {
    background: #3ddc84;
    box-shadow: 0 0 8px rgba(61, 220, 132, 0.7);
}

.eins-player-status.is-offline {
    background: #ff5555;
    box-shadow: 0 0 8px rgba(255, 85, 85, 0.6);
}

/* Empty seat placeholder */
.eins-player--empty {
    background: rgba(255, 255, 255, 0.03);
    border-style: dashed;
    border-color: rgba(255, 255, 255, 0.14);
}

.eins-player--empty .eins-player-avatar {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.4);
}

.eins-player--empty .eins-player-name {
    color: rgba(255, 255, 255, 0.4);
    font-weight: 500;
    font-style: italic;
}

/* Host toggle: let guests edit rules */
.eins-guest-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.7rem;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.eins-guest-toggle .form-check-input {
    margin: 0;
    cursor: pointer;
}

.eins-guest-toggle .form-check-input:checked {
    background-color: #ff5555;
    border-color: #ff5555;
}

/* Lobby rules sit in their own card (no <details> wrapper like the solo menu) */
#rules-host {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-bottom: 0.4rem;
}

/* Read-only rules for guests without edit rights */
.eins-rules-body.is-readonly {
    opacity: 0.7;
}

.eins-rules-body.is-readonly .eins-rule label {
    cursor: default;
}

/* Leave button */
.eins-leave-btn {
    display: block;
    width: 100%;
    margin-top: 0.6rem;
    border-radius: 12px;
    padding: 0.7rem;
    font-weight: 700;
    color: #ff8787;
    background: transparent;
    border: 2px solid rgba(255, 85, 85, 0.45);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.eins-leave-btn:hover {
    background: rgba(255, 85, 85, 0.15);
    border-color: #ff5555;
    color: #fff;
}

@media (max-width: 480px) {
    .eins-menu { padding: 1.2rem; }
    .eins-brand-oval { font-size: 1.7rem; padding: 0.35rem 1.8rem; }
    .eins-code-field { font-size: 1.35rem; letter-spacing: 4px; text-indent: 4px; }
    .eins-icon-btn { width: 48px; font-size: 1.15rem; }
    .eins-share-btn { font-size: 0.82rem; }
}
