@import url('https://fonts.googleapis.com/css2?family=Patrick+Hand+SC&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Walter+Turncoat&display=swap');
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Walter Turncoat', cursive, sans-serif !important;
}

:root {
    --primary: #1e3a8a;
    --primary-dark: #162f73;
    --secondary: #6b21a8;
    --success: #0f766e;
    --danger: #b42318;
    --warning: #b45309;
    --bg: #b8956a;
    --paper: #fffdf3;
    --paper-shadow: rgba(0, 0, 0, 0.18);
    --line-color: rgba(39, 123, 192, 0.22);
    --text: #1f2937;
    --text-muted: rgba(31, 41, 55, 0.68);
    --border: rgba(31, 41, 55, 0.28);
    --red-line: rgba(220, 38, 38, 0.35);
    --line-height: 32px;
    --margin-left: 80px;
}

body {
    font-family: 'Walter Turncoat', cursive, sans-serif !important;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 15% 20%, rgba(75, 46, 21, 0.10) 0%, transparent 50%),
        radial-gradient(circle at 85% 70%, rgba(70, 44, 20, 0.10) 0%, transparent 55%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.08));
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 900px;
    min-height: 600px;
    margin: 2rem auto;
    padding: var(--line-height) 2.5rem var(--line-height) var(--margin-left);
    background: var(--paper);
    background-image:
        radial-gradient(circle at 20% 15%, rgba(0, 0, 0, 0.03) 0%, transparent 55%),
        radial-gradient(circle at 80% 80%, rgba(0, 0, 0, 0.025) 0%, transparent 60%);
    border: 2px solid var(--border);
    box-shadow: 
        0 1px 3px var(--paper-shadow),
        0 10px 30px rgba(0, 0, 0, 0.3),
        inset 0 0 100px rgba(255, 243, 205, 0.5);
    position: relative;
    border-radius: 14px 8px 18px 10px;
    transform: rotate(-0.15deg);
}

.container::before {
    content: '';
    position: absolute;
    left: 60px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--red-line);
    opacity: 0.6;
}

.container::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-image: repeating-linear-gradient(
        transparent,
        transparent 31px,
        var(--line-color) 31px,
        var(--line-color) 33px
    );
    pointer-events: none;
    opacity: 0.28;
    z-index: 0;
}

.container > * {
    position: relative;
    z-index: 1;
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: 1.5rem;
    margin-top: 1rem;
}

h1 { 
    font-size: 2.5rem;
    margin-bottom: 2rem;
}

h2 { 
    font-size: 2rem;
    margin-bottom: 1.5rem;
}

h3 { 
    font-size: 1.5rem;
}

p {
    margin-bottom: 1.5rem;
    line-height: 1.8;
}

/* Navbar */
.navbar {
    background: var(--paper);
    border-bottom: 3px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px var(--paper-shadow);
}

.navbar .container {
    /* The app reuses `.container` inside the navbar.
       Override the main paper-sheet container styles here so the navbar stays header-sized. */
    min-height: auto;
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    background: transparent;
    background-image: none;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    transform: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar .container::before,
.navbar .container::after {
    display: none;
}

.logo {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--primary);
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
    transform: rotate(-2deg);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 40px;
    border: 2px solid var(--border);
    border-radius: 10px 7px 12px 8px;
    background: rgba(255, 255, 255, 0.55);
    color: var(--text);
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    line-height: 1;
    font-size: 1.25rem;
    padding: 0;
}

.nav-toggle:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);
}

/* Mobile/compact navbar (also covers mobile landscape widths) */
@media (max-width: 900px) {
    .navbar .container {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
        justify-content: space-between;
    }

    .logo {
        flex: 1 1 auto;
    }

    .nav-toggle {
        display: inline-flex;
        order: 2;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        justify-content: center;
        padding-top: 0.5rem;
        border-top: 2px dashed rgba(31, 41, 55, 0.18);
        order: 3;
    }

    .navbar.nav-open .nav-links {
        display: flex;
    }
}

