/* ── Theme Variables ── */
:root {
    --bg-color: #18191a;
    --card-bg: #242526;
    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --border-color: #3e4042;
    --surface-color: #3a3b3c;
    --nav-pill-bg: #303132;
    --nav-pill-text: #e4e6eb;
    --primary-color: #4080ff;
    --primary-dark: #242526; /* Match card bg for seamless nav */
    --success-color: #45a049;
    --error-color: #e53935;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] {
    /* High contrast dark mode for variety */
    --bg-color: #0b0c0d;
    --card-bg: #161718;
    --border-color: #2a2b2c;
    --surface-color: #1f2021;
}

/* ── Base ── */
body {
    background: var(--bg-color);
    font-family: 'Roboto', sans-serif;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

main {
    flex: 1;
    padding-bottom: 4rem;
}

/* ── Navbar ── */
nav {
    background-color: var(--primary-dark) !important;
}

nav .nav-wrapper {
    padding: 0 1rem;
}

nav .brand-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.4rem;
    font-weight: 500;
}

nav ul li a {
    font-weight: 500;
    letter-spacing: 0.3px;
}

.theme-toggle {
    cursor: pointer;
    padding: 0 15px;
    display: flex;
    align-items: center;
}

/* ── Page wrapper ── */
.page-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ── Search ── */
.search-wrapper .input-field input {
    border-radius: 24px !important;
    padding: 0 1.2rem 0 3rem !important;
    box-sizing: border-box;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    background-color: var(--surface-color) !important;
    box-shadow: none !important;
}

.search-wrapper .input-field input:focus {
    border: 1px solid var(--primary-color) !important;
    box-shadow: 0 0 0 1px var(--primary-color) !important;
}

/* ── Materialize overrides ── */
.card {
    background-color: var(--card-bg) !important;
    color: var(--text-primary) !important;
}

/* Override Materialize's 300px default card width everywhere except navigator */
.create-form-card,
.question-block,
.card:not(.question-navigator) {
    width: 100% !important;
}

.divider {
    background-color: var(--border-color) !important;
}

/* Materialize inputs for dark theme */
.input-field input,
.input-field textarea {
    color: var(--text-primary) !important;
    border-bottom-color: var(--border-color) !important;
    background: transparent !important;
    box-shadow: none !important;
}

.input-field input:focus,
.input-field textarea:focus {
    border-bottom-color: var(--primary-color) !important;
    box-shadow: 0 1px 0 0 var(--primary-color) !important;
}

.input-field label {
    color: var(--text-secondary) !important;
}

.input-field label.active {
    color: var(--primary-color) !important;
}

/* ── Create / Edit Layout ── */
.create-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.create-form-card {
    flex: 1;
    min-width: 0;
}

/* ── Question Blocks ── */
.question-block {
    border-radius: 8px;
    margin-bottom: 1rem;
}

.question-block .card-content {
    padding: 12px 16px !important;
}

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

.question-header .q-label {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.question-header-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.question-block.collapsed .q-body {
    display: none;
}

.collapsed-summary {
    display: none;
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 4px 0 0;
}

.question-block.collapsed .collapsed-summary {
    display: block;
}

/* ── Option Rows ── */
.option-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 0.5rem;
}

.option-row .input-field {
    flex: 1;
    margin: 0 !important;
}

.opt-correct-wrap {
    display: flex;
    align-items: center;
    margin-top: 8px;
    flex-shrink: 0;
}

.opt-correct-wrap label {
    height: auto;
    line-height: 1;
}

.opt-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    margin-top: 4px;
    flex-shrink: 0;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.15s;
    line-height: 1;
}

.opt-delete:hover { color: var(--error-color); }

/* ── Floating Footer ── */
.floating-footer {
    position: sticky;
    bottom: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    margin-top: 1rem;
}

/* ── Quiz Card ── */

.quiz-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 8px;
}

.quiz-card .card-content {
    flex: 1;
}

