:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --text: #1a1d26;
    --muted: #6b7280;
    --primary: #e85d04;
    --primary-dark: #c44900;
    --yes: #16a34a;
    --no: #dc2626;
    --border: #e5e7eb;
    --ok: #dcfce7;
    --fail: #fee2e2;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container { max-width: 900px; margin: 0 auto; padding: 1rem; }
.container.quiz-wide { max-width: 1200px; }
.container.admin-wide { max-width: 1100px; }

.site-header {
    background: #111827;
    color: #fff;
    margin-bottom: 1.5rem;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.logo { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }

.site-header nav { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.site-header a { color: #e5e7eb; text-decoration: none; font-size: 0.95rem; }
.site-header a:hover { color: #fff; }
.site-header .user { color: #9ca3af; font-size: 0.9rem; }

.site-footer { margin-top: 3rem; padding: 1rem 0; color: var(--muted); text-align: center; }

h1 { margin-top: 0; font-size: 1.75rem; }
.lead { color: var(--muted); }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-narrow { max-width: 420px; margin: 3rem auto; }

label { display: block; margin-bottom: 1rem; }
label input, label select, label textarea {
    display: block;
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
legend { padding: 0 0.5rem; font-weight: 600; }

.btn {
    display: inline-block;
    padding: 0.65rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 1rem;
}

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.btn-yes { background: var(--yes); border-color: var(--yes); color: #fff; min-width: 120px; }
.btn-no { background: var(--no); border-color: var(--no); color: #fff; min-width: 120px; }

.answer-buttons { display: flex; gap: 1rem; justify-content: center; margin-top: 1.5rem; }
.answer-form button { font-size: 1.2rem; padding: 1rem 2rem; }

.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-error { background: var(--fail); color: #991b1b; }
.alert-success { background: var(--ok); color: #166534; }

.stats-grid, .action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.stat-card, .action-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    text-align: center;
}

.action-card { text-decoration: none; color: inherit; transition: box-shadow 0.15s; }
.action-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); }

.stat-value { display: block; font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: 0.9rem; }

.mode-option { display: flex; gap: 0.5rem; align-items: flex-start; margin-bottom: 0.75rem; }
.mode-option input { width: auto; margin-top: 0.25rem; }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.5rem; }
.topic-chip { display: flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; }
.topic-chip input { width: auto; }

.hidden { display: none; }
.hint { font-size: 0.85rem; color: var(--muted); }

.progress-bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.2s; }
.progress-text { text-align: center; color: var(--muted); }

.question-card .question-text { font-size: 1.15rem; margin: 1rem 0; }
.question-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: #fff7ed;
    color: var(--primary-dark);
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-muted { background: #f3f4f6; color: var(--muted); }

.review-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.review-item.correct { border-left-color: var(--yes); }
.review-item.wrong { border-left-color: var(--no); }

.review-dl dt { font-weight: 600; margin-top: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.review-dl dd { margin: 0.15rem 0 0; }

.result-badge { float: right; padding: 0.2rem 0.6rem; border-radius: 6px; font-size: 0.85rem; }
.result-badge.ok { background: var(--ok); color: #166534; }
.result-badge.fail { background: var(--fail); color: #991b1b; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 0.75rem; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.95rem; }
th { background: #f9fafb; }

.filter-bar { margin-bottom: 1rem; }
.filter-bar select { min-width: 240px; }

.admin-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; align-items: end; }
.inline-form { display: inline-flex; gap: 0.35rem; align-items: center; margin: 0.25rem 0; }
.admin-actions { min-width: 280px; }

.admin-filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}

.admin-filter-form label { margin-bottom: 0; flex: 1 1 200px; }

.admin-questions-table .question-preview {
    max-width: 420px;
    line-height: 1.45;
}

.row-inactive { opacity: 0.55; }

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 1.25rem;
}

.breadcrumb { margin-bottom: 0.5rem; }
.breadcrumb a { color: var(--primary-dark); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.admin-question-form .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.admin-question-form textarea {
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.55;
    resize: vertical;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    padding-top: 1.75rem;
}

.checkbox-label input { width: auto; margin: 0; }

.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* Quiz play — main + right navigation panel */
.quiz-page { margin: 0 -0.25rem; }

.quiz-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 1.25rem;
    align-items: start;
}

.quiz-nav-panel {
    position: sticky;
    top: 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    max-height: calc(100vh - 2rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.quiz-nav-header {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.quiz-nav-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.quiz-nav-sub {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.quiz-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.quiz-nav-item { margin-bottom: 0.35rem; }

.quiz-nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    font-size: 0.88rem;
    border: 1px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}

.quiz-nav-link:hover:not(.disabled) {
    background: #f9fafb;
    border-color: var(--border);
}

.quiz-nav-link.disabled {
    opacity: 0.45;
    cursor: default;
}

.quiz-nav-num {
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #f3f4f6;
    font-weight: 700;
    font-size: 0.8rem;
}

.quiz-nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quiz-nav-result {
    margin-left: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
}

.quiz-nav-item.correct .quiz-nav-num { background: var(--ok); color: #166534; }
.quiz-nav-item.wrong .quiz-nav-num { background: var(--fail); color: #991b1b; }
.quiz-nav-item.correct .quiz-nav-result { color: #166534; }
.quiz-nav-item.wrong .quiz-nav-result { color: #991b1b; }
.quiz-nav-item.active .quiz-nav-link {
    background: #fff7ed;
    border-color: #fed7aa;
}
.quiz-nav-item.active .quiz-nav-num {
    background: var(--primary);
    color: #fff;
}
.quiz-nav-item.current .quiz-nav-num {
    background: #dbeafe;
    color: #1d4ed8;
}
.quiz-nav-item.current .quiz-nav-result { color: #1d4ed8; }

.review-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    background: #f0f9ff;
    border-color: #bae6fd;
}

.review-banner p { margin: 0; font-size: 0.95rem; }

.question-card.review-correct { border-left: 4px solid var(--yes); }
.question-card.review-wrong { border-left: 4px solid var(--no); }

@media (max-width: 900px) {
    .quiz-layout {
        grid-template-columns: 1fr;
    }

    .quiz-nav-panel {
        position: static;
        max-height: none;
        order: -1;
    }

    .quiz-nav-list {
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
        overflow: visible;
    }

    .quiz-nav-item {
        margin: 0;
        flex: 0 0 auto;
    }

    .quiz-nav-link {
        flex-direction: column;
        gap: 0.2rem;
        padding: 0.4rem 0.5rem;
        min-width: 3.25rem;
        text-align: center;
    }

    .quiz-nav-label {
        display: none;
    }
}

@media (max-width: 600px) {
    .answer-buttons { flex-direction: column; }
    .btn-yes, .btn-no { width: 100%; }
}