.nav-links a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.3s;
    font-weight: bold;
    border-bottom: 2px solid transparent;
}

.nav-links a:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

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

.username {
    color: var(--text);
    font-weight: bold;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: 2px solid var(--primary);
    background: rgba(255, 255, 255, 0.55);
    color: var(--primary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.2);
    text-decoration: none;
    display: inline-block;
    border-radius: 12px 7px 14px 8px;
    position: relative;
    letter-spacing: 0.02em;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 3px;
    border: 2px solid rgba(31, 41, 55, 0.18);
    border-radius: 12px 7px 14px 8px;
    transform: rotate(-0.6deg);
    pointer-events: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary::after {
    border-color: rgba(255, 255, 255, 0.22);
}

.btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.65);
    color: var(--primary);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
}

.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Forms */
.form-group {
    margin-bottom: 2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: bold;
    color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border);
    background: white;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Home page specific */
.hero {
    text-align: center;
    margin: 3rem 0;
    padding: 2rem 0;
}

.hero h1 {
    color: var(--primary);
    margin-bottom: 1rem;
}

.hero p {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.cta-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin: 4rem 0;
    padding: 2rem 0;
}

.feature,
.feature-card {
    text-align: center;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 14px 8px 18px 10px;
    border: 2px solid var(--border);
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.10);
    position: relative;
}

.feature-card:nth-child(odd),
.feature:nth-child(odd) {
    transform: rotate(-0.4deg);
}

.feature-card:nth-child(even),
.feature:nth-child(even) {
    transform: rotate(0.35deg);
}

.feature h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

/* Quiz list */
.quiz-list {
    display: grid;
    gap: 1.5rem;
    margin: 2rem 0;
}

.quiz-item {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.quizzes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.quiz-card {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.55);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.10);
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.quiz-card:hover {
    transform: translateY(-2px) rotate(-0.2deg);
    box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.10);
}

.quiz-card h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.quiz-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--paper-shadow);
}

.quiz-item h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

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

/* Quiz creation */
.section {
    display: none;
    margin-bottom: 3rem;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid var(--border);
    border-radius: 4px;
}

.section.active {
    display: block;
}

.form-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 2.25rem;
    background: rgba(255, 255, 255, 0.50);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.10);
}

.form-container form {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
    width: 100%;
}

.form-container input,
.form-container textarea,
.form-container select,
.settings-grid input,
.settings-grid textarea,
.settings-grid select {
    font-family: inherit;
    border: 2px solid var(--border);
    background: rgba(255, 255, 255, 0.70);
    border-radius: 12px 7px 14px 8px;
    padding: 0.9rem 1rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.form-container input:focus,
.form-container textarea:focus,
.form-container select:focus,
.settings-grid input:focus,
.settings-grid textarea:focus,
.settings-grid select:focus {
    outline: none;
    border-color: rgba(30, 58, 138, 0.55);
    box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.10);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin: 1rem 0 2rem;
}

.settings-grid label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.remove-btn {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--danger);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.10);
}

.remove-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.10);
}

.section h2 {
    color: var(--primary);
    margin-bottom: 1rem;
}

.rounds-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.round {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border);
    border-radius: 4px;
}

.round-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.questions-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.question {
    padding: 1rem;
    background: white;
    border: 2px solid var(--border);
    border-radius: 4px;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.answers-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.answer {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.answer input[type="text"] {
    flex: 1;
}

.answer input[type="checkbox"] {
    width: auto;
}

/* Lobby */
.lobby-header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
}

.lobby-code {
    font-size: 3rem;
    color: var(--primary);
    font-weight: bold;
    letter-spacing: 0.5rem;
    margin: 1rem 0;
}

.players-list {
    display: grid;
    gap: 1rem;
    margin: 3rem 0;
}

.participants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.participant-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.55);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.10);
}

.participant-card.host {
    border-color: rgba(180, 83, 9, 0.45);
    background: rgba(255, 247, 220, 0.75);
}

