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

/* ── Light card-deck theme (default) ── */
:root {
    --bg-table: #2d6a4f;           /* green felt table */
    --bg-card: #fffff8;            /* off-white card stock */
    --bg-card-back: #1a3c6e;       /* card back — deep navy */
    --bg-button: #fffff8;
    --bg-button-hover: #e8e0d0;
    --bg-pick: #b5451b;            /* warm red-orange, like a casino chip */
    --bg-pick-hover: #9e3a14;
    --border-card: #c8b99a;        /* aged-paper edge */
    --shadow-card: 0 4px 20px rgba(0,0,0,0.25), 0 1px 4px rgba(0,0,0,0.15);
    --shadow-card-hover: 0 8px 30px rgba(0,0,0,0.3);
    --text-main: #2c2416;
    --text-heading: #fffff8;
    --text-muted: #6b5e4f;
    --text-hint: #8a7e6e;
    --text-done: #b5451b;
    --text-strong: #1a3c6e;
    --text-button: #2c2416;
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --deck-offset: 5px;
}

/* ── Dark mode ── */
body.dark {
    --bg-table: #1a1a2e;
    --bg-card: #23233a;
    --bg-card-back: #0f3460;
    --bg-button: #2a2a45;
    --bg-button-hover: #3d3d5c;
    --bg-pick: #c0392b;
    --bg-pick-hover: #a93226;
    --border-card: #3d3d5c;
    --shadow-card: 0 4px 20px rgba(0,0,0,0.5), 0 1px 4px rgba(0,0,0,0.3);
    --shadow-card-hover: 0 8px 30px rgba(0,0,0,0.6);
    --text-main: #e0ddd5;
    --text-heading: #e0ddd5;
    --text-muted: #9a9080;
    --text-hint: #706858;
    --text-done: #e67e22;
    --text-strong: #7fb3e0;
    --text-button: #e0ddd5;
}

body {
    font-family: var(--font-body);
    background: var(--bg-table);
    /* Subtle felt texture via radial noise */
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(255,255,255,0.03) 0%, transparent 70%),
        radial-gradient(ellipse at 80% 50%, rgba(0,0,0,0.06) 0%, transparent 70%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    transition: background 0.4s, color 0.4s;
}

h1 {
    font-family: var(--font-display);
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: var(--text-heading);
    text-align: center;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ── Controls ── */
.controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 2rem;
}

select, button {
    font-family: var(--font-body);
    font-size: 1.1rem;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
}

select {
    background: var(--bg-card);
    color: var(--text-main);
    border: 2px solid var(--border-card);
    font-size: 1.05rem;
}

button {
    background: var(--bg-button);
    color: var(--text-button);
    border: 2px solid var(--border-card);
    transition: all 0.15s ease;
    font-weight: 500;
}