.quiz-card .card-title {
    font-size: 1.1rem !important;
    font-weight: 500 !important;
    color: var(--primary-color) !important;
    display: block;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.quiz-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.quiz-card .card-action {
    border-top: 1px solid var(--border-color) !important;
}

.delete-fab {
    position: absolute;
    top: 10px;
    right: 10px;
    left: auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1rem;
    padding: 0;
    z-index: 2;
}

.delete-fab:hover {
    color: var(--error-color);
    background: rgba(229, 57, 53, 0.1);
}

/* ── Question Navigator ── */
.question-navigator {
    width: 165px;
    flex-shrink: 0;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    overflow: hidden;
    background: var(--card-bg);
}

.question-navigator .nav-header {
    padding: 0.75rem 1rem;
    background: var(--primary-color);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.question-navigator .nav-header .badge {
    background: rgba(255,255,255,0.25);
    border-radius: 99px;
    padding: 1px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
}

.nav-pills-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem;
    background: var(--card-bg);
}

.nav-pills-grid::-webkit-scrollbar { width: 3px; }
.nav-pills-grid::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.q-pill {
    aspect-ratio: 1;
    border: none;
    background: var(--nav-pill-bg);
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s;
    position: relative;
    color: var(--nav-pill-text);
}

.q-pill:hover { background: var(--primary-color); color: white; }
.q-pill.active { background: var(--primary-color); color: white; }

.q-pill.answered {
    background: var(--success-color) !important;
    color: white !important;
}

.q-pill.flagged::before {
    content: "\f024";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 10px;
    color: var(--error-color);
    background: var(--card-bg);
    border-radius: 50%;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.navigator-actions {
    padding: 0.5rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.navigator-actions .btn-flat {
    height: 30px;
    line-height: 30px;
    font-size: 0.75rem;
    padding: 0 0.5rem;
    width: 100%;
    text-align: center;
    color: var(--primary-color) !important;
}

/* ── Play Options ── */
.play-option {
    display: block !important;
    padding: 0.75rem 1rem !important;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    user-select: none;
    position: relative;
}

.play-option:hover {
    background: var(--border-color);
}

.play-option [type="radio"] + span,
.play-option [type="checkbox"] + span {
    display: block !important;
    padding-left: 35px !important;
    color: var(--text-primary) !important;
    font-size: 1rem;
    line-height: 1.5;
    height: auto !important;
    min-height: 25px;
    overflow-wrap: break-word;
    word-break: break-word;
}

.play-option [type="radio"] + span:before,
.play-option [type="radio"] + span:after,
.play-option [type="checkbox"] + span:before,
.play-option [type="checkbox"] + span:after {
    top: 4px !important;
}

.play-option.correct {
    border-color: var(--success-color) !important;
    background: rgba(76, 175, 80, 0.1) !important;
}

.play-option.incorrect {
    border-color: var(--error-color) !important;
    background: rgba(244, 67, 54, 0.1) !important;
}

/* ── Common Components ── */
.grey-text { color: var(--text-secondary) !important; }
.blue-text { color: var(--primary-color) !important; }
.btn { border-radius: 4px; }
.btn.blue { background-color: var(--primary-color) !important; }
.btn.green { background-color: var(--success-color) !important; }

/* ── Mobile ── */
@media (max-width: 768px) {
    .nav-pills-grid {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        flex: 1;
        background: var(--card-bg);
    }
    .q-pill { width: 32px; height: 32px; flex-shrink: 0; aspect-ratio: unset; }
}

/* ── Score chip ── */
.score-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 16px;
    border-radius: 99px;
    font-weight: 700;
    font-size: 0.95rem;
    color: white;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    min-width: 260px;
    background: #323232;
    color: white;
    padding: 0.875rem 1.25rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateY(80px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 0.9rem;
    font-weight: 400;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success i { color: #69F0AE; font-size: 1.1rem; }
.toast.error   i { color: #FF5252; font-size: 1.1rem; }

/* ── Mobile ── */
@media (max-width: 768px) {
    /* Fix heading wrap on narrow screens */
    h4 { font-size: 1.5rem !important; }

    /* Extra bottom breathing room so buttons aren't clipped */
    main { padding-bottom: 6rem; }

    /* Offset Materialize row negative margins so cards don't hug the edge */
    #quiz-list { padding-left: 0.75rem; padding-right: 0.75rem; }

    .create-layout { flex-direction: column; }

    .question-navigator {
        width: 100%;
        position: sticky;
        top: 0;
        max-height: none;
        flex-direction: row;
        border-radius: 0;
        z-index: 50;
    }

    .question-navigator .nav-header { display: none; }

    .nav-pills-grid {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        flex: 1;
    }

    .q-pill { width: 32px; height: 32px; flex-shrink: 0; aspect-ratio: unset; }

    .navigator-actions {
        flex-direction: row;
        border-top: none;
        border-left: 1px solid #e0e0e0;
    }

    .floating-footer { flex-direction: column; }
    .floating-footer .btn { width: 100%; text-align: center; }
}
