/* Custom Dracula & Retro Terminal Theme Stylesheet */

:root {
    --color-bg: #1e1f29;          /* Deep Dracula Dark */
    --color-panel-bg: #282a36;    /* Dark Gray Panel */
    --color-primary: #9b72ff;     /* Violet/Lavender Highlight */
    --color-secondary: #8be9fd;   /* Cyan */
    --color-success: #50fa7b;     /* Emerald Green */
    --color-danger: #ff5555;      /* Coral Red */
    --color-warning: #ffb86c;     /* Orange Warning */
    --color-muted: #6272a4;       /* Slate Slate Muted */
    --color-fg: #f8f8f2;          /* Off-white */
    
    --font-mono: 'Fira Code', 'Courier New', Courier, monospace;
}

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

body {
    background-color: var(--color-bg);
    color: var(--color-fg);
    font-family: var(--font-mono);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* CRT Scanlines and Screen Glow Effects */
.glow-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle, rgba(155, 114, 255, 0.05) 0%, rgba(30, 31, 41, 0) 80%);
    pointer-events: none;
    z-index: 999;
}

.crt-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.25) 50%
    );
    background-size: 100% 4px;
    z-index: 1000;
    pointer-events: none;
}

/* Header and Navigation */
.app-header {
    background-color: var(--color-panel-bg);
    border-bottom: 2px solid var(--color-primary);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.header-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    text-shadow: 0 0 10px rgba(155, 114, 255, 0.5);
}

.logo-prompt {
    animation: blink 1.2s infinite;
}

.user-status {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logged-in-badge {
    font-size: 0.8rem;
    color: var(--color-success);
    text-shadow: 0 0 5px rgba(80, 250, 123, 0.5);
}

.logged-in-badge.offline {
    color: var(--color-muted);
    text-shadow: none;
}

.username-display {
    font-weight: 500;
}

.btn-link {
    color: var(--color-danger);
    text-decoration: none;
    transition: color 0.2s;
}

.btn-link:hover {
    color: #ff79c6;
}

/* Main Container Grid Layout */
.app-container {
    flex: 1;
    padding: 2rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 2rem;
    flex: 1;
}

@media (max-width: 1200px) {
    .dashboard-grid, .dashboard-grid.logged-in {
        grid-template-columns: 1fr;
    }
}

/* Panels (Terminal Styling) */
.dash-panel {
    background-color: rgba(40, 42, 54, 0.6);
    border: 1px solid var(--color-muted);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    overflow: hidden;
    transition: border-color 0.3s;
    min-width: 0; /* Allows grid items to shrink past their content size */
}

.dash-panel:hover {
    border-color: var(--color-primary);
}

.panel-header {
    background-color: rgba(98, 114, 164, 0.2);
    border-bottom: 1px solid var(--color-muted);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    color: var(--color-secondary);
    font-weight: 500;
}

.panel-body {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* User & Auth panel styling */
.welcome-box {
    text-align: center;
}

.welcome-box h3 {
    color: var(--color-success);
    margin-bottom: 1rem;
    text-shadow: 0 0 5px rgba(80, 250, 123, 0.3);
}

.welcome-box p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--color-fg);
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-muted);
}

