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

:root {
    --primary: #0080CC;
    --primary-dark: #006699;
    --primary-light: #E6F4FB;
    --accent: #00AEEF;
    --bg: #FFFFFF;
    --bg-gray: #F4F6F8;
    --bg-card: #FFFFFF;
    --text: #1A2332;
    --text-secondary: #4A6070;
    --text-muted: #8FA3B0;
    --border: #DDE4EA;
    --success: #2E9E4F;
    --success-bg: #EBF7EE;
    --danger: #D9534F;
    --danger-bg: #FBEAEA;
    --returns-color: #F0B429; /* 70s マスタードゴールド */
}

.returns-word {
    color: var(--returns-color);
    display: inline-block;
}

/* === 入場演出（CSSのみ＝JS非依存。最初から隠すので“舞台裏”が見えず、JS不調でも必ず表示される） === */

/* 「リターンズ」を 0.6秒後から 1.4秒かけてじわじわ表示 */
.returns-word.returns-intro {
    opacity: 0;
    transform: scale(0.97);
    transform-origin: center bottom;
    animation: returnsIntro 1.4s ease 0.6s forwards;
}
@keyframes returnsIntro {
    to { opacity: 1; transform: none; }
}

/* 本文（遊び方以下）は最初からCSSで隠し、リターンズが出切る頃(2秒)にフェードイン。
   名前入力欄(#name-field)は最初からdisplay:noneで採点モード選択時に出すため対象外。 */
.start-card > *:not(#start-title):not(#name-field) {
    opacity: 0;
    transform: translateY(12px);
    animation: bodyIntro 0.7s ease 2s forwards;
}
@keyframes bodyIntro {
    to { opacity: 1; transform: none; }
}

/* モーション軽減設定では動き(scale/slide)を消し、フェードのみにする */
@media (prefers-reduced-motion: reduce) {
    .returns-word.returns-intro { transform: none; }
    .start-card > *:not(#start-title):not(#name-field) { transform: none; }
}

.name-hint {
    margin-top: 8px;
    font-size: 0.82em;
    color: var(--text-muted);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-gray);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    color: var(--text);
}

#app {
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Screen Base */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    flex-direction: column;
    background: var(--bg-gray);
}

.screen.active {
    display: flex;
}

/* =====================
   SHARED HEADER
   ===================== */

.header {
    background: var(--primary);
    padding: 0 40px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.matrix-page-header {
    background: var(--primary);
    padding: 28px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.matrix-page-header h1 {
    font-size: clamp(1.6em, 4.5vw, 3.6em);
    font-weight: 700;
    color: white;
    letter-spacing: -0.5px;
    line-height: 1.15;
    width: 100%;
    text-align: center;
}

.matrix-page-header h1 .accent {
    color: #A8DEFF;
}

/* =====================
   START SCREEN
   ===================== */

#start-screen {
    background: var(--bg-gray);
}

.start-scroll {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
}

.start-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    padding: 36px 40px;
    max-width: 640px;
    width: 100%;
}

@media (min-width: 769px) {
    .start-card {
        max-width: 860px;
    }
    .start-title {
        white-space: nowrap;
    }
}

.start-title {
    font-size: clamp(1.5em, 4vw, 2.4em);
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    line-height: 1.25;
    margin-bottom: 28px;
}

.start-block {
    margin-bottom: 24px;
}

.start-h2 {
    font-size: 0.78em;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 12px;
}

.instructions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.instructions-list li {
    position: relative;
    padding-left: 22px;
    line-height: 1.6;
    color: var(--text);
}

.instructions-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--primary);
    font-weight: 700;
}

kbd {
    background: var(--bg-gray);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 0.85em;
    font-family: inherit;
}

.mode-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 10px;
    transition: all 0.15s ease;
}

.mode-option:hover {
    border-color: var(--accent);
    background: var(--primary-light);
}

.mode-option input {
    margin-top: 4px;
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.mode-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.mode-text strong {
    font-size: 1.05em;
    color: var(--text);
}

.mode-text small {
    color: var(--text-secondary);
    line-height: 1.5;
}

.name-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.05em;
    font-family: inherit;
    color: var(--text);
}

.name-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.btn-large {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.15em;
    margin-top: 8px;
}

/* =====================
   MATRIX SCREEN
   ===================== */

#matrix-screen .container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-gray);
    overflow: hidden;
}

