:root {
    --bg: #0f172a;
    --panel: #111827;
    --card: #0b1220;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --primary: #22c55e;
    --primary-700: #16a34a;
    --secondary: #3b82f6;
    --danger: #ef4444;
    --ring: #1f2937;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    position: relative;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    background: radial-gradient(1200px 1200px at 10% 0%, #101b34, #0b1122 45%, #060910 80%) fixed, #030712;
    color: var(--text);
    transition: background 0.4s ease;
}

body.game-session {
    background-color: #000;
}

body.game-session::before {
    content: '';
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.78) 55%, rgba(0,0,0,0.9) 100%);
    pointer-events: none;
    z-index: 0;
}

#app { min-height: 100%; display: flex; flex-direction: column; position: relative; z-index: 1; }

.app-header, .app-footer { text-align: center; padding: 16px; color: var(--muted); }

main {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
}

.card {
    background: rgba(12, 18, 27, 0.82);
    border: 1px solid rgba(37, 56, 74, 0.9);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.55);
}

.hidden { display: none !important; }

.players-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 12px 0 16px; }
.players-grid label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.players-grid input, .players-grid select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--ring); background: #0a0f1c; color: var(--text); }
.admin-wrapper label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="file"], select, textarea {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--ring);
    background: #0a0f1c;
    color: var(--text);
    font-family: inherit;
}
.admin-subsection { display: grid; gap: 12px; margin-top: 16px; }
.admin-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.admin-list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid rgba(37, 56, 74, 0.8); border-radius: 10px; background: rgba(15, 23, 42, 0.55); }
.admin-list li .meta { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); }
.admin-list li .meta strong { font-size: 15px; color: var(--text); }
.admin-list li .actions { display: flex; gap: 8px; }
.admin-grid-full { grid-column: 1 / -1; }
.admin-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: start; }
.admin-list button { padding: 6px 10px; font-size: 13px; }
.admin-list .danger { border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }
.table-wrapper { overflow: auto; border: 1px solid rgba(37, 56, 74, 0.7); border-radius: 10px; background: rgba(15, 23, 42, 0.45); }
.admin-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid rgba(37, 56, 74, 0.6); font-size: 13px; }
.admin-table th { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: rgba(59, 130, 246, 0.08); }
.admin-table td.empty { text-align: center; color: var(--muted); font-style: italic; }
.setup-actions { display: grid; gap: 12px; }
.online { padding: 12px; border: 1px dashed var(--ring); border-radius: 10px; background: rgba(255,255,255,0.03); }
.online-row { display: grid; grid-template-columns: 1fr auto 12px 160px auto; gap: 8px; align-items: center; }
.online-row input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--ring); background: #0a0f1c; color: var(--text); }
.online .spacer { }
.hint { color: var(--muted); }

.session-pill { margin-left: 8px; background: rgba(255,255,255,0.08); border: 1px solid var(--ring); border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--muted); }

button { cursor: pointer; border-radius: 10px; border: 1px solid var(--ring); padding: 10px 14px; color: var(--text); background: #0a0f1c; transition: all 0.15s ease; }
button:hover { transform: translateY(-1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
button.primary { background: var(--primary); color: #031107; border-color: transparent; font-weight: 700; }
button.primary:hover { background: var(--primary-700); }
button.secondary { background: #0a0f1c; }
button.ghost { background: transparent; }

.board {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
    width: 100%;
    max-width: none;
}

@media (min-width: 900px) {
    .board { grid-template-columns: 1fr 1fr; align-items: start; }
}

.ladder-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 48px; }
.legend { display: flex; gap: 8px; }
.marker { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 2px solid rgba(255,255,255,0.8); }
.marker-0 { background: #22c55e; }
.marker-1 { background: #3b82f6; }
.marker-2 { background: #f59e0b; }
.marker-3 { background: #ef4444; }

.question-card { display: grid; gap: 12px; }
.question-text { font-size: 18px; font-weight: 600; }
.choices { display: grid; gap: 8px; }
.choices button { text-align: left; }

.turn-indicator { margin-bottom: 12px; color: var(--muted); }
.feedback { min-height: 22px; margin-top: 6px; font-weight: 600; }
.feedback.correct { color: var(--primary); }
.feedback.incorrect { color: var(--danger); }

.controls { display: flex; gap: 8px; margin-top: 8px; }

.winner { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.6); overflow: hidden; }
.winner .winner-content { text-align: center; position: relative; z-index: 2; }

/* Multiple ladders layout */
.ladders-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    justify-content: center;
    justify-items: center;
}
.player-ladder {
    position: relative;
    /* border: 1px solid rgba(42, 62, 84, 0.8); */
    border-radius: 16px;
    padding: 16px 56px 36px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
    width: clamp(180px, 24vw, 240px);
}
.player-ladder h3 {
    margin: 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #f8fafc;
    text-transform: uppercase;
    letter-spacing: 0.55px;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}
.player-label-name { font-weight: 600; }
.player-ladder h3 .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.35);
    display: inline-block;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.player-ladder h3 .dot.dot-0 { background: #22c55e; }
.player-ladder h3 .dot.dot-1 { background: #3b82f6; }
.player-ladder h3 .dot.dot-2 { background: #f59e0b; }
.player-ladder h3 .dot.dot-3 { background: #ef4444; }
body:not(.game-session) .player-ladder { display: none; }
.ladder-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 3;
    margin: 0 auto;
    background-image: url('./assets/ladder-new.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
}
.ladder-scale {
    position: absolute;
    right: -42px;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    font-size: clamp(10px, 1.1vw, 12px);
    color: rgba(226, 232, 240, 0.85);
    text-shadow: 0 2px 6px rgba(0,0,0,0.75);
    pointer-events: none;
}
.ladder-marker { padding-right: 4px; }
.ladder-chip {
    position: absolute;
    left: 50%;
    bottom: -6%;
    transform: translate(-50%, 0);
    width: clamp(48px, 46%, 96px);
    height: auto;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
    transition: bottom 0.35s ease;
}
.ladder-character {
    width: 180%;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 6px 12px rgba(0,0,0,0.7));
    animation: ladder-bob 1.6s ease-in-out infinite alternate;
}

.ladder {
    background-image: url('./assets/background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

@keyframes ladder-bob {
    from { transform: translateY(0); }
    to { transform: translateY(-6px); }
}

@media (min-width: 1000px) {
    .ladders-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.confetti-container { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
.confetti-piece {
    position: absolute;
    top: -12%;
    width: 10px;
    height: 18px;
    border-radius: 2px;
    opacity: 0;
    animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translate3d(0, -10vh, 0) rotate(0deg);
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    100% {
        transform: translate3d(var(--confetti-x, 0px), 120vh, 0) rotate(720deg);
        opacity: 0;
    }
}