.auth-tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--color-muted);
    font-family: var(--font-mono);
    padding: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.auth-tab-btn.active {
    color: var(--color-primary);
    font-weight: bold;
    border-bottom: 2px solid var(--color-primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.auth-form.hidden {
    display: none;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--color-secondary);
}

.term-input {
    background-color: #181920;
    border: 1px solid var(--color-muted);
    color: var(--color-fg);
    font-family: var(--font-mono);
    padding: 0.75rem;
    border-radius: 4px;
    outline: none;
}

.term-input:focus {
    border-color: var(--color-secondary);
    box-shadow: 0 0 5px rgba(139, 233, 253, 0.3);
}

.btn-submit {
    background: none;
    border: 1px solid var(--color-success);
    color: var(--color-success);
    font-family: var(--font-mono);
    padding: 0.75rem;
    cursor: pointer;
    font-weight: bold;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-submit:hover {
    background-color: rgba(80, 250, 123, 0.1);
    box-shadow: 0 0 10px rgba(80, 250, 123, 0.3);
}

.auth-error-msg {
    background-color: rgba(255, 85, 85, 0.1);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    padding: 0.5rem;
    font-size: 0.8rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.auth-success-msg {
    background-color: rgba(80, 250, 123, 0.1);
    border: 1px solid var(--color-success);
    color: var(--color-success);
    padding: 0.5rem;
    font-size: 0.8rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

/* Quiz Catalog styling */
.catalog-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.quiz-card {
    border: 1px dashed var(--color-muted);
    padding: 1.25rem;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background-color: rgba(30, 31, 41, 0.4);
}

.quiz-card:hover {
    border-color: var(--color-primary);
}

.quiz-card.selected {
    border-style: solid;
    border-color: var(--color-success);
    background-color: rgba(80, 250, 123, 0.05);
    box-shadow: 0 0 8px rgba(80, 250, 123, 0.2);
}

.quiz-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.quiz-title {
    font-weight: bold;
    color: var(--color-fg);
    font-size: 1rem;
}

.quiz-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-weight: bold;
}

.quiz-badge.trivia {
    border: 1px solid var(--color-secondary);
    color: var(--color-secondary);
}

.quiz-badge.personality {
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
}

.quiz-desc {
    font-size: 0.85rem;
    color: #a9a9b3;
    line-height: 1.5;
}

.quiz-meta-row {
    font-size: 0.8rem;
    color: var(--color-muted);
    display: flex;
    gap: 1rem;
}

.btn-play-quiz {
    align-self: flex-start;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: bold;
}

.btn-play-quiz:hover {
    color: #b794ff;
    text-shadow: 0 0 5px rgba(155, 114, 255, 0.4);
}

/* Leaderboard styling */
.leaderboard-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--color-muted);
}

.l-tab-link {
    text-decoration: none;
    color: var(--color-muted);
    font-size: 0.8rem;
    white-space: nowrap;
    padding: 0.25rem 0.5rem;
}

.l-tab-link.active {
    color: var(--color-secondary);
    font-weight: bold;
}

.leaderboard-table-container {
    flex: 1;
    overflow: auto;
    max-height: 60vh;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    text-align: left;
}

.leaderboard-table th {
    color: var(--color-secondary);
    border-bottom: 2px solid var(--color-muted);
    padding: 0.75rem 0.5rem;
    font-weight: bold;
}

.leaderboard-table td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid rgba(98, 114, 164, 0.2);
}

.leaderboard-table tr:hover {
    background-color: rgba(98, 114, 164, 0.1);
}

.usr-col {
    font-weight: bold;
    color: var(--color-primary);
}

.outcome-col {
    color: var(--color-warning);
}

.empty-table {
    text-align: center;
    color: var(--color-muted);
    padding: 2rem !important;
}

/* Scrollbar customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #181920;
}

::-webkit-scrollbar-thumb {
    background: var(--color-muted);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Footer styling */
.app-footer {
    background-color: var(--color-panel-bg);
    border-top: 1px solid var(--color-muted);
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--color-muted);
}

.footer-shortcuts {
    color: var(--color-warning);
    font-weight: 500;
}