.score-bar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 10px 36px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.score-bar-name {
    font-weight: 700;
    color: var(--text);
}

.score-bar-progress {
    color: var(--text-secondary);
    font-size: 0.95em;
}

.score-bar-score {
    color: var(--primary);
    font-size: 1.25em;
    font-weight: 800;
}

.btn-grade {
    margin-left: auto;
    background: var(--success);
    color: white;
    border: none;
    padding: 10px 26px;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 2px 8px rgba(46, 158, 79, 0.3);
}

.btn-grade:hover:not(:disabled) {
    background: #268043;
    transform: translateY(-1px);
}

.btn-grade:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

.matrix-grid {
    flex: 1;
    padding: 24px 36px;
    overflow: auto;
}

table {
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 6px;
    width: 100%;
}

table th,
table td {
    width: 100px;
    height: 80px;
    padding: 3px;
}

table th:first-child,
table td:first-child {
    width: 88px;
    padding-right: 8px;
}

table th {
    color: var(--text-secondary) !important;
    font-size: 1.05em !important;
    font-weight: 700 !important;
    text-align: center !important;
    vertical-align: bottom !important;
    padding-bottom: 10px !important;
    background: transparent !important;
    border: none !important;
    line-height: 1.3;
    letter-spacing: 0.2px;
}

table td:first-child {
    color: var(--text-secondary) !important;
    font-size: 1.05em !important;
    font-weight: 700 !important;
    text-align: right !important;
    background: transparent !important;
    border: none !important;
    letter-spacing: 0.3px;
}

/* Quiz cells */
.quiz-cell {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25em;
    font-weight: 700;
    color: white;
    transition: all 0.15s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    letter-spacing: 0.3px;
}

.quiz-cell:hover {
    background: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 128, 204, 0.35);
}

/* answered (graded, before scoring) */
.quiz-cell.answered {
    background: var(--primary-dark);
}

.quiz-cell.answered:hover {
    background: var(--accent);
}

.quiz-cell.answered .cell-mark {
    font-size: 1.1rem;
}

/* correct / incorrect (after reveal) */
.quiz-cell.correct {
    background: var(--success);
}

.quiz-cell.correct:hover {
    background: #36b25a;
}

.quiz-cell.incorrect {
    background: var(--danger);
}

.quiz-cell.incorrect:hover {
    background: #e0635f;
}

.quiz-cell .cell-mark {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
}

.quiz-cell .reset-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: rgba(255, 255, 255, 0.92);
    color: var(--danger);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.12s ease;
}

.quiz-cell .reset-btn:hover {
    background: var(--danger);
    color: white;
    transform: scale(1.1);
}

/* Restart button (subtle, bottom-right) */
.reset-all-btn {
    position: absolute;
    bottom: 10px;
    right: 14px;
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    z-index: 10;
}

.reset-all-btn:hover {
    opacity: 1;
    background: var(--bg-card);
    color: var(--danger);
    border-color: var(--danger);
}

/* =====================
   PROBLEM & ANSWER SCREENS
   ===================== */

#problem-screen .container,
#answer-screen .container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-gray);
    overflow: hidden;
}

.btn-back {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 8px 18px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.25);
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    align-self: center;
    box-sizing: border-box;
}

/* =====================
   PROBLEM SCREEN
   ===================== */

#problem-screen .content {
    max-width: none;
    width: 100%;
    padding: 20px 5vw;
    overflow-x: hidden;
}

.problem-layout {
    display: flex;
    flex-direction: column;
}

.problem-layout:not(.has-image) {
    align-items: center;
}

.problem-layout:not(.has-image) #problem-title,
.problem-layout:not(.has-image) .problem-content {
    width: 35vw;
    min-width: 320px;
}

.problem-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.problem-layout.has-image {
    display: grid;
    grid-template-columns: 55fr 35fr;
    grid-template-rows: auto 1fr;
    column-gap: 28px;
    row-gap: 8px;
}

.problem-layout.has-image #problem-title {
    grid-column: 1;
    grid-row: 1;
    text-align: left;
}

.problem-layout.has-image #problem-images {
    grid-column: 1;
    grid-row: 2;
    margin: 0;
    align-items: flex-start;
    justify-content: flex-start;
    min-width: 0;
}