.participant-icon {
    font-size: 1.3rem;
}

.player-item {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-name {
    font-weight: bold;
}

.host-badge {
    background: var(--warning);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
}

/* Quiz gameplay */
.quiz-header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
}

.question-container {
    padding: 3rem;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border);
    border-radius: 4px;
    text-align: center;
    margin-bottom: 3rem;
    min-height: 300px;
}

.question-card {
    padding: 2rem;
    background: rgba(255, 255, 255, 0.55);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.10);
}

.answer-reveal {
    margin-top: 1rem;
}

.answer-option {
    padding: 0.9rem 1rem;
    margin-top: 0.6rem;
    background: rgba(255, 255, 255, 0.70);
    border: 2px dashed rgba(31, 41, 55, 0.22);
    border-radius: 12px 7px 14px 8px;
}

.answer-option.correct-answer {
    border-style: solid;
    border-color: rgba(15, 118, 110, 0.45);
    background: rgba(214, 255, 242, 0.55);
}

.answer-option.incorrect-answer {
    border-style: solid;
    border-color: rgba(180, 35, 24, 0.45);
    background: rgba(255, 225, 221, 0.55);
}

.time-up-message {
    color: var(--danger);
    font-weight: bold;
    margin-top: 0.75rem;
}

.host-controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1.25rem;
}

.host-message {
    text-align: center;
    color: var(--text-muted);
}

.timer.warning {
    color: var(--warning);
}

.timer.danger {
    color: var(--danger);
}

.keyboard-container {
    margin-top: 1.25rem;
}

.keyboard-grid {
    display: grid;
    gap: 0.5rem;
    justify-content: center;
}

.keyboard-grid.numeric {
    grid-template-columns: repeat(5, minmax(48px, 56px));
}

.keyboard-grid.alphabetic {
    grid-template-columns: repeat(7, minmax(44px, 54px));
}

.keyboard-key {
    padding: 0.7rem 0.6rem;
    background: rgba(255, 255, 255, 0.70);
    border: 2px solid var(--border);
    border-radius: 12px 7px 14px 8px;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.10);
    cursor: pointer;
    user-select: none;
    text-align: center;
}

.keyboard-key.selected {
    background: rgba(30, 58, 138, 0.12);
    border-color: rgba(30, 58, 138, 0.45);
}

.keyboard-key:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.10);
}

.question-text {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 1rem;
    overflow-wrap: anywhere;
}

.question-image {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
    border: 2px solid var(--border);
}

/* Quiz mode: keep question view within the viewport (no vertical scrolling) */
body.quiz-active {
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.quiz-active .navbar {
    flex: 0 0 auto;
}

body.quiz-active main.container {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 auto;
    padding: 1rem 1.25rem;
    transform: none;
    overflow: hidden;
}

body.quiz-active #lobbySection.section,
body.quiz-active #quizSessionSection.section {
    margin-bottom: 0;
    padding: 0;
    background: transparent;
    border: 0;
}

body.quiz-active #lobbyContainer,
body.quiz-active #quizSessionContent {
    height: 100%;
}

