:root {
  --ink: #1c2b3a;
  --navy: #9f1d1d;
  --navy-deep: #6e121c;
  --blue: #d32f2f;
  --blue-dark: #b71c1c;
  --coral: #ef6f57;
  --gold: #f0b429;
  --green: #1f9d6a;
  --violet: #7b61c4;
  --sky: #f4f7fb;
  --paper: #ffffff;
  --line: #e3ebf5;
  --good: #178a56;
  --good-bg: #e8f8f0;
  --bad: #d64545;
  --bad-bg: #fdecec;
  --muted: #66788a;
  --shadow: 0 12px 32px rgba(159, 29, 29, 0.1);
  --glow-a: rgba(211, 47, 47, 0.12);
  --glow-b: rgba(239, 111, 87, 0.1);
  --glow-c: rgba(31, 157, 106, 0.1);
  --guest-grad: linear-gradient(165deg, #e53935 0%, #c62828 48%, #8e1b1b 100%);
  --tone: var(--blue);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: var(--sky);
}

body.theme-sd,
body.theme-sd :root {
  --navy: #9f1d1d;
  --navy-deep: #6e121c;
  --blue: #d32f2f;
  --blue-dark: #b71c1c;
  --shadow: 0 12px 32px rgba(159, 29, 29, 0.1);
  --glow-a: rgba(211, 47, 47, 0.12);
  --glow-b: rgba(239, 111, 87, 0.1);
  --glow-c: rgba(31, 157, 106, 0.1);
  --guest-grad: linear-gradient(165deg, #e53935 0%, #c62828 48%, #8e1b1b 100%);
}

body.theme-smp {
  --navy: #1d4e89;
  --navy-deep: #163a66;
  --blue: #2f80ed;
  --blue-dark: #1f68c9;
  --shadow: 0 12px 32px rgba(29, 78, 137, 0.1);
  --glow-a: rgba(47, 128, 237, 0.14);
  --glow-b: rgba(31, 157, 106, 0.1);
  --glow-c: rgba(240, 180, 41, 0.12);
  --guest-grad: linear-gradient(165deg, #2f80ed 0%, #1d4e89 55%, #163a66 100%);
}

body.theme-sma {
  --navy: #4b5563;
  --navy-deep: #374151;
  --blue: #6b7280;
  --blue-dark: #4b5563;
  --shadow: 0 12px 32px rgba(55, 65, 81, 0.12);
  --glow-a: rgba(107, 114, 128, 0.16);
  --glow-b: rgba(156, 163, 175, 0.14);
  --glow-c: rgba(75, 85, 99, 0.12);
  --guest-grad: linear-gradient(165deg, #9ca3af 0%, #6b7280 48%, #4b5563 100%);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 0% 0%, var(--glow-a), transparent 32%),
    radial-gradient(circle at 100% 0%, var(--glow-b), transparent 28%),
    radial-gradient(circle at 100% 100%, var(--glow-c), transparent 30%),
    var(--sky);
}
a { color: var(--blue-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

.nav-toggle, .gate { position: absolute; opacity: 0; pointer-events: none; }
.backdrop, .burger { display: none; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 280px;
  height: 100vh;
  flex: none;
  overflow: hidden;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #f5f9ff;
  display: flex;
  flex-direction: column;
  padding: 22px 18px;
}
.brand { display: flex; gap: 12px; align-items: flex-start; text-decoration: none; color: inherit; }
.brand img { width: 56px; height: 56px; border-radius: 16px; background: white; object-fit: cover; }
.brand strong { display: block; font-size: 1.12rem; line-height: 1.25; }
.brand p { margin: 6px 0 0; color: rgba(245, 249, 255, 0.78); font-size: 0.82rem; line-height: 1.4; }
.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 28px; flex: 1; min-height: 0; overflow: auto; }
.side-nav a {
  color: rgba(245, 249, 255, 0.9);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 12px;
}
.side-nav a.active, .side-nav a:hover { background: rgba(255, 255, 255, 0.14); color: white; }
.side-nav a.active { box-shadow: inset 3px 0 0 var(--gold); }
.userbox { flex: none; margin-top: 16px; padding-top: 18px; border-top: 1px solid rgba(255, 255, 255, 0.16); }
.userbox strong { display: block; }
.userbox span { display: block; color: #ffd978; font-size: 0.82rem; margin: 4px 0 12px; }

.main { flex: 1; min-width: 0; }
.topbar { padding: 28px 32px 0; }
.eyebrow { margin: 0 0 4px; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.75rem; color: var(--blue); font-weight: 700; }
.topbar h1, .guest-copy h1, .sheet h1 { font-weight: 750; letter-spacing: -0.03em; }
.topbar h1 { margin: 0; font-size: 2rem; }
.content { padding: 22px 32px 48px; }

.card, .stat, .pass {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card { padding: 20px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.stat-grid, .split, .master-grid { display: grid; gap: 16px; }
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat { padding: 18px; border-top: 4px solid var(--blue); }
.stat:nth-child(2) { border-top-color: var(--coral); }
.stat:nth-child(3) { border-top-color: var(--green); }
.stat:nth-child(4) { border-top-color: var(--gold); }
.stat b { display: block; font-size: 2rem; margin-top: 6px; color: var(--navy); }
.stat span, .muted { color: var(--muted); }
.split { grid-template-columns: 1.4fr 0.8fr; }
.master-grid { grid-template-columns: 1fr 1fr; align-items: start; }

.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.subject-card h2 { margin: 0 0 8px; font-size: 1.2rem; }
.tone-blue { --tone: #2f80ed; }
.tone-coral { --tone: #ef6f57; }
.tone-green { --tone: #1f9d6a; }
.tone-gold { --tone: #e2a312; }
.tone-violet { --tone: #7b61c4; }
.subject-card, .practice { border-top: 5px solid var(--tone); }
.progress { height: 8px; background: #e8eef6; border-radius: 99px; overflow: hidden; margin: 12px 0; }
.progress span, .bar span { display: block; height: 100%; background: var(--tone); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  text-decoration: none;
  cursor: pointer;
  background: transparent;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-ghost { background: transparent; color: inherit; border: 1px solid currentColor; }
.sidebar .btn-ghost { color: #f5f9ff; }
.btn-danger { background: var(--bad); color: white; }
.btn-small { padding: 6px 12px; font-size: 0.88rem; }
.btn-block { width: 100%; margin-top: 8px; }
.btn:disabled, .is-disabled { opacity: 0.55; pointer-events: none; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
th.col-no, td.col-no { width: 1%; text-align: center; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
th.col-actions, td.actions { text-align: right; white-space: nowrap; width: 1%; }
td.actions form, td.actions a, td.actions button { display: inline-flex; vertical-align: middle; margin-left: 8px; }
td.actions form:first-child, td.actions a:first-child, td.actions button:first-child { margin-left: 0; }
table input[type="text"], table select { width: 100%; min-width: 88px; margin: 0; padding: 8px 10px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span, .check { font-size: 0.92rem; }
input[type="text"], input[type="password"], input[type="search"], input[type="file"], select, textarea {
  width: 100%;
  border: 1px solid #d5e1ef;
  background: white;
  border-radius: 12px;
  padding: 12px 14px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--blue) 28%, transparent); border-color: var(--blue); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 160px; }

.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; }
.banner-ok { background: var(--good-bg); color: var(--good); }
.banner-bad { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; background: #fdecec; color: var(--navy); font-size: 0.78rem; }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }

.practice { max-width: 760px; margin: 0 auto; }
.practice-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 0.92rem; }
.prompt { font-size: 1.45rem; line-height: 1.45; margin: 8px 0 18px; }
.q-image { margin: 0 0 16px; }
.q-image img, .image-preview img, .choice-image {
  display: block;
  max-width: min(100%, 520px);
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  object-fit: contain;
}
.image-preview { margin: 0 0 16px; display: grid; gap: 8px; }
.choice-body { flex: 1; display: grid; gap: 8px; text-align: left; }
.choice-image { max-height: 160px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  cursor: pointer;
}
.choice:hover { border-color: var(--tone); }
.letter {
  width: 38px; height: 38px; flex: none; border-radius: 12px;
  display: grid; place-items: center; background: #fdecec; color: var(--navy); font-weight: 750;
}
.choice-text { flex: 1; }
.tag { font-size: 0.75rem; border-radius: 999px; padding: 3px 8px; background: #fdecec; }
.choice.is-correct { background: var(--good-bg); border-color: var(--good); }
.choice.is-correct .letter, .choice.is-correct .tag { background: white; color: var(--good); }
.choice.is-wrong { background: var(--bad-bg); border-color: var(--bad); }
.choice.is-wrong .letter { background: white; color: var(--bad); }
.result { border-radius: 14px; padding: 12px 14px; font-weight: 700; }
.result.is-good { background: var(--good-bg); color: var(--good); }
.result.is-bad { background: var(--bad-bg); color: var(--bad); }
.explain { margin-top: 16px; padding: 16px 18px; border-radius: 16px; background: #fff8e8; border-left: 5px solid var(--gold); }
.explain h2 { margin: 0 0 8px; font-size: 1rem; }
.hint { color: var(--muted); font-size: 0.9rem; }
.score-hero { font-size: 4rem; margin: 0; line-height: 1; color: var(--navy); }
.bar-row { display: grid; grid-template-columns: 90px 1fr 48px; gap: 8px; align-items: center; margin: 8px 0; }
.bar { height: 10px; background: #e8eef6; border-radius: 99px; overflow: hidden; }

.pager { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
.pager a { text-decoration: none; }
.pager-disabled { color: var(--muted); }

.check { display: flex; gap: 8px; align-items: center; }
.option-edit { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: start; margin-bottom: 10px; }
.key { display: flex; gap: 8px; align-items: center; padding-top: 12px; }

.bulk-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding: 12px 16px;
}
.bulk-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.col-check { width: 36px; text-align: center; }
.row-muted { opacity: 0.72; }
.status-form { margin: 0; }
.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: #c5d0dc;
    position: relative;
    transition: background 0.15s ease;
    flex: 0 0 auto;
}
.switch-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}
.switch input:checked + .switch-track { background: var(--good); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch-label { font-size: 0.85rem; color: var(--muted); min-width: 2.5rem; }
.switch input:checked ~ .switch-label { color: var(--good); font-weight: 600; }

.guest { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 0.95fr; }
.guest-copy {
  position: relative;
  overflow: hidden;
  background: var(--guest-grad);
  color: #f5f9ff;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.guest-copy::before, .guest-copy::after {
  content: "";
  position: absolute;
  border-radius: 50%;
}
.guest-copy::before { width: 220px; height: 220px; background: rgba(240, 180, 41, 0.28); top: -50px; right: -40px; }
.guest-copy::after { width: 140px; height: 140px; background: rgba(239, 111, 87, 0.28); bottom: 40px; left: -30px; }
.guest-copy > * { position: relative; z-index: 1; }
.guest-copy img { width: 84px; height: 84px; border-radius: 22px; background: white; }
.guest-copy h1 { font-size: 3rem; margin: 18px 0 8px; }
.guest-copy p { max-width: 460px; line-height: 1.5; color: rgba(245, 249, 255, 0.9); }
.guest-form { padding: 48px 40px; display: flex; align-items: center; }
.panel { width: min(460px, 100%); }
.tab-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.tab-switch label { text-align: center; padding: 10px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; background: white; }
#tab-warga:checked ~ .tab-switch label[for="tab-warga"],
#tab-ortu:checked ~ .tab-switch label[for="tab-ortu"] { background: var(--navy); color: white; border-color: var(--navy); }
#tab-warga:checked ~ .panel-ortu, #tab-ortu:checked ~ .panel-warga { display: none; }
.demo { margin-top: 22px; font-size: 0.88rem; color: var(--muted); }
.demo code { font-family: Consolas, monospace; color: var(--navy); }

.sheet { max-width: 860px; margin: 0 auto; padding: 24px; }
.pass { padding: 22px; margin-bottom: 18px; break-inside: avoid; page-break-inside: avoid; border-top: 5px solid var(--blue); }
.pass-head { display: flex; gap: 12px; align-items: center; }
.pass-head img { width: 58px; height: 58px; border-radius: 14px; }
.code { font-family: Consolas, monospace; font-size: 2rem; letter-spacing: 0.08em; margin: 8px 0; color: var(--navy); }

@media (max-width: 960px) {
  .split, .master-grid, .guest, .grid-2, .option-edit { grid-template-columns: 1fr; }
  .guest-copy { padding: 28px; }
  .guest-copy h1 { font-size: 2.2rem; }
  .burger {
    display: inline-flex;
    margin-bottom: 10px;
    border: 0;
    border-radius: 999px;
    padding: 8px 14px;
    background: var(--navy);
    color: white;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(300px, 88vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    overflow: hidden;
  }
  .nav-toggle:checked ~ .sidebar { transform: none; }
  .nav-toggle:checked ~ .backdrop { display: block; position: fixed; inset: 0; background: rgba(110, 18, 28, 0.45); z-index: 15; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
}

@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .pass { box-shadow: none; }
}