button:hover:not(:disabled) {
    background: var(--bg-button-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.nav-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.status {
    font-size: 0.95rem;
    color: var(--text-heading);
    margin-left: 0.5rem;
    opacity: 0.8;
}

.keyboard-hint {
    font-size: 0.8rem;
    color: var(--text-hint);
    margin-top: 0.4rem;
    text-align: center;
    width: 100%;
}

/* ── Student list ── */
.student-list {
    max-width: 720px;
    width: 100%;
    margin-bottom: 1rem;
    display: none;
}

.student-list-toggle {
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.15s ease;
}

.student-list-toggle:hover {
    background: var(--bg-button-hover);
}

.student-count {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: auto;
}

.student-list-items {
    list-style: none;
    display: none;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.6rem 0 0 0;
}

.student-list-items.expanded {
    display: flex;
}

.student-list-item {
    background: var(--bg-button);
    color: var(--text-button);
    border: 1px solid var(--border-card);
    padding: 0.3rem 0.65rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.student-list-item:hover {
    background: var(--bg-pick);
    color: #fff;
    border-color: var(--bg-pick);
}

.student-list-item.shown {
    opacity: 0.35;
    text-decoration: line-through;
}

/* ── Card deck area ── */
.deck-area {
    position: relative;
    max-width: 720px;
    width: 100%;
    min-height: 280px;
    perspective: 800px;
}

/* Stacked deck cards behind the main card */
.deck-card {
    position: absolute;
    inset: 0;
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.deck-card-1 {
    transform: translate(6px, 6px) rotate(1.5deg);
}

.deck-card-2 {
    transform: translate(12px, 10px) rotate(-2.2deg);
}

.deck-card-3 {
    transform: translate(3px, 14px) rotate(3deg);
}

/* Hide deck cards progressively as pool shrinks */
.deck-area.deck-few .deck-card-3 {
    opacity: 0;
    transform: translate(12px, 10px) rotate(-2.2deg) scale(0.97);
}

.deck-area.deck-empty .deck-card {
    opacity: 0;
    transform: translate(0, 0) rotate(0) scale(0.98);
}

/* ── The question card itself ── */
.question-card {
    position: relative;
    z-index: 1;
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 12px;
    padding: 2.5rem 2.5rem 2rem;
    min-height: 280px;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: var(--shadow-card);
    transition: background 0.4s, border-color 0.4s, box-shadow 0.3s, transform 0.15s;
}

.question-card:hover {
    box-shadow: var(--shadow-card-hover);
}

/* Card flip animation */
.question-card.flipping {
    animation: cardFlip 0.45s ease-in-out;
}

@keyframes cardFlip {
    0%   { transform: rotateY(0deg) scale(1); }
    40%  { transform: rotateY(90deg) scale(0.95); }
    60%  { transform: rotateY(90deg) scale(0.95); }
    100% { transform: rotateY(0deg) scale(1); }
}

/* Subtle deal-in for first appearance */
.question-card.deal-in {
    animation: dealIn 0.35s ease-out;
}

@keyframes dealIn {
    from { transform: translateY(-30px) rotate(-2deg); opacity: 0; }
    to   { transform: translateY(0) rotate(0); opacity: 1; }
}

/* ── Card content ── */
.question-card .author {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border-card);
}

.question-card .content {
    font-family: var(--font-display);
    font-size: 1.45rem;
    line-height: 1.65;
    color: var(--text-main);
}

.question-card .content p {
    margin-bottom: 1rem;
}

.question-card .content strong {
    color: var(--text-strong);
}

.scroll-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding-top: 0.5rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.9; }
}

.placeholder {
    text-align: center;
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-style: italic;
    padding-top: 2rem;
}

.done-message {
    text-align: center;
    color: var(--text-done);
    font-family: var(--font-display);
    font-size: 1.3rem;
    padding-top: 2rem;
}

/* ── Primary action button — casino chip style ── */
#pickBtn {
    background: var(--bg-pick);
    font-weight: 700;
    color: #fff;
    border-color: var(--bg-pick);
    letter-spacing: 0.02em;
}

#pickBtn:hover:not(:disabled) {
    background: var(--bg-pick-hover);
    border-color: var(--bg-pick-hover);
}

/* ── Theme toggle ── */
#themeBtn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.2);
    font-size: 1.3rem;
    padding: 0.35rem 0.55rem;
    line-height: 1;
    border-radius: 6px;
}

#themeBtn:hover {
    background: rgba(255,255,255,0.25);
}

/* ── Remaining count badge ── */
.remaining-badge {
    display: inline-block;
    background: var(--bg-card);
    color: var(--text-muted);
    border: 2px solid var(--border-card);
    border-radius: 20px;
    padding: 0.25rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: 0.5rem;
    letter-spacing: 0.03em;
}

/* ── Mobile ── */
@media (max-width: 600px) {
    body { padding: 1rem 0.75rem; }
    h1 { font-size: 1.3rem; margin-bottom: 1rem; }

    .controls {
        flex-direction: column;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    select {
        width: 100%;
        font-size: 1.05rem;
    }

    .nav-row {
        display: flex;
        width: 100%;
        gap: 0.5rem;
    }

    .nav-row button {
        flex: 1;
        font-size: 0.95rem;
        padding: 0.65rem 0.5rem;
    }

    .nav-row #pickBtn {
        flex: 2;
    }

    .keyboard-hint { display: none; }

    .status {
        margin-left: 0;
        text-align: center;
        width: 100%;
    }

    .deck-area { min-height: 220px; }

    .question-card {
        padding: 1.2rem;
        border-radius: 10px;
        max-height: 60vh;
        min-height: 220px;
    }

    .question-card .content { font-size: 1.1rem; }
    .placeholder, .done-message { font-size: 1.05rem; }
}