body.quiz-active .quiz-in-lobby,
body.quiz-active .quiz-session {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

body.quiz-active .quiz-header,
body.quiz-active .session-header {
    margin-bottom: 0;
    padding: 0.5rem 0;
}

body.quiz-active .quiz-header h2,
body.quiz-active .session-header h2 {
    margin: 0;
}

body.quiz-active .quiz-header h3 {
    margin: 0.25rem 0;
}

body.quiz-active .timer {
    margin: 0.5rem 0;
    font-size: 1.75rem;
}

body.quiz-active .question-card {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow: hidden;
}

body.quiz-active .question-text {
    margin-bottom: 0.5rem;
    font-size: 1.35rem;
    line-height: 1.25;
    flex: 0 1 auto;
    min-height: 0;
}

/* If the question text is long, shrink it so the keyboard stays visible */
body.quiz-active .question-text.long {
    font-size: 1.15rem;
}

/* Safety valve for extremely long text: shrink more and allow internal scroll (not page scroll) */
body.quiz-active .question-text.xlong {
    font-size: 1.0rem;
    max-height: 28vh;
    max-height: 28dvh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 0.25rem;
}

body.quiz-active .question-image {
    display: block;
    margin: 0.5rem auto;
    max-width: 100%;
    width: auto;
    max-height: 32vh;
    max-height: 32dvh;
    object-fit: contain;
}

body.quiz-active .keyboard-container {
    margin-top: auto;
}

@media (max-width: 900px) {
    /* During gameplay on mobile, hide the navbar to maximize space */
    body.quiz-active .navbar {
        display: none;
    }

    body.quiz-active main.container {
        padding: 0.6rem;
    }

    body.quiz-active .quiz-header,
    body.quiz-active .session-header {
        padding: 0.25rem 0;
    }

    body.quiz-active .quiz-header h2,
    body.quiz-active .session-header h2 {
        font-size: 1.25rem;
        line-height: 1.15;
    }

    body.quiz-active .quiz-header h3 {
        font-size: 1rem;
        line-height: 1.15;
    }

    body.quiz-active .timer {
        margin: 0.25rem 0;
        font-size: 1.5rem;
    }

    body.quiz-active .quiz-header p,
    body.quiz-active .session-header p {
        margin: 0.2rem 0;
        font-size: 0.95rem;
    }

    /* Override inline styles used in the quiz header metadata */
    body.quiz-active .quiz-header > div:not(.timer) {
        font-size: 0.8rem !important;
        margin-top: 0.25rem !important;
    }

    body.quiz-active .quiz-header h3 {
        margin: 0.15rem 0 !important;
    }

    body.quiz-active .question-image {
        max-height: 22vh;
        max-height: 22dvh;
    }

    body.quiz-active .question-text {
        font-size: 1.15rem;
    }

    body.quiz-active .question-text.long {
        font-size: 1.0rem;
    }

    body.quiz-active .question-text.xlong {
        font-size: 0.95rem;
        max-height: 22vh;
        max-height: 22dvh;
    }
}

body.quiz-active .answer-option {
    margin-top: 0.4rem;
    padding: 0.75rem 0.9rem;
}

@media (max-width: 768px) {
    body.quiz-active main.container {
        padding: 0.75rem;
    }
}

.answer-input {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.timer {
    font-size: 2rem;
    color: var(--danger);
    font-weight: bold;
    margin: 1rem 0;
}

.answers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.answer-button {
    padding: 1.5rem;
    background: white;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
}

.answer-button:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.05);
}

.answer-button.selected {
    background: var(--primary);
    color: white;
}

.answer-button.correct {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.answer-button.incorrect {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* Leaderboard */
.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 2rem 0;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border);
    border-radius: 4px;
    min-height: 60px;
}

.leaderboard-item.first {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    border-color: #d4af37;
}

.leaderboard-item.second {
    background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
    border-color: #999;
}

.leaderboard-item.third {
    background: linear-gradient(135deg, #cd7f32 0%, #e6a85c 100%);
    border-color: #8b5a2b;
}

.leaderboard-rank {
    font-size: 1.5rem;
    font-weight: bold;
    width: 3rem;
}

.leaderboard-name {
    flex: 1;
    font-weight: bold;
}

.leaderboard-score {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary);
}

.leaderboard-container {
    padding: 2rem;
    background: rgba(255, 255, 255, 0.45);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.10);
}

.leaderboard-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.leaderboard-entries {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.leaderboard-entry {
    display: grid;
    grid-template-columns: 110px 1fr 140px;
    gap: 0.75rem;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.60);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
}

.leaderboard-entry .rank {
    font-weight: bold;
}

.leaderboard-entry .points {
    text-align: right;
    font-weight: bold;
    color: var(--primary);
}

