/* Variables */
:root {
    --bg-dark-1: #050505;
    --bg-dark-2: #141414;
    --accent-color: #ff5f1f;
    --focus-accent-color: #22c55e;
    --text-light: #f0f0f0;
    --border-color: #333;
    --shadow-color: rgba(0, 0, 0, 0.5);

    /* Footer Variables */
    --badge-bg-light: rgba(255,255,255,.85);
    --badge-bg-dark: rgba(18,18,18,.75);
    --badge-text-light:#1a1a1a;
    --badge-text-dark:#fff;
    --fade-duration: .9s;
    --spin-duration: 2.4s;
    --glow-duration: 3.6s;
    --breath-duration: 6s;
}

/* Global Reset and Dark Theme */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: sans-serif;
}

body {
    overflow-x: hidden;
    background-color: var(--bg-dark-1);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body:not(.student-body) {
    font-size: 15px;
}

.app-container {
    max-width: 1200px;
    width: 95%;
    margin: 0 auto;
    flex-grow: 1;
    padding-bottom: 50px; /* Space for fixed footer */
}

/* --- Typography --- */
h2 {
    color: var(--accent-color);
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

/* --- Top Bar (Header) --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.logo {
    font-size: 1.6em;
    font-weight: bold;
    cursor: pointer;
}


.logo-accent {
    color: var(--accent-color);
}

body.focus-mode-on .logo-accent {
    color: var(--focus-accent-color);
}

.user-info span {
    margin-right: 15px;
}

/* --- Buttons and Inputs --- */
.btn {
    padding: 8px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
    white-space: nowrap;
    position: relative;
}

.btn-primary {
    background-color: var(--accent-color);
    color: var(--bg-dark-1);
}

.btn-primary:hover {
    background-color: #ff7f47;
}

.btn-secondary {
    background-color: var(--bg-dark-2);
    color: var(--text-light);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #222;
}

.big-btn {
    padding: 15px 30px;
    font-size: 1.5em;
    margin: 20px 0;
}

/* Loading state (for student RANDOM button spinner) */
.btn-loading {
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    right: -26px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: rgba(255,255,255,1);
    animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Input/Select Styling */
select, input[type="text"], input[type="password"] {
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--bg-dark-2);
    color: var(--text-light);
    margin-right: 10px;
}

.upload-btn {
    display: inline-block;
}

/* --- Main Layout (Teacher page default) --- */
.main-content {
    display: flex;
    gap: 20px;
}


/* Panels container (teacher) */
.app-content-layout {
    display: flex; /* shown/hidden via JS */
    gap: 20px;
    width: 100%;
    align-items: stretch;
}

.section-filters, .section-history {
    background-color: var(--bg-dark-2);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px var(--shadow-color);
}

.section-filters {
    flex: 1; /* Left panel */
    min-width: 300px;
}

.section-picker {
    flex: 2; /* Center panel */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.section-history {
    flex: 1; /* Right panel */
    min-width: 250px;
}

.filter-row {
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* --- Name Display Box --- */
#name-display-box {
    background-color: var(--bg-dark-2);
    border: 3px solid var(--accent-color);
    border-radius: 15px;
    padding: 20px; /* Reduced vertical padding to allow more text room */
    margin-bottom: 20px;
    width: 100%;
    height: 200px;
    min-height: 200px;
    max-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: border-color 0.3s;
    overflow: hidden;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}


#picker-name {
    width: 100%;
    max-width: 100%;
    display: block;
    text-align: center;
    line-height: 1.2;
    padding: 0 10px;
    
    /* UPDATED: Allow text wrapping */
    white-space: normal;
    word-wrap: break-word;
    
    font-size: 10px; /* Default small, JS will maximize it */
    font-weight: 900;
    color: var(--text-light);
    transition: transform 0.3s;
}

/* Picker Animation (Class added in JS) */
.picked {
    animation: pulse 0.5s ease-out;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 1; color: var(--accent-color); }
    100% { transform: scale(1); opacity: 1; }
}

/* Error / Info Messages */
.error-message {
    color: var(--accent-color); 
    margin-top: 10px;
    font-weight: bold;
}

/* --- Teacher History List --- */
#history-list {
    list-style: none;
    padding: 0;
    max-height: 400px;
    overflow-y: auto;
}

#history-list li {
    padding: 8px 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 1.1em;
}

#history-list li:last-child {
    border-bottom: none;
}

.history-placeholder {
    color: #888;
    text-align: center;
}

/* --- Modal --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

/* IMPORTANT: allow scrolling inside tall modals */
.modal-content {
    background-color: var(--bg-dark-2);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 0 20px var(--shadow-color);
    text-align: center;
    max-height: 90vh;      /* <--- added */
    overflow-y: auto;      /* <--- added */
}

#pin-input {
    width: 150px;
    text-align: center;
    font-size: 1.5em;
    margin-bottom: 15px;
}