.problem-layout.has-image #problem-images img {
    max-width: 100%;
    max-height: 78vh;
    width: 100%;
    object-fit: contain;
    border: none;
    box-shadow: none;
    border-radius: 0;
}

.problem-layout.has-image .problem-content {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
}

.problem-layout.has-image.portrait-image {
    grid-template-areas:
        ". title"
        "img text";
    grid-template-columns: auto 35vw;
    grid-template-rows: auto auto;
    column-gap: 5vw;
    justify-content: center;
}

.problem-layout.has-image.portrait-image #problem-title {
    grid-area: title;
}

.problem-layout.has-image.portrait-image #problem-images {
    grid-area: img;
}

.problem-layout.has-image.portrait-image #problem-images img {
    max-height: calc((100vh - 60px) * 0.95);
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.problem-layout.has-image.portrait-image .problem-content {
    grid-area: text;
    width: 35vw;
}

#problem-title {
    font-size: 2.4em;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
    letter-spacing: -0.3px;
}

.problem-text {
    font-size: 1.1em;
    line-height: 1.75;
    color: var(--text);
    background: var(--bg-card);
    padding: 24px 28px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 24px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.problem-hint {
    font-size: 0.88em;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-align: center;
}

.problem-options {
    list-style: none;
    margin: 0 0 28px 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-item {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    padding: 16px 22px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 6px;
    font-size: 1.05em;
    line-height: 1.6;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.option-clickable {
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.option-clickable:hover {
    background: var(--primary-light);
    border-left-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 128, 204, 0.18);
}

.option-clickable:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 128, 204, 0.25);
}

.option-clickable:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* graded: 現在の選択をハイライト */
.option-item.selected {
    background: var(--primary-light);
    border-left-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent) inset;
}

.option-item.selected .option-label::after {
    content: ' ✓';
    color: var(--primary);
}

.option-label {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.35em;
    min-width: 32px;
    line-height: 1.3;
}

