:root {
    color-scheme: light dark;
    --bg: #f8f9fb;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --subtext: #555555;
    --border: #e0e0e0;
    --accent: #2f7dff;
    --accent-soft: rgba(47, 125, 255, 0.12);
    --danger: #e74c3c;
    --success: #27ae60;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

:root.dark {
    --bg: #121417;
    --card-bg: #1f2329;
    --text: #f1f5f9;
    --subtext: #cbd5f5;
    --border: #2b3037;
    --accent: #6d9bff;
    --accent-soft: rgba(109, 155, 255, 0.16);
    --danger: #ff6b6b;
    --success: #4cd964;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem clamp(1rem, 5vw, 3rem);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.branding h1 {
    font-size: clamp(1.25rem, 2vw + 0.8rem, 2rem);
    margin: 0;
}

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

.icon-button {
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: grid;
    place-items: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.icon-button:hover,
.icon-button:focus {
    background: var(--accent-soft);
    outline: none;
    transform: translateY(-1px);
}

.progress-container {
    height: 6px;
    background: var(--border);
    margin: 0 clamp(1rem, 5vw, 3rem);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #6ee7b7);
    width: 0%;
    transition: width 0.3s ease;
}

.app {
    flex: 1;
    padding: clamp(1rem, 4vw, 3rem);
    display: flex;
    justify-content: center;
}

.card {
    width: min(960px, 100%);
    background: var(--card-bg);
    border-radius: 1.25rem;
    padding: clamp(1.5rem, 5vw, 3rem);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card h2 {
    margin: 0;
}

.text-muted {
    color: var(--subtext);
    line-height: 1.6;
}

.menu-grid {
    display: grid;
    gap: 1.5rem;
}

.mode-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mode-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.mode-card h3 {
    margin: 0;
}

.mode-card p {
    margin: 0;
    color: var(--subtext);
    line-height: 1.6;
}

.custom-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.form-row label {
    flex: 1 1 180px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-weight: 600;
}

.form-row input {
    padding: 0.6rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
}

.form-row input:focus {
    outline: 2px solid var(--accent);
}

.primary-button,
.secondary-button,
.ghost-button {
    cursor: pointer;
    border-radius: 0.75rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.primary-button {
    background: var(--accent);
    color: #fff;
    box-shadow: var(--shadow);
}

.primary-button:hover,
.primary-button:focus {
    transform: translateY(-1px);
}

.controls button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.secondary-button {
    background: var(--accent-soft);
    color: var(--accent);
}

.ghost-button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.controls .spacer {
    flex: 1 1 auto;
}

.question-meta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.session-badge {
    align-self: flex-start;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.session-subtext {
    color: var(--subtext);
    font-size: 0.9rem;
}

.question-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 1rem;
    align-items: baseline;
}

.question-info span {
    color: var(--subtext);
}

.question-progress {
    color: var(--subtext);
    font-size: 0.95rem;
}

.question-title {
    font-size: clamp(1.1rem, 1vw + 1rem, 1.4rem);
    line-height: 1.7;
    white-space: pre-wrap;
}

.question-image {
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    background: #fff;
}

.options {
    display: grid;
    gap: 0.75rem;
}

.option-button {
    text-align: left;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, border 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.option-button strong {
    font-size: 1.1rem;
    min-width: 2rem;
}

.option-button span {
    flex: 1;
}

.option-button:hover,
.option-button:focus {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    outline: none;
}

.option-button.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.option-button.correct {
    border-color: var(--success);
    background: rgba(39, 174, 96, 0.12);
}

.option-button.incorrect {
    border-color: var(--danger);
    background: rgba(231, 76, 60, 0.12);
}

.feedback {
    border-radius: 1rem;
    padding: 1rem;
    background: var(--accent-soft);
    color: var(--accent);
}

.feedback.correct {
    background: rgba(39, 174, 96, 0.12);
    color: var(--success);
}

.feedback.incorrect {
    background: rgba(231, 76, 60, 0.12);
    color: var(--danger);
}

.explanation {
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--border);
    padding: 1rem;
    line-height: 1.6;
}

.ps-note {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 0.75rem;
    padding: 0.75rem;
}

.status-panel {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 1.5rem;
    transition: opacity 0.2s ease;
}

.status-panel.hidden {
    opacity: 0;
    pointer-events: none;
}

.status-panel__content {
    width: min(720px, 100%);
    background: var(--card-bg);
    border-radius: 1.25rem;
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.status-panel__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-panel__legend {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.legend-item {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
}

.legend-answered {
    background: rgba(39, 174, 96, 0.12);
    color: var(--success);
}

.legend-unanswered {
    background: rgba(231, 76, 60, 0.12);
    color: var(--danger);
}

.legend-bookmarked {
    background: var(--accent-soft);
    color: var(--accent);
}

.status-panel__list {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    overflow-y: auto;
    padding-right: 0.25rem;
}

.status-item {
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border 0.15s ease;
    text-align: center;
}

.status-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.status-item.current {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.status-item.answered {
    background: rgba(39, 174, 96, 0.12);
    border-color: var(--success);
}

.status-item.bookmarked {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.status-item .status-label {
    font-size: 0.9rem;
    color: var(--subtext);
}

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

.jump-input input {
    width: 80px;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
}

.jump-input input:focus {
    outline: 2px solid var(--accent);
}

.result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.result-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.result-card {
    background: var(--card-bg);
    border-radius: 1.5rem;
    padding: 2rem;
    width: min(520px, 100%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.result-summary {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.result-box {
    border-radius: 1rem;
    padding: 1rem;
    background: var(--accent-soft);
    color: var(--accent);
    text-align: center;
}

.result-box strong {
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

@media (max-width: 768px) {
    .card {
        padding: 1.25rem;
        border-radius: 1rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .jump-input {
        width: 100%;
    }

    .jump-input input {
        flex: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
