:root {
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #d7dde6;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --brand: #12645f;
    --brand-dark: #0d4d49;
    --danger: #b42318;
    --warn: #9a6700;
    --ok: #137333;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 22px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 700; color: var(--ink); }
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; }
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.narrow { max-width: 540px; }
.panel, .card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 16px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 14px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
label { display: block; font-weight: 700; margin: 12px 0 6px; }
input, textarea, select {
    width: 100%;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
}
textarea { min-height: 94px; resize: vertical; }
.inline-input { width: auto; min-width: 180px; }
.btn, button {
    border: 0;
    border-radius: 6px;
    padding: 10px 14px;
    background: var(--brand);
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
    display: inline-block;
}
.btn:hover, button:hover { background: var(--brand-dark); text-decoration: none; }
.btn.secondary, button.secondary { background: #4b5563; }
.btn.danger, button.danger { background: var(--danger); }
.btn.light, button.light { background: #eef2f7; color: var(--ink); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: #ffffff; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 10px; vertical-align: top; }
th { background: #eef2f7; font-size: 14px; }
.flash { border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--line); background: #ffffff; }
.flash.ok { border-color: #b7dfc4; color: var(--ok); }
.flash.err { border-color: #f1b8b5; color: var(--danger); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; background: #eef2f7; font-size: 12px; font-weight: 700; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.qr { width: 260px; height: 260px; image-rendering: pixelated; border: 1px solid var(--line); background: #fff; }
.question-shell { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 16px; }
.question-head { align-items: flex-start; }
.timebox {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    padding: 8px 10px;
    font-weight: 700;
    white-space: nowrap;
}
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.palette a {
    text-align: center;
    min-height: 38px;
    padding: 8px 0;
    border-radius: 6px;
    background: #eef2f7;
    color: var(--ink);
    font-weight: 700;
}
.palette a.current { outline: 3px solid var(--brand); }
.palette a.answered { background: #dcfce7; }
.palette a.marked { background: #fef3c7; }
.palette a.skipped { background: #fee2e2; }
.option {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    margin: 10px 0;
    font-weight: 400;
}
.option input { width: auto; margin-right: 8px; }
.option-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 28px;
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #eef2f7;
    font-weight: 800;
}
.autosave-status { min-height: 22px; font-size: 14px; }
.autosave-status.saving { color: var(--warn); }
.autosave-status.saved { color: var(--ok); }
.autosave-status.error { color: var(--danger); }
.correct { border-color: #86efac; background: #f0fdf4; }
.wrong { border-color: #fca5a5; background: #fff1f2; }
.timer { font-weight: 800; font-size: 20px; color: var(--danger); }
.print-only { display: none; }
@media (max-width: 800px) {
    body { padding-bottom: 92px; }
    .container { margin: 12px auto; padding: 0 10px; }
    .question-shell { grid-template-columns: 1fr; gap: 10px; }
    .question-panel, .palette-panel { padding: 12px; }
    .palette-panel { order: -1; }
    .palette-panel h2 { font-size: 16px; margin-bottom: 8px; }
    .palette { grid-template-columns: repeat(8, minmax(34px, 1fr)); gap: 6px; }
    .palette a { min-height: 38px; padding: 7px 0; font-size: 14px; }
    .question-head {
        position: sticky;
        top: 0;
        z-index: 6;
        margin: -12px -12px 12px;
        padding: 10px 12px;
        background: #ffffff;
        border-bottom: 1px solid var(--line);
    }
    .question-head h1 { font-size: 20px; margin: 0; }
    .timebox { padding: 6px 8px; font-size: 13px; }
    .timer { font-size: 18px; }
    .option { min-height: 52px; padding: 13px 10px; }
    .option input { transform: scale(1.2); margin-top: 5px; }
    .action-row {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        margin: 0;
        padding: 10px;
        background: #ffffff;
        border-top: 1px solid var(--line);
        box-shadow: 0 -6px 16px rgba(31, 41, 55, 0.12);
    }
    .action-row button { width: 100%; padding: 12px 8px; min-height: 46px; }
    .topbar { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 430px) {
    .palette { grid-template-columns: repeat(6, minmax(34px, 1fr)); }
    .action-row { grid-template-columns: repeat(2, 1fr); }
}
@media print {
    .topbar, .no-print, .btn, button { display: none !important; }
    body { background: #fff; }
    .container { margin: 0; max-width: none; }
    .panel, .card { border: 0; page-break-inside: avoid; }
    .print-only { display: block; }
}