.leaderboard-display {
    margin-top: 1.5rem;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255, 255, 255, 0.55);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    overflow: hidden;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 0.8rem 0.9rem;
    border-bottom: 2px dashed rgba(31, 41, 55, 0.18);
}

.leaderboard-table th {
    text-align: left;
    color: var(--text);
    background: rgba(255, 255, 255, 0.35);
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.round-transition {
    text-align: center;
    padding: 1rem 0;
}

/* Notifications */
.notification {
    position: fixed;
    right: 1.25rem;
    top: 1.25rem;
    max-width: min(420px, calc(100vw - 2.5rem));
    padding: 0.9rem 1.1rem;
    background: rgba(255, 255, 255, 0.85);
    border: 2px solid var(--border);
    border-radius: 14px 8px 18px 10px;
    box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.12);
    transform: translateY(-10px) rotate(-0.3deg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1000;
}

.notification.show {
    opacity: 1;
    transform: translateY(0) rotate(-0.3deg);
}

.notification.success {
    border-color: rgba(15, 118, 110, 0.45);
}

.notification.error {
    border-color: rgba(180, 35, 24, 0.45);
}

.notification.warning {
    border-color: rgba(180, 83, 9, 0.45);
}

/* Utility classes */
.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.hidden {
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        margin: 0;
        padding: 1.25rem 1rem;
        max-width: 100%;
        transform: none;
    }

    .container::before {
        display: none;
    }

    .container::after {
        opacity: 0.22;
    }

    /* Prevent rotated cards from causing horizontal scroll on narrow screens */
    .feature,
    .feature-card,
    .quiz-card,
    .notification {
        transform: none;
    }

    /* Avoid iOS Safari auto-zoom on focus (16px+) */
    input,
    select,
    textarea {
        font-size: 16px;
    }

    .navbar .container {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
        justify-content: space-between;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        justify-content: center;
        padding-top: 0.5rem;
        border-top: 2px dashed rgba(31, 41, 55, 0.18);
    }

    .navbar.nav-open .nav-links {
        display: flex;
    }

    .user-info {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .features {
        grid-template-columns: 1fr;
    }

    .cta-buttons {
        flex-direction: column;
    }

    .cta-buttons .btn,
    .form-container .btn,
    .host-controls .btn {
        width: 100%;
    }

    .lobby-code {
        font-size: 2rem;
        letter-spacing: 0.3rem;
    }

    /* Quiz gameplay layout adjustments */
    .quiz-header {
        margin-bottom: 1.5rem;
        padding: 1rem 0;
    }

    .question-container {
        padding: 1.25rem;
        margin-bottom: 1.5rem;
        min-height: auto;
    }

    .question-card {
        padding: 1rem;
    }

    .question-text {
        font-size: 1.25rem;
    }

    .timer {
        font-size: 1.6rem;
    }

    .answers-grid {
        grid-template-columns: 1fr;
    }

    .answer-button {
        padding: 1rem;
    }

    .keyboard-grid.numeric {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .keyboard-grid.alphabetic {
        grid-template-columns: repeat(7, minmax(0, 1fr));
    }

    .keyboard-key {
        padding: 0.6rem 0.45rem;
    }

    /* Leaderboard compaction */
    .leaderboard-container {
        padding: 1rem;
    }

    .leaderboard-entry {
        grid-template-columns: 1fr;
    }

    .leaderboard-entry .points {
        text-align: left;
    }
}

@media (max-width: 420px) {
    .logo {
        font-size: 1.6rem;
    }

    #lobbyCodeInput {
        font-size: 1.25rem !important;
        letter-spacing: 0.15em !important;
        padding: 0.85rem 0.9rem;
    }

    .lobby-code {
        font-size: 1.75rem;
        letter-spacing: 0.22rem;
    }

    .keyboard-grid.alphabetic {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    body.quiz-active .timer {
        font-size: 1.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn,
    .quiz-card,
    .notification {
        transition: none;
    }
}