/* TERMINAL VIEW SCREEN (FOR PLAYING QUIZ) */
.terminal-view-container {
    width: 100%;
    max-width: 900px;
    margin: 2rem auto;
    background-color: #1e1f29;
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6), 0 0 30px rgba(155, 114, 255, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.terminal-header-bar {
    background-color: #14151b;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #282a36;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.term-lights {
    display: flex;
    gap: 6px;
}

.term-lights .light {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.term-lights .light.red { background-color: var(--color-danger); }
.term-lights .light.yellow { background-color: var(--color-warning); }
.term-lights .light.green { background-color: var(--color-success); }

.term-title-text {
    font-size: 0.8rem;
    color: var(--color-muted);
    font-weight: bold;
}

.term-exit-btn {
    text-decoration: none;
    font-size: 0.8rem;
    color: var(--color-danger);
    font-weight: bold;
}

.terminal-body {
    background-color: #1a1b24;
    padding: 2rem;
    min-height: 450px;
    font-size: 1rem;
    line-height: 1.5;
    white-space: pre-wrap;
    outline: none; /* Focus outline removed */
    position: relative;
    overflow-y: auto;
}

/* Internal styled classes for JavaScript injection */
.term-header {
    color: var(--color-fg);
    background-color: var(--color-primary);
    padding: 0.5rem 1.5rem;
    font-weight: bold;
    display: inline-block;
    margin-bottom: 1rem;
}

.term-banner-text {
    color: var(--color-fg);
}

.term-meta {
    border: 1px solid var(--color-muted);
    padding: 1rem;
    margin: 1.5rem 0;
    color: var(--color-fg);
    width: 100%;
    max-width: 650px;
}

.term-meta-title {
    color: var(--color-secondary);
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.term-btn-start {
    background-color: var(--color-success);
    color: #1e1f29;
    padding: 0.25rem 1rem;
    font-weight: bold;
    display: inline-block;
    margin-top: 1rem;
    animation: pulse 1.5s infinite;
}

.term-q-title {
    font-weight: bold;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
}

.term-q-box {
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    max-width: 700px;
    color: var(--color-fg);
}

.term-warning {
    color: var(--color-warning);
    font-weight: bold;
    margin-bottom: 1rem;
}

.term-option-line {
    cursor: pointer;
    padding: 0.25rem 0;
    display: flex;
    align-items: center;
}

.term-option-text {
    margin-left: 0.5rem;
}

.term-option-line.highlighted {
    color: var(--color-primary);
    font-weight: bold;
}

.term-option-line.highlighted .term-option-text {
    text-shadow: 0 0 5px rgba(155, 114, 255, 0.3);
}

.term-indicator-selected {
    color: var(--color-secondary);
    font-weight: bold;
}

.term-indicator-normal {
    color: var(--color-fg);
}

.term-help-footer {
    color: var(--color-muted);
    font-size: 0.8rem;
    margin-top: 2rem;
    border-top: 1px dashed var(--color-muted);
    padding-top: 0.5rem;
}

/* Results view in TUI */
.term-res-title {
    font-weight: bold;
    color: var(--color-secondary);
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.term-res-card {
    border: 2px double var(--color-success);
    padding: 1rem 2.5rem;
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--color-success);
    display: inline-block;
    margin-bottom: 1.5rem;
}

.term-res-card.danger {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.term-res-card.warning {
    border-color: var(--color-warning);
    color: var(--color-warning);
}

.term-progress-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.term-progress-bar {
    font-family: monospace;
}

.term-progress-fill {
    color: var(--color-primary);
}

.term-progress-empty {
    color: var(--color-muted);
}

.term-q-detail-row {
    margin-bottom: 1rem;
}

.term-q-status {
    font-weight: bold;
}

.term-q-status.correct { color: var(--color-success); }
.term-q-status.wrong { color: var(--color-danger); }

/* Blinking animations */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(80, 250, 123, 0.4); }
    70% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(80, 250, 123, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(80, 250, 123, 0); }
}

/* Full Screen Terminal View Override */
.full-terminal-body {
    background-color: #1a1b24;
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.full-terminal-screen {
    background-color: #1a1b24;
    width: 100vw;
    height: 100vh;
    padding: 3rem;
    box-sizing: border-box;
    overflow-y: auto;
    outline: none;
    font-size: 1.15rem;
    line-height: 1.6;
    border: none;
}

/* Category Filter Bar Styles */
.category-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.cat-btn {
    background: none;
    border: 1px solid var(--color-muted);
    color: var(--color-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.35rem 0.65rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.cat-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.cat-btn.active {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
    font-weight: bold;
    box-shadow: 0 0 5px rgba(139, 233, 253, 0.2);
}

/* Two-column layout grid override when logged in */
.dashboard-grid.logged-in {
    grid-template-columns: 1.25fr 1fr;
}

/* User Progress Summary Banner */
.user-progress-summary {
    background-color: rgba(98, 114, 164, 0.1);
    border: 1px dashed var(--color-muted);
    padding: 0.75rem 1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
    color: var(--color-fg);
}

/* Completed vs Pending Badges */
.status-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-weight: bold;
}

.status-badge.completed {
    border: 1px solid var(--color-success);
    color: var(--color-success);
    background-color: rgba(80, 250, 123, 0.05);
}

.status-badge.pending {
    border: 1px solid var(--color-muted);
    color: var(--color-muted);
    background-color: rgba(98, 114, 164, 0.05);
}

/* Touch and click target padding improvements */
.term-option-line {
    cursor: pointer;
    padding: 0.65rem 0.85rem !important; /* Touch-friendly size */
    margin: 0.4rem 0 !important;
    border: 1px dashed transparent;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.term-option-line:hover, .term-option-line.highlighted {
    background-color: rgba(98, 114, 164, 0.15);
    border-color: rgba(155, 114, 255, 0.3);
}

/* Touch Control buttons for mobile */
.term-touch-controls {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    margin-bottom: 1.5rem;
    max-width: 500px;
    width: 100%;
}

.term-touch-btn {
    background: none;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    padding: 0.75rem 1.25rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    flex: 1;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.term-touch-btn.primary {
    border: 1px solid var(--color-success);
    color: var(--color-success);
}

.term-touch-btn.primary:hover, .term-touch-btn.primary:active {
    background-color: rgba(80, 250, 123, 0.1);
    box-shadow: 0 0 10px rgba(80, 250, 123, 0.2);
}

.term-touch-btn.secondary {
    border: 1px solid var(--color-secondary);
    color: var(--color-secondary);
}

.term-touch-btn.secondary:hover, .term-touch-btn.secondary:active {
    background-color: rgba(139, 233, 253, 0.1);
    box-shadow: 0 0 10px rgba(139, 233, 253, 0.2);
}

.term-touch-btn.start {
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
    margin-top: 1.5rem;
    max-width: 320px;
    width: 100%;
}

.term-touch-btn.start:hover, .term-touch-btn.start:active {
    background-color: rgba(155, 114, 255, 0.1);
    box-shadow: 0 0 10px rgba(155, 114, 255, 0.2);
}

/* Badge containers and play buttons styling */
.quiz-badge-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.logged-in .quiz-card {
    cursor: pointer;
    transition: all 0.25s ease;
}

.disabled-quiz-btn {
    opacity: 0.5;
    cursor: not-allowed;
    border: 1px solid var(--color-muted);
    color: var(--color-muted);
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.05);
}

.leaderboard-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px dashed var(--color-muted);
    padding-bottom: 0.75rem;
}

.leaderboard-header-title {
    font-size: 0.9rem;
    color: var(--color-secondary);
    font-weight: bold;
}

.leaderboard-general-btn {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    margin: 0;
    background: rgba(80, 250, 123, 0.05);
    cursor: pointer;
}

.usr-col a {
    display: inline-block;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

/* Mobile Responsiveness Media Queries */
@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .app-container {
        padding: 1rem;
    }

    .panel-body {
        padding: 1rem;
    }

    .dashboard-grid {
        gap: 1rem;
    }

    .full-terminal-screen {
        padding: 1.5rem;
        font-size: 0.95rem;
    }

    .category-filter-bar {
        gap: 0.25rem;
    }

    .cat-btn {
        font-size: 0.65rem;
        padding: 0.25rem 0.5rem;
    }

    .quiz-card {
        padding: 1rem;
    }

    .leaderboard-table th, .leaderboard-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }

    .term-touch-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .term-touch-btn {
        width: 100%;
    }

    .term-q-box {
        padding: 0.75rem;
    }

    /* Disable panel height limitations and scroll trapping on mobile stacked view */
    .catalog-panel .panel-body,
    .leaderboard-panel .panel-body,
    .profile-history-panel .panel-body {
        max-height: none !important;
        overflow-y: visible !important;
    }

    .catalog-list,
    .leaderboard-table-container {
        max-height: none !important;
        overflow-y: visible !important;
    }

    .usr-col a {
        max-width: 80px;
    }
}

/* Layout panel height constraint and custom scrollbar rules (for screens wider than mobile) */
@media (min-width: 769px) {
    .catalog-panel .panel-body,
    .leaderboard-panel .panel-body,
    .profile-history-panel .panel-body {
        max-height: 65vh;
        overflow-y: auto;
    }
}

.panel-body::-webkit-scrollbar {
    width: 6px;
}
.panel-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
.panel-body::-webkit-scrollbar-thumb {
    background: var(--color-muted);
    border-radius: 3px;
}
.panel-body::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Specific mobile media queries positioned at the bottom to guarantee precedence */
@media (max-width: 1200px) {
    .dashboard-grid.logged-in {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .date-col, .outcome-col {
        display: none !important;
    }
}

/* Micro mobile targets (Phones) */
@media (max-width: 480px) {
    .app-container {
        padding: 0.75rem;
    }

    .panel-body {
        padding: 0.75rem !important;
    }

    .leaderboard-header-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .quiz-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .usr-col a {
        max-width: 65px;
    }
}