.hidden {
    display: none !important;
}

/* --- Responsive Design (Teacher) --- */
@media (max-width: 900px) {
    /* Teacher panels should stack on phone */
    body:not(.student-body) .app-content-layout {
        flex-direction: column;
        align-items: center;
    }
    body:not(.student-body) .app-content-layout .section-filters,
    body:not(.student-body) .app-content-layout .section-picker,
    body:not(.student-body) .app-content-layout .section-history {
        width: 100%;
    }
    body:not(.student-body) .filter-row {
        align-items: center;
    }
    body:not(.student-body) .filter-row label {
        width: 100%;
        text-align: center;
    }

    .main-content {
        flex-direction: column;
    }

    .section-filters, .section-history {
        min-width: unset;
        width: 100%;
    }
    
    .section-picker {
        order: -1; /* Place picker at the top on mobile */
    }

    .filter-row {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .filter-row select, .filter-row label, .filter-row button {
        width: 100%;
        margin-bottom: 5px;
    }

    #picker-name {
        /* JS handles sizing now */
    }
}

/* ===================== STUDENT PAGE LAYOUT ===================== */

/* Center main content on student page */
.student-body .main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Card-like panels on student page (join + picker) */
.student-panel {
    background-color: var(--bg-dark-2);
    padding: 24px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 8px var(--shadow-color);
    width: 100%;
    max-width: 480px;
    margin: 20px auto;
    text-align: center;
}

/* Student picker layout: vertical stack, history under button */
.student-content-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Make the box consistent size so it doesn’t “jump” with long names */
.student-content-layout #name-display-box {
    width: 94%; /* Keeps a small gap on mobile so it's not edge-to-edge */
    min-height: 180px;
}

/* Student history list styling */
#history-list-student {
    list-style: none;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
    text-align: left;
}

#history-list-student li {
    padding: 6px 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 1em;
}

#history-list-student li:last-child {
    border-bottom: none;
}

/* On small screens, still centered */
@media (max-width: 900px) {
    .student-body .main-content {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .student-panel {
        margin: 10px auto;
        /* Ensure panel width is controlled on very small screens */
        width: 95%; 
    }
}

/* ===================== GLOBAL FOOTER BADGE CSS ===================== */
.global-footer-badge{
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%) translateY(6px);
    z-index: 900;
    user-select: none;
    font: 500 clamp(12px,1.6vw,14px)/1.2 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
    color: var(--badge-text-light);
    background: var(--badge-bg-light);
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 999px;
    padding: 8px 14px;
    box-shadow: 0 6px 24px rgba(0,0,0,.08);
    backdrop-filter: saturate(120%) blur(6px);
    opacity: 0;
    white-space: nowrap; /* keep in one line on mobile as much as possible */

    /* Animations: fade-in + gentle breathing shadow */
    animation:
        badge-fade-in var(--fade-duration) ease-out forwards,
        badge-breathe var(--breath-duration) ease-in-out infinite;
}

.global-footer-badge .prefix { opacity: .8; margin-right: 6px; }
.global-footer-badge .name { margin: 0 6px; font-weight: 600; }

/* Hearts: gentle 3D spin + glow pulse (staggered) */
.global-footer-badge .heart{
    display: inline-block;
    margin: 0 2px;
    transform-origin: 50% 55%;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,.1));
    will-change: transform, filter;
    animation:
        heart-spin var(--spin-duration) cubic-bezier(.45,.05,.55,.95) infinite,
        heart-glow var(--glow-duration) ease-in-out infinite;
}
.global-footer-badge .heart:first-of-type{ animation-delay: .3s, .0s; }
.global-footer-badge .heart:last-of-type { animation-delay: .0s, .9s; }

