:root {
  --navy: #0b2e4a;
  --navy-mid: #164a6e;
  --navy-deep: #071e32;
  --gold: #c9a227;
  --gold-2: #e6c85c;
  --gold-soft: #f8efd0;
  --paper: #f4efe3;
  --paper-2: #ebe4d3;
  --ink: #1c2330;
  --muted: #5b6b7c;
  --white: #fffdf8;
  --green: #1b7a4c;
  --green-soft: #e3f5eb;
  --red: #c0392b;
  --red-soft: #fdecea;
  --orange: #d35400;
  --orange-soft: #fff1e4;
  --blue: #2b6cb0;
  --line: #e2d9c4;
  --shadow: 0 12px 36px rgba(11, 46, 74, 0.1);
  --radius: 20px;
  --nav-h: calc(66px + env(safe-area-inset-bottom, 0px));
  --font: "Outfit", "Segoe UI", system-ui, sans-serif;
  --display: "Fraunces", "Georgia", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; display: block; }
button { cursor: pointer; border: 0; background: none; color: inherit; }
a { color: inherit; }

.app {
  min-height: 100%;
  padding-bottom: var(--nav-h);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: linear-gradient(180deg, var(--navy-deep), var(--navy));
  color: #fff;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.topbar .brand img {
  width: 36px;
  height: 40px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.25));
}
.topbar h1 {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
}
.topbar h1 small {
  display: block;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  opacity: 0.72;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255,255,255,.08);
}
.icon-btn:active { background: rgba(255,255,255,.16); }

.view {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

.hero-card {
  background: linear-gradient(145deg, var(--navy) 0%, var(--navy-mid) 55%, #1c5d82 100%);
  color: #fff;
  border-radius: 24px;
  padding: 22px 20px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201,162,39,.35), transparent 70%);
}
.hero-card .kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-2);
  font-weight: 600;
}
.hero-card h2 {
  font-family: var(--display);
  font-size: 26px;
  margin: 6px 0 8px;
  position: relative;
}
.hero-card p { opacity: 0.8; font-size: 14px; position: relative; }
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
  position: relative;
}
.hero-stats div {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  padding: 10px 8px;
  text-align: center;
}
.hero-stats strong { display: block; font-size: 20px; font-family: var(--display); }
.hero-stats span { font-size: 11px; opacity: 0.7; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: scale(0.98); }
.btn-gold {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: var(--navy-deep);
  box-shadow: 0 8px 20px rgba(201,162,39,.28);
}
.btn-navy { background: var(--navy); color: #fff; }
.btn-ghost {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--navy);
}
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 16px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}
.tile {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 14px;
  text-align: left;
  box-shadow: 0 4px 14px rgba(11,46,74,.04);
}
.tile .ico {
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--gold-soft);
  color: var(--navy);
  margin-bottom: 10px;
  font-size: 18px;
}
.tile h3 { font-size: 14px; margin-bottom: 4px; }
.tile p { font-size: 12px; color: var(--muted); line-height: 1.4; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 0 10px;
}
.section-title h3 { font-size: 15px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.section-title button { font-size: 13px; color: var(--navy-mid); font-weight: 600; }

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 6px 18px rgba(11,46,74,.05);
}
.card + .card { margin-top: 12px; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,39,.2); }