.option-text {
    color: var(--text);
    flex: 1;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 13px 34px;
    border-radius: 4px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.15s;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 8px rgba(0, 128, 204, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 14px rgba(0, 128, 204, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 13px 28px;
    border-radius: 4px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.15s;
}

.btn-secondary:hover {
    background: var(--bg-gray);
    color: var(--text);
}

/* =====================
   ANSWER / REVIEW SCREEN
   ===================== */

#answer-screen .content {
    max-width: 60vw;
    width: 60vw;
}

.answer-quiz-title {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 16px;
}

.review-problem-section,
.answer-section,
.explanation-section {
    margin-bottom: 16px;
    padding: 24px 28px;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.review-problem-section h2 {
    font-size: 0.7em;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 14px;
}

.review-options {
    list-style: none;
    margin: 16px 0 0 0;
    padding: 0;
}

.review-options li {
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.95em;
    background: var(--bg-main);
}

.review-options li.review-correct {
    border-color: var(--success);
    background: color-mix(in srgb, var(--success) 12%, transparent);
    font-weight: 700;
}

.review-options li.review-user-answer:not(.review-correct) {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.answer-section h2,
.explanation-section h2 {
    font-size: 0.7em;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 14px;
}

.answer-message {
    font-weight: 700;
    padding: 18px 22px;
    border-radius: 6px;
    line-height: 1.6;
}

.answer-message.correct {
    color: var(--success);
    background: var(--success-bg);
    border-left: 4px solid var(--success);
}

.answer-message.incorrect {
    color: #C92A2A;
    background: var(--danger-bg);
    border-left: 4px solid var(--danger);
}

.answer-message .result-headline {
    font-size: 1.8em;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.answer-message .result-detail {
    font-size: 0.95em;
    font-weight: 600;
    margin-top: 6px;
    color: var(--text);
}

.answer-message .your-answer {
    color: var(--text-secondary);
}

.answer-message .correct-answer {
    color: var(--text);
}

.explanation-text {
    font-size: 1.05em;
    line-height: 1.85;
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* =====================
   RESULT SCREEN
   ===================== */

#result-screen .container {
    width: 100%;
    height: 100%;
    display: flex;
    background: var(--bg-gray);
}

.result-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.1);
    padding: 48px 56px;
    text-align: center;
    max-width: 520px;
    width: 100%;
}

.result-score-label {
    font-size: 0.78em;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 18px;
}

.result-name {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.result-score {
    font-size: 4em;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
    margin: 8px 0;
}

.result-score .unit {
    font-size: 0.35em;
    color: var(--text-secondary);
    margin-left: 4px;
}

.result-sub {
    color: var(--text-secondary);
    font-size: 1.05em;
    margin-bottom: 28px;
}

.result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* =====================
   IMAGE NAVIGATION
   ===================== */

.images-container {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.images-container img {
    max-width: 100%;
    max-height: 320px;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.image-nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.image-nav button {
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.15s;
}

.image-nav button:hover {
    background: var(--primary);
    color: white;
}

.image-nav button:disabled {
    border-color: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
}

.image-counter {
    font-size: 0.85em;
    color: var(--text-muted);
}

/* =====================
   LARGE SCREEN (1920px+)
   ===================== */

@media (min-width: 1920px) {
    .header { height: 72px; }
    .matrix-page-header { padding: 40px 24px; }
    table th, table td { width: 130px; height: 100px; }
    table th { font-size: 1.4em !important; }
    table td:first-child { font-size: 1.4em !important; }
    .quiz-cell { font-size: 1.6em; }
    .quiz-cell .cell-mark { font-size: 2rem; }
    #problem-title { font-size: 3.4em; }
    .problem-text { font-size: 1.35em; }
    .option-item { font-size: 1.3em; padding: 20px 28px; }
    .option-label { font-size: 1.5em; min-width: 44px; }
    .answer-message .result-headline { font-size: 2.4em; }
    .answer-message .result-detail { font-size: 1.15em; }
    .images-container img { max-height: 500px; }
    .btn-primary { padding: 16px 44px; font-size: 1.1em; }
}

/* =====================
   RESPONSIVE
   ===================== */

@media (max-width: 1024px) {
    .matrix-grid { padding: 16px 20px; }
    table th, table td { width: 82px; height: 68px; }
    .quiz-cell { font-size: 1.05em; }

    /* 狭い画面では問題レイアウトを縦1列に積む（画像とテキストの重なり防止） */
    .problem-layout:not(.has-image) #problem-title,
    .problem-layout:not(.has-image) .problem-content { width: 100%; min-width: 0; }
    .problem-layout.has-image,
    .problem-layout.has-image.portrait-image {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas: none;
    }
    .problem-layout.has-image #problem-title,
    .problem-layout.has-image.portrait-image #problem-title {
        grid-area: unset;
        grid-column: 1;
        grid-row: 1;
    }
    .problem-layout.has-image #problem-images,
    .problem-layout.has-image.portrait-image #problem-images {
        grid-area: unset;
        grid-column: 1;
        grid-row: 2;
    }
    .problem-layout.has-image #problem-images img,
    .problem-layout.has-image.portrait-image #problem-images img {
        height: auto;
        width: 100%;
        max-width: 100%;
        max-height: 60vh;
        object-fit: contain;
    }
    .problem-layout.has-image .problem-content,
    .problem-layout.has-image.portrait-image .problem-content {
        grid-area: unset;
        grid-column: 1;
        grid-row: 3;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .matrix-page-header, .header { padding: 0 20px; }
    .matrix-page-header { padding: 20px; }
    .header { padding: 0 20px; }
    .content { padding: 20px; }
    .score-bar { padding: 10px 20px; }
    .start-card { padding: 24px 20px; }
    #answer-screen .content { max-width: 100%; width: 100%; }
    .images-container img { max-height: 200px; }
    .result-card { padding: 32px 24px; }
    .result-score { font-size: 3em; }
}

/* =====================
   SCROLLBAR
   ===================== */

.content::-webkit-scrollbar,
.matrix-grid::-webkit-scrollbar,
.start-scroll::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

.content::-webkit-scrollbar-track,
.matrix-grid::-webkit-scrollbar-track,
.start-scroll::-webkit-scrollbar-track {
    background: var(--bg-gray);
}

.content::-webkit-scrollbar-thumb,
.matrix-grid::-webkit-scrollbar-thumb,
.start-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.content::-webkit-scrollbar-thumb:hover,
.matrix-grid::-webkit-scrollbar-thumb:hover,
.start-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* =====================
   LIGHTBOX
   ===================== */

.zoomable { cursor: zoom-in; }

#lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 24px;
    cursor: zoom-out;
}

#lightbox-img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    object-fit: contain;
    cursor: default;
}

#lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}