@keyframes badge-fade-in{
    0%   { opacity: 0; transform: translateX(-50%) translateY(10px); }
    100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes badge-breathe{
    0%,100% { box-shadow: 0 6px 24px rgba(0,0,0,.08); }
    50%     { box-shadow: 0 10px 28px rgba(0,0,0,.12); }
}

/* Subtle 3D spin + tilt so it's not a flat wheel */
@keyframes heart-spin{
    0%   { transform: rotateY(0deg)  rotateZ(0deg)   translateY(0); }
    25%  { transform: rotateY(180deg) rotateZ(6deg)  translateY(-1px); }
    50%  { transform: rotateY(360deg) rotateZ(0deg)  translateY(0); }
    75%  { transform: rotateY(540deg) rotateZ(-6deg) translateY(-1px); }
    100% { transform: rotateY(720deg) rotateZ(0deg)  translateY(0); }
}
@keyframes heart-glow{
    0%,100% { filter: drop-shadow(0 1px 0 rgba(0,0,0,.1)) }
    50%     { filter: drop-shadow(0 0 6px rgba(255, 0, 64, .35)) }
}

/* Dark mode polish */
@media (prefers-color-scheme: dark) {
    .global-footer-badge{
        color: var(--badge-text-dark);
        background: var(--badge-bg-dark);
        border-color: rgba(255,255,255,.12);
        box-shadow: 0 6px 24px rgba(0,0,0,.35);
    }
}

/* Accessibility: respect reduced motion */
@media (prefers-reduced-motion: reduce){
    .global-footer-badge{
        animation: none;
        opacity: 1;
        transform: translateX(-50%);
    }
    .global-footer-badge .heart{
        animation: none;
    }
    .picked{
        animation: none;
    }
}

/* Mobile tweak */
@media (max-width:480px){
    .global-footer-badge{
        bottom: 10px;
        padding: 7px 12px;
    }
}

/* --- New Code Display Style --- */
.big-code {
    font-size: 4em;
    font-weight: bold;
    color: var(--accent-color);
    margin: 20px 0;
    letter-spacing: 5px;
}

/* --- QR Code & Session Info --- */
.session-info-modal {
    text-align: center;
}

.qr-code-container {
    margin: 15px auto;
    background: white;
    padding: 10px;
    width: fit-content;
    border-radius: 10px;
}

.short-link {
    display: block;
    margin-top: 10px;
    color: var(--accent-color);
    text-decoration: none;
    font-size: 1.2em;
    font-weight: bold;
    word-break: break-all;
}

/* Top Corner Floating Badge */
.mini-session-badge {
    position: fixed;
    top: 90px;
    right: 20px;
    background: rgba(20, 20, 20, 0.95);
    border: 2px solid var(--accent-color);
    padding: 15px;
    border-radius: 12px;
    z-index: 1500;
    display: none; /* Hidden by default, show via JS */
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    min-width: 150px;
}

.mini-session-badge span {
    font-size: 0.8em;
    color: #aaa;
    margin-bottom: 5px;
}

.mini-session-badge strong {
    font-size: 2em;
    color: white;
    letter-spacing: 3px;
    font-weight: 900;
    margin-bottom: 10px;
}

.badge-controls {
    display: flex;
    gap: 5px;
}

.badge-btn {
    padding: 5px 10px;
    font-size: 0.8em;
    cursor: pointer;
    border-radius: 4px;
    border: none;
    font-weight: bold;
}

.btn-show {
    background: #333;
    color: white;
    border: 1px solid #555;
}

.btn-end {
    background: red;
    color: white;
}


/* Session modal links */
.modal-content .short-link {
    color: #fff;
}
.modal-content .secondary-link {
    opacity: 0.85;
    font-size: 0.95em;
}
.tiny-muted {
    margin-top: 8px;
    font-size: 0.9em;
    opacity: 0.85;
}


/* Student join overlay */
.joining-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.joining-card {
    background: rgba(20,20,20,0.95);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
    padding: 18px 18px;
    width: min(340px, 90vw);
    text-align: center;
}

.joining-text {
    margin-top: 12px;
    font-weight: 700;
    color: #fff;
}

.spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.25);
    border-top-color: #fff;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Slot shuffle effect */
.slot-shuffling {
    letter-spacing: 1px;
    filter: blur(0.4px);
    opacity: 0.92;
}

/* Restart button styling */
.btn-restart {
    border: 2px solid var(--accent-color);
}


/* Responsive layout for teacher page on phone/tablet */
@media (max-width: 900px) {
    .main-content {
        flex-direction: column;
        gap: 14px;
    }

    .section-filters,
    .section-picker,
    .section-history {
        width: 100%;
    }

    .section-picker {
        padding: 14px;
    }
}


/* top-bar stack on phone (teacher) */
@media (max-width: 700px) {
    body:not(.student-body) .top-bar {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        text-align: center;
    }
    body:not(.student-body) .user-info {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    body:not(.student-body) .user-info span {
        margin-right: 0;
    }
}

/* teacher-picker-font */
body:not(.student-body) #picker-name {
    /* JS will override, this is fallback */
    font-size: 2.7em;
}
@media (max-width: 700px) {
    body:not(.student-body) #picker-name {
        font-size: 2.2em;
    }
}



/* Keep the name box stable. Shrink the TEXT, not the box. */
#picker-name {
    width: 100%;
    max-width: 100%;
    
    /* Allow text wrapping for long names */
    white-space: normal; 
    word-wrap: break-word;
    
    /* Center it inside the box */
    text-align: center;
}

/* Slot-machine shuffle effect (student side) */
#picker-name.slot-shuffling {
    animation: slotFlicker 0.18s infinite;
    filter: blur(0.4px);
}

@keyframes slotFlicker {
    0% { transform: translateY(0px); opacity: 0.95; letter-spacing: 0.5px; }
    50% { transform: translateY(-1px); opacity: 1; letter-spacing: 1.2px; }
    100% { transform: translateY(0px); opacity: 0.95; letter-spacing: 0.5px; }
}
