:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --text: #172321;
  --muted: #60706d;
  --line: #d9e3e1;
  --brand: #0f665a;
  --brand-dark: #08483f;
  --brand-soft: #dff1ed;
  --danger: #a52d35;
  --danger-soft: #fbe8e9;
  --warning: #9a6200;
  --warning-soft: #fff3d8;
  --shadow: 0 18px 50px rgba(22, 52, 47, 0.09);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at top left, #e4f1ef 0, transparent 35rem), var(--bg); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(15, 102, 90, 0.28); outline-offset: 2px; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.site-header { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 5vw; border-bottom: 1px solid rgba(217, 227, 225, 0.8); background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 20; }
.brand { display: inline-flex; align-items: center; gap: 0.75rem; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; color: white; background: linear-gradient(145deg, var(--brand), var(--brand-dark)); font-weight: 800; font-size: 1.25rem; box-shadow: 0 8px 24px rgba(15, 102, 90, 0.23); }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: 0.08em; }
.brand small { margin-top: 0.1rem; color: var(--muted); }
.quiet-link { color: var(--muted); text-decoration: none; font-weight: 650; }
.quiet-link:hover { color: var(--brand); }

.shell { width: min(1120px, calc(100% - 2rem)); margin: 3.5rem auto 5rem; }
.shell.narrow { width: min(760px, calc(100% - 2rem)); }
.panel { background: rgba(255, 255, 255, 0.96); border: 1px solid rgba(217, 227, 225, 0.9); border-radius: var(--radius); box-shadow: var(--shadow); }
.hero { width: min(700px, 100%); margin: 4vh auto; padding: clamp(1.5rem, 5vw, 3.5rem); }
.eyebrow { margin-bottom: 0.55rem; color: var(--brand); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
h1, h2, h3 { margin-top: 0; line-height: 1.16; letter-spacing: -0.025em; }
h1 { margin-bottom: 0.8rem; font-size: clamp(2rem, 5vw, 3.15rem); }
h2 { font-size: clamp(1.35rem, 3vw, 2rem); }
.lead { margin: 0 0 1.75rem; color: var(--muted); font-size: 1.08rem; line-height: 1.65; }

.exam-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; margin: 1.5rem 0 2rem; }
.exam-facts div { min-width: 0; padding: 0.9rem; border-radius: 13px; background: var(--surface-soft); }
.exam-facts span, .exam-facts strong { display: block; }
.exam-facts span { color: var(--muted); font-size: 0.78rem; }
.exam-facts strong { margin-top: 0.25rem; overflow-wrap: anywhere; }
.countdown-card { margin-top: 0.25rem; padding: 1rem; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(145deg, var(--surface-soft), white); overflow: hidden; }
.countdown-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.countdown-heading > span { color: var(--muted); font-size: 0.75rem; font-weight: 750; }
.countdown-units { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.55rem; }
.countdown-units div { padding: 0.7rem 0.45rem; text-align: center; border-radius: 12px; background: white; border: 1px solid rgba(217, 227, 225, 0.85); }
.countdown-units strong, .countdown-units span { display: block; }
.countdown-units strong { font-size: clamp(1.35rem, 4vw, 2rem); font-variant-numeric: tabular-nums; letter-spacing: -0.04em; }
.countdown-units span { margin-top: 0.15rem; color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; }
.countdown-progress, .timer-progress { height: 6px; overflow: hidden; margin-top: 0.85rem; border-radius: 999px; background: rgba(15, 102, 90, 0.1); }
.countdown-progress span, .timer-progress span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--brand); transition: width 500ms linear; }
.countdown-card.urgent { border-color: #eed89e; background: var(--warning-soft); }
.countdown-card.urgent .countdown-progress span { background: var(--warning); }
.countdown-card.finished { opacity: 0.72; }
.stack { display: grid; gap: 1.15rem; }
label > span, .answer-label { display: block; margin-bottom: 0.45rem; font-weight: 720; }
label small { color: var(--muted); font-weight: 500; }
input, select, textarea { width: 100%; color: var(--text); border: 1px solid var(--line); border-radius: 12px; background: white; transition: border-color 150ms, box-shadow 150ms; }
input, select { min-height: 50px; padding: 0 0.95rem; }
textarea { resize: vertical; min-height: 260px; padding: 1rem; line-height: 1.65; }
input:hover, select:hover, textarea:hover { border-color: #afc3bf; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(15, 102, 90, 0.09); outline: none; }
textarea:disabled { background: #edf1f0; }

button { min-height: 46px; padding: 0.75rem 1.15rem; border: 0; border-radius: 12px; cursor: pointer; font-weight: 750; transition: transform 120ms, box-shadow 120ms, background 120ms; }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { color: white; background: var(--brand); box-shadow: 0 8px 22px rgba(15, 102, 90, 0.18); }
.primary:hover:not(:disabled) { background: var(--brand-dark); }
.secondary { color: var(--text); border: 1px solid var(--line); background: white; }
.secondary:hover:not(:disabled) { background: var(--surface-soft); }
.danger { color: white; background: var(--danger); }
.form-error { min-height: 1.2rem; margin: 0; color: var(--danger); font-weight: 650; }

.exam-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: 1.5rem 1.75rem; margin-bottom: 1rem; }
.exam-toolbar h1 { margin-bottom: 0; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.timer-card { flex: 0 0 auto; min-width: 165px; padding: 0.8rem 1rem; border-radius: 14px; text-align: right; background: var(--brand-soft); }
.timer-card span, .timer-card strong { display: block; }
.timer-card span { color: var(--brand-dark); font-size: 0.78rem; font-weight: 700; }
.timer-card strong { margin-top: 0.2rem; font-size: 1.55rem; font-variant-numeric: tabular-nums; }
.timer-card .timer-progress { margin-top: 0.55rem; background: rgba(8, 72, 63, 0.12); }
.timer-card.urgent { color: var(--danger); background: var(--danger-soft); }
.timer-card.urgent .timer-progress span { background: var(--danger); }
.timer-card.finished { opacity: 0.7; }
.status-banner { margin: 0 0 1rem; padding: 0.9rem 1.1rem; border-radius: 12px; font-weight: 650; }
.status-banner.offline { color: #6e4900; background: var(--warning-soft); border: 1px solid #eed89e; }
.status-banner.error { color: var(--danger); background: var(--danger-soft); border: 1px solid #efc5c8; }
#waiting-panel { padding: 2rem; text-align: center; }

.progress-panel { margin-bottom: 1rem; padding: 1rem 1.2rem; }
.progress-copy { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 0.7rem; font-weight: 700; }
.save-state { color: var(--muted); font-size: 0.9rem; }
.save-state[data-status="saved"] { color: var(--brand); }
.save-state[data-status="warning"] { color: var(--warning); }
.save-state[data-status="error"] { color: var(--danger); }
.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
#progress-fill { width: 0; height: 100%; border-radius: inherit; background: var(--brand); transition: width 180ms ease; }
.question-card { padding: clamp(1.4rem, 4vw, 2.5rem); }
.question-number { margin-bottom: 0.7rem; color: var(--brand); font-weight: 800; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.1em; }
.question-card h2 { max-width: 850px; margin-bottom: 2rem; }
.answer-meta { display: flex; justify-content: space-between; gap: 1rem; margin-top: 0.6rem; color: var(--muted); font-size: 0.84rem; }
.exam-actions, .review-actions { display: flex; justify-content: space-between; gap: 0.8rem; margin-top: 1rem; }

#review-view .panel { padding: clamp(1.4rem, 4vw, 2.8rem); }
.review-list { display: grid; gap: 0.8rem; margin: 2rem 0; }
.review-item { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 1rem; width: 100%; text-align: left; border: 1px solid var(--line); background: white; }
.review-item p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-weight: 450; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-item .complete { color: var(--brand); }
.review-item .missing { color: var(--danger); }
.receipt { width: min(680px, 100%); margin: 5vh auto; padding: 3rem; text-align: center; }
.receipt-icon { display: grid; place-items: center; width: 68px; height: 68px; margin: 0 auto 1.5rem; border-radius: 50%; color: white; background: var(--brand); font-size: 2rem; font-weight: 800; }
.receipt dl { display: grid; grid-template-columns: auto 1fr; gap: 0.75rem 1.5rem; margin: 2rem auto 0; padding: 1.2rem; max-width: 520px; text-align: left; border-radius: 13px; background: var(--surface-soft); }
.receipt dt { color: var(--muted); }
.receipt dd { margin: 0; overflow-wrap: anywhere; font-weight: 700; }
.site-footer { padding: 2rem 1rem 3rem; color: var(--muted); text-align: center; font-size: 0.85rem; }

/* Admin */
.admin-shell { width: min(1280px, calc(100% - 2rem)); margin: 2rem auto 5rem; }
.admin-login { width: min(520px, 100%); margin: 8vh auto; padding: 2.5rem; }
.admin-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; }
.admin-header h1 { margin-bottom: 0.2rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem; }
.toolbar label { flex: 1 1 160px; }
.toolbar button { flex: 0 0 auto; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin: 1rem 0; }
.metric { padding: 1.25rem; }
.metric span, .metric strong { display: block; }
.metric span { color: var(--muted); font-size: 0.84rem; }
.metric strong { margin-top: 0.35rem; font-size: 2rem; }
.admin-panel { padding: 1.25rem; margin-top: 1rem; }
.table-wrap { overflow-x: auto; margin-top: 1rem; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--surface-soft); font-size: 0.78rem; letter-spacing: 0.03em; text-transform: uppercase; }
.sort-button { min-height: auto; padding: 0; color: inherit; background: transparent; border-radius: 4px; text-transform: inherit; letter-spacing: inherit; }
.sort-button:hover:not(:disabled) { color: var(--brand); transform: none; }
tbody tr:hover { background: #f8fbfa; }
tbody tr:last-child td { border-bottom: 0; }
.status-pill { display: inline-flex; align-items: center; padding: 0.25rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 750; }
.status-pill.submitted { color: var(--brand-dark); background: var(--brand-soft); }
.status-pill.in_progress { color: #765000; background: var(--warning-soft); }
.status-pill.in_progress.online { color: var(--brand-dark); background: var(--brand-soft); }
.status-pill.in_progress.offline { color: var(--danger); background: var(--danger-soft); }
.link-button { min-height: auto; padding: 0; color: var(--brand); background: transparent; text-decoration: underline; }
.empty-state { padding: 2rem; text-align: center; color: var(--muted); }
.admin-status { margin: 0; color: var(--muted); }
body[data-admin-mode="easy"] .advanced-only { display: none !important; }
body[data-admin-mode="advanced"] .easy-only { display: none !important; }
.admin-mode-switch { display: inline-flex; gap: 0.35rem; margin-bottom: 1rem; padding: 0.35rem; border: 1px solid var(--line); border-radius: 14px; background: white; }
.admin-mode-button { min-height: 40px; padding: 0.55rem 0.9rem; color: var(--muted); background: transparent; box-shadow: none; }
.admin-mode-button.active { color: white; background: var(--brand); }
.admin-header.compact { align-items: center; margin-bottom: 1rem; }
.config-panel { padding: clamp(1rem, 3vw, 1.6rem); }
.config-form { display: grid; gap: 1.25rem; }
.config-primary-grid, .config-advanced-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.input-with-unit { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: white; overflow: hidden; }
.input-with-unit input { border: 0; border-radius: 0; box-shadow: none; }
.input-with-unit span { padding: 0 0.8rem; color: var(--muted); font-weight: 700; }
.question-editor-heading, .question-set-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.question-editor-heading h3, .question-set-header h4 { margin: 0; }
.question-sets { display: grid; gap: 1rem; }
.question-set-editor { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: #fbfdfc; }
.question-set-groups { display: block; margin-top: 0.9rem; }
.question-editor-list { display: grid; gap: 0.7rem; margin: 0.9rem 0; }
.question-editor-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 42px; align-items: start; gap: 0.6rem; }
.question-editor-row textarea { min-height: 92px; }
.question-index { display: grid; place-items: center; width: 34px; height: 34px; margin-top: 0.25rem; border-radius: 10px; color: var(--brand-dark); background: var(--brand-soft); font-weight: 800; }
.icon-button { width: 42px; min-height: 42px; padding: 0; font-size: 1.3rem; }
.danger-soft { color: var(--danger); background: var(--danger-soft); }
.compact-button { min-height: 38px; padding: 0.5rem 0.75rem; }
.config-actions { display: flex; justify-content: flex-end; }

.dialog { width: min(900px, calc(100% - 2rem)); max-height: calc(100vh - 3rem); padding: 0; overflow: hidden; border: 0; border-radius: var(--radius); box-shadow: 0 30px 100px rgba(0, 0, 0, 0.25); }
.dialog::backdrop { background: rgba(12, 26, 23, 0.58); backdrop-filter: blur(3px); }
.dialog-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; padding: 1.4rem 1.6rem; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin-bottom: 0.2rem; }
.dialog-close { width: 42px; min-height: 42px; padding: 0; font-size: 1.4rem; border: 1px solid var(--line); background: white; }
.dialog-body { max-height: calc(100vh - 160px); padding: 1.5rem; overflow-y: auto; }
.answer-card { margin-bottom: 1rem; padding: 1.2rem; border: 1px solid var(--line); border-radius: 13px; }
.answer-card h3 { margin-bottom: 0.5rem; }
.answer-content { margin: 1rem 0 0; padding: 1rem; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 10px; background: var(--surface-soft); line-height: 1.6; }
.audit-list { display: grid; gap: 0.65rem; max-height: 320px; overflow-y: auto; }
.audit-item { padding: 0.8rem; border: 1px solid var(--line); border-radius: 10px; font-size: 0.88rem; }
.audit-item time { display: block; color: var(--muted); }

@media (max-width: 760px) {
  .site-header { padding: 0 1rem; }
  .shell, .admin-shell { margin-top: 1.25rem; }
  .exam-facts, .metrics { grid-template-columns: 1fr 1fr; }
  .exam-toolbar { align-items: flex-start; flex-direction: column; }
  .timer-card { width: 100%; text-align: left; }
  .exam-actions { display: grid; grid-template-columns: 1fr 1fr; }
  #review { grid-column: 1 / -1; grid-row: 1; }
  .answer-meta, .review-actions, .admin-header { align-items: stretch; flex-direction: column; }
  .review-actions { display: grid; }
  .receipt { padding: 2rem 1.2rem; }
  .receipt dl { grid-template-columns: 1fr; gap: 0.2rem; }
  .receipt dd { margin-bottom: 0.8rem; }
  .toolbar > * { flex-basis: 100%; }
}

@media (max-width: 440px) {
  .quiet-link { display: none; }
  .hero { padding: 1.35rem; }
  .exam-facts, .metrics { grid-template-columns: 1fr; }
  .exam-actions { grid-template-columns: 1fr; }
  #review { grid-column: auto; grid-row: auto; }
}

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