.key-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.chip {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
}
.chip.active { background: var(--navy); color: #fff; }

.key-list { display: grid; gap: 6px; }
.key-row {
  display: grid;
  grid-template-columns: 36px repeat(4, 1fr);
  gap: 6px;
  align-items: center;
}
.key-row .qnum {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}
.opt {
  min-height: 42px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-weight: 700;
  color: var(--navy);
}
.opt.on {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.opt.correct { background: var(--green); color: #fff; border-color: var(--green); }
.opt.wrong { background: var(--red-soft); color: var(--red); border-color: #f3c0ba; }
.opt.picked { box-shadow: inset 0 0 0 2px var(--gold); }

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--nav-h);
  background: #fffdf8;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 30;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--navy); }
.nav-item.scan-fab {
  transform: translateY(-14px);
}
.nav-item.scan-fab .fab {
  width: 56px; height: 56px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: var(--navy-deep);
  display: grid; place-items: center;
  box-shadow: 0 10px 20px rgba(201,162,39,.35);
}
.nav-item.scan-fab span { color: var(--navy); }

.scan-screen, .full-screen {
  position: fixed;
  inset: 0;
  background: #050d16;
  z-index: 50;
  display: flex;
  flex-direction: column;
  color: #fff;
}
.scan-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
}
.scan-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.scan-stage video, .scan-stage canvas, .scan-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.overlay-frame {
  position: absolute;
  inset: 8% 10%;
  border: 2px dashed rgba(230,200,92,.85);
  border-radius: 12px;
  pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0,0,0,.35);
}
.scan-hint {
  position: absolute;
  bottom: 18px;
  left: 16px; right: 16px;
  text-align: center;
  font-size: 13px;
  color: #f8efd0;
  text-shadow: 0 1px 4px #000;
}
.scan-actions {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 14px 20px calc(18px + env(safe-area-inset-bottom, 0px));
  background: #071e32;
}
.shutter {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: radial-gradient(circle at 50% 50%, #fff 0 28px, transparent 29px);
}
.shutter:active { transform: scale(0.94); }
.side-act {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 600;
}

.corner-handle {
  position: absolute;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  z-index: 3;
  touch-action: none;
}
.quad-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.score-ring {
  width: 160px; height: 160px;
  margin: 8px auto 12px;
  position: relative;
}
.score-ring svg { width: 160px; height: 160px; transform: rotate(-90deg); }
.score-ring .val {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-ring .val strong {
  font-family: var(--display);
  font-size: 42px;
  line-height: 1;
  color: var(--navy);
}
.score-ring .val span { font-size: 12px; color: var(--muted); font-weight: 600; }

.pills {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.pill {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
}
.pill strong { display: block; font-size: 18px; }
.pill span { font-size: 11px; color: var(--muted); }
.pill.ok strong { color: var(--green); }
.pill.bad strong { color: var(--red); }
.pill.mute strong { color: var(--muted); }
.pill.warn strong { color: var(--orange); }

.result-q {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}
.result-q:last-child { border-bottom: 0; }
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-bad { background: var(--red-soft); color: var(--red); }
.badge-mute { background: var(--paper-2); color: var(--muted); }
.badge-warn { background: var(--orange-soft); color: var(--orange); }

.thumb-sheet {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.history-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  width: 100%;
  text-align: left;
}
.history-item .avatar-score {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 16px;
  flex-shrink: 0;
}
.history-item .meta { flex: 1; min-width: 0; }
.history-item h4 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item p { font-size: 12px; color: var(--muted); }

.empty {
  text-align: center;
  padding: 28px 10px;
  color: var(--muted);
}
.empty .big { font-size: 36px; margin-bottom: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 12px);
  transform: translateX(-50%);
  background: var(--navy-deep);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

.modal-back {
  position: fixed; inset: 0;
  background: rgba(7,30,50,.45);
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-modal {
  background: var(--white);
  width: 100%;
  max-width: 560px;
  border-radius: 22px 22px 0 0;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom, 0px));
}
.handle {
  width: 42px; height: 4px; border-radius: 4px;
  background: var(--line); margin: 4px auto 12px;
}

.paper-preview {
  background: #fff;
  color: #111;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.loading-splash {
  position: fixed; inset: 0;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  gap: 12px;
}
.loading-splash img { width: 72px; height: 80px; object-fit: contain; }
.loading-splash h1 { font-family: var(--display); font-size: 28px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: var(--gold-2);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.process-overlay {
  position: absolute; inset: 0;
  background: rgba(7,30,50,.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 5;
}

.vis-wrap { position: relative; }
.vis-wrap img, .vis-wrap canvas { width: 100%; border-radius: 12px; }

.help-list {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  padding-left: 18px;
}
.help-list li { margin: 6px 0; }

/* ===== Printable answer sheet ===== */
.lembar {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #111;
  padding: 10mm 12mm 12mm;
  position: relative;
  font-family: "Times New Roman", Times, serif;
  margin: 0 auto;
}
.marker {
  position: absolute;
  width: 7mm;
  height: 7mm;
  background: #000;
}
.marker.tl { top: 5mm; left: 5mm; }
.marker.tr { top: 5mm; right: 5mm; }
.marker.bl { bottom: 5mm; left: 5mm; }
.marker.br { bottom: 5mm; right: 5mm; }

.lembar-head {
  display: grid;
  grid-template-columns: 16mm 1fr;
  gap: 4mm;
  align-items: center;
  text-align: center;
}
.lembar-head img { width: 15mm; height: 17mm; object-fit: contain; margin: 0 auto; }
.lembar-head .org { font-size: 11pt; font-weight: 700; letter-spacing: 0.3px; }
.lembar-head .sch { font-size: 13pt; font-weight: 800; }
.lembar-head .addr { font-size: 8pt; margin-top: 1mm; }
.lembar hr.double {
  border: 0;
  border-top: 2.5px solid #111;
  border-bottom: 1px solid #111;
  height: 3px;
  margin: 3mm 0 3.5mm;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10pt;
}
.info-table td {
  border: 1.2px solid #111;
  padding: 1.6mm 2mm;
  height: 7.2mm;
}
.info-table .lbl { width: 38mm; font-weight: 700; white-space: nowrap; }
.info-table .nilai {
  width: 28mm;
  text-align: center;
  font-weight: 800;
  letter-spacing: 1px;
  vertical-align: top;
}
.info-table .nilai .box {
  height: 28mm;
}

.lembar h2.title {
  text-align: center;
  font-size: 14pt;
  margin: 5mm 0 2mm;
  letter-spacing: 1px;
}
.pg-label { font-size: 10.5pt; font-weight: 700; margin: 0 0 1.5mm; }

.omr-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 8pt;
  margin-bottom: 4.5mm;
}
.omr-table th, .omr-table td {
  border: 1px solid #111;
  text-align: center;
  height: 6.3mm;
  padding: 0;
  font-weight: 700;
}
.omr-table th { height: 6.6mm; }
.omr-table .lab { width: 8mm; }

.essay-title { font-size: 10.5pt; font-weight: 700; margin: 1mm 0 2mm; }
.essay-line {
  border-bottom: 1px solid #222;
  height: 7.4mm;
}

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .app, .bottom-nav, .topbar, .toast, .modal-back, .scan-screen, .full-screen, .loading-splash { display: none !important; }
  #print-root { display: block !important; }
  .lembar { box-shadow: none; }
}

@media screen {
  #print-root { display: none; }
  #print-root.print-preview {
    display: block;
    padding: 12px;
    overflow: auto;
  }
  #print-root.print-preview .lembar {
    transform-origin: top center;
    box-shadow: var(--shadow);
  }
}

@media (max-width: 420px) {
  .hero-card h2 { font-size: 22px; }
}
