/* ============================================================
   1A Half-Yearly Examination App (Pro) — Core Stylesheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color .18s ease, color .18s ease;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.3px;
  line-height: 1.3;
}
h1 { font-size: 27px; }
h2 { font-size: 19px; }
h3 { font-size: 15.5px; }

.sub { color: var(--ink-2); font-size: 14px; margin: 6px 0 0; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.eyebrow {
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--accent);
  margin-bottom: 8px;
}

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none !important;
  flex-shrink: 0;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 14px;
  font-family: var(--mono);
  letter-spacing: -0.5px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 32%, transparent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14.5px; font-weight: 650; }
.brand-text em { font-style: normal; font-size: 11.5px; color: var(--ink-3); }

.subject-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.subtab {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.subtab:hover { color: var(--ink); }
.subtab.is-on {
  background: var(--surface);
  color: var(--accent);
  font-weight: 650;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}
.navlink {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-badge {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bad-soft);
  color: var(--bad);
  line-height: 1.4;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.theme-switch button {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 4px 8px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  transition: all .15s;
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* Mobile Subject Ribbon (hidden on desktop) */
.mobile-subbar { display: none; }
/* Mobile Bottom Nav (hidden on desktop) */
.bottom-nav { display: none; }

/* ---------------- Layout & Cards ---------------- */

.view {
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 26px 20px 64px;
  flex: 1;
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.panel { padding: 20px 22px; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.hero {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 30px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.hero::after {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  right: -80px;
  top: -80px;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: .75;
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 12px;
}
.section-title span { font-size: 13px; color: var(--ink-3); }

/* ---------------- Buttons & Chips ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.3;
  transition: all .14s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-hover);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-lg { padding: 10px 20px; font-size: 14.5px; border-radius: 11px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}
.btn-ok {
  background: var(--ok);
  border-color: var(--ok);
  color: #ffffff;
}
.btn-ok:hover:not(:disabled) {
  filter: brightness(1.06);
  color: #ffffff;
  border-color: var(--ok);
}
.btn-warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn);
}
.btn-warn:hover:not(:disabled) {
  background: var(--warn);
  color: #ffffff;
  border-color: var(--warn);
}
.btn-danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  filter: brightness(1.06);
  color: #ffffff;
  border-color: var(--bad);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--ink);
}
.btn-flag.is-flagged {
  background: var(--flag-soft);
  border-color: var(--flag);
  color: var(--flag);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 550;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--mono);
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.type { font-family: var(--font); margin-left: auto; }

/* ---------------- Landing Grid ---------------- */

.landing-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}
.landing-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--ink-2);
}
.landing-pill b { color: var(--ink); font-family: var(--mono); }

.subj-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}
.subj-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
  min-height: 186px;
}
button.subj-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
}
.subj-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.subj-code {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
}
.subj-card strong { font-size: 17px; font-weight: 650; margin-bottom: 4px; }
.subj-meta { font-size: 13px; color: var(--ink-2); }
.subj-hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.subj-foot {
  width: 100%;
  margin-top: auto;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.subj-go {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
}
.subj-links {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: auto;
  padding-top: 12px;
}
.subj-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  transition: filter .15s;
}
.subj-link:hover { text-decoration: none; filter: brightness(.96); }

/* ---------------- Mode Cards ---------------- */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.mode-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.mode-top {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
}
.glyph {
  display: inline-grid;
  place-items: center;
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
}
.mode-card strong { font-size: 15.5px; }
.mode-card .desc { font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.mode-card .count {
  margin-top: auto;
  padding-top: 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
}

/* ---------------- Chapters & Setup ---------------- */

.module-block { margin-bottom: 18px; }
.module-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  margin: 0 -10px 8px;
  border-radius: 9px;
  user-select: none;
  transition: background .14s;
}
.module-head.is-toggleable { cursor: pointer; }
.module-head.is-toggleable:hover { background: var(--surface-2); }
.module-head .tag {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
}
.module-head .mod-count {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--ink-3);
}
.module-head .mod-toggle-pill {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--ink-2);
  background: var(--surface);
}
.module-head.is-all .mod-toggle-pill {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chapter-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.chapter-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .14s, background .14s, transform .14s;
  text-align: left;
  width: 100%;
}
button.chapter-item:not(.is-disabled),
label.chapter-item:not(.is-disabled) { cursor: pointer; }
button.chapter-item:not(.is-disabled):hover,
label.chapter-item:not(.is-disabled):hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}
.chapter-item.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.chapter-item.is-disabled {
  opacity: .52;
  background: var(--surface-2);
  cursor: not-allowed;
}
.chapter-item input[type="checkbox"],
.chapter-item input[type="radio"] {
  margin: 3px 2px 0 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.chapter-item > span, .chapter-item > div { flex: 1; min-width: 0; }
.c-id {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}
.c-title {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}
.c-zh {
  display: block;
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}
.c-n {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
  flex-shrink: 0;
}

.setup-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.stepper label { font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
.stepper input[type="number"] {
  width: 72px;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: var(--mono);
  font-weight: 650;
  text-align: center;
}
.preset-row {
  display: inline-flex;
  gap: 4px;
}
.selected-hint { font-size: 13px; color: var(--ink-2); }
.selected-hint b { color: var(--ink); font-family: var(--mono); }

/* ---------------- Quiz Shell ---------------- */

.quiz-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.quiz-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.qpos { font-size: 13.5px; color: var(--ink-2); }
.qpos b { color: var(--ink); font-family: var(--mono); }
.spacer { flex: 1; }
.timer {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  font-weight: 650;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
}
.timer.is-warn { background: var(--warn-soft); color: var(--warn); }
.timer.is-danger { background: var(--bad-soft); color: var(--bad); }
.timer.is-paused { opacity: .6; }

.progress-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .22s ease;
}

.qcard { padding: 24px 26px; }
.qmeta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 16px;
}
.qstem {
  font-size: 16px;
  line-height: 1.72;
  color: var(--ink);
  white-space: pre-line;
  margin-bottom: 16px;
}

.qimg-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.qimg-box {
  position: relative;
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--img-bg);
  padding: 8px;
  max-width: 100%;
  cursor: zoom-in;
  overflow: hidden;
}
.qimg {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 0 auto;
}
.qimg-zoom-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .72);
  color: #fff;
  font-size: 11.5px;
  pointer-events: none;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  width: 100%;
  padding: 12px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .14s, background .14s;
  line-height: 1.5;
}
.option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-hover);
}
.option .key {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.option.is-picked {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.option.is-picked .key { background: var(--accent); color: var(--accent-ink); }
.option.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}
.option.is-correct .key { background: var(--ok); color: #fff; }
.option.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
}
.option.is-wrong .key { background: var(--bad); color: #fff; }
.option.is-locked { cursor: default; }

.opt-letters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.letter-btn {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  transition: all .14s;
}
.letter-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.letter-btn.is-picked { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.letter-btn.is-correct { border-color: var(--ok); background: var(--ok); color: #fff; }
.letter-btn.is-wrong { border-color: var(--bad); background: var(--bad); color: #fff; }

/* Fill inputs */
.fill-input {
  display: inline-block;
  width: 170px;
  max-width: 100%;
  padding: 5px 10px;
  margin: 2px 4px;
  border-radius: 8px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 550;
  transition: border-color .14s, background .14s;
}
.fill-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.fill-input.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}
.fill-input.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
  color: var(--bad);
}
.fill-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.short-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  resize: vertical;
  line-height: 1.6;
}
.short-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.refbox {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
}
.refbox strong { display: block; font-size: 13px; color: var(--accent); margin-bottom: 6px; }
.refbox p { margin: 0; white-space: pre-line; font-size: 14px; color: var(--ink); }

.feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.feedback.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.feedback.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.feedback.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.feedback strong { display: block; font-size: 14.5px; margin-bottom: 4px; }
.feedback.ok strong { color: var(--ok); }
.feedback.bad strong { color: var(--bad); }
.feedback.warn strong { color: var(--warn); }
.feedback .ans { font-weight: 600; font-size: 14px; margin: 4px 0 6px; color: var(--ink); }
.feedback p { margin: 4px 0 0; font-size: 13.8px; color: var(--ink-2); }

.qactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.partial-score-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 9px;
}
.partial-score-wrap input {
  width: 52px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: var(--mono);
  text-align: center;
}

.qnav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.qdot {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  display: grid;
  place-items: center;
  transition: all .12s;
}
.qdot:hover { border-color: var(--accent); color: var(--accent); }
.qdot.is-current { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.qdot.is-done:not(.is-current) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.qdot.is-right:not(.is-current) { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.qdot.is-wrong:not(.is-current) { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.qdot.is-partial:not(.is-current) { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.qdot.is-flagged::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--flag);
  border: 2px solid var(--surface);
}

/* ---------------- Province Map Layout ---------------- */

.map-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1.08fr) minmax(300px, 1fr);
  gap: 18px;
  align-items: start;
}
.map-side {
  position: sticky;
  top: calc(var(--header-h) + 14px);
}
.map-side .qimg-box { width: 100%; }
.map-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 10px;
  padding: 7px 11px;
  border-radius: 9px;
  background: var(--surface-2);
}
.prov-grid, .link-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.prov-cell, .link-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.prov-cell-top, .link-row-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.prov-no {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.link-name {
  font-size: 13px;
  font-weight: 550;
  flex: 1;
  min-width: 0;
}
.prov-cell .fill-input,
.link-row .fill-input {
  width: 100%;
  margin: 0;
  padding: 5px 8px;
  font-size: 13.5px;
}
.link-row .fill-input { width: 64px; text-align: center; font-family: var(--mono); }
.map-correction {
  font-size: 11.5px;
  color: var(--ok);
  font-weight: 600;
  padding-left: 2px;
}

.mobile-map-toggle { display: none; }

/* ---------------- Result & Review ---------------- */

.result-hero {
  padding: 32px 24px;
  text-align: center;
}
.score-ring {
  --pct: 0;
  width: 136px;
  height: 136px;
  border-radius: 50%;
  margin: 0 auto 18px;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--surface-2) 0);
  display: grid;
  place-items: center;
  position: relative;
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 50%;
  background: var(--surface);
}
.score-in { position: relative; z-index: 1; text-align: center; }
.score-num { font-size: 30px; font-weight: 750; font-family: var(--mono); line-height: 1.1; }
.score-den { font-size: 12.5px; color: var(--ink-3); font-family: var(--mono); margin-top: 2px; }

.result-stats {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 14px;
  margin: 18px auto 4px;
}
.rstat .v { font-size: 24px; font-weight: 750; font-family: var(--mono); }
.rstat .v.ok { color: var(--ok); }
.rstat .v.bad { color: var(--bad); }
.rstat .k { font-size: 12.5px; color: var(--ink-3); }

.breakdown { display: flex; flex-direction: column; gap: 10px; }
.brow {
  display: grid;
  grid-template-columns: minmax(130px, 240px) 1fr 64px;
  align-items: center;
  gap: 12px;
  font-size: 13.5px;
}
.bname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.btrack { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bfill { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.bval { text-align: right; font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.filter-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 550;
}
.filter-chip.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------------- Papers, Wrong Book & Stats ---------------- */

.paper-list { display: flex; flex-direction: column; gap: 12px; }
.paper-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.p-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 750;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.p-body { flex: 1; min-width: 0; }
.p-meta { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

.list-item {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.li-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
}
.li-stem {
  font-size: 14.8px;
  color: var(--ink);
  white-space: pre-line;
  margin-bottom: 10px;
  line-height: 1.6;
}
.li-stem .blank {
  display: inline-block;
  min-width: 28px;
  text-align: center;
  padding: 0 5px;
  margin: 0 2px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 700;
}
.li-answers {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--surface-2);
}
.li-ans-wrong b { color: var(--bad); }
.li-ans-right b { color: var(--ok); }
.li-explain {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-2);
  white-space: pre-line;
}
.li-thumb {
  max-height: 130px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--img-bg);
  padding: 4px;
  margin-bottom: 10px;
  cursor: zoom-in;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.stat-box {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.stat-box .v { font-size: 28px; font-weight: 750; font-family: var(--mono); line-height: 1.15; }
.stat-box .k { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.history-row:last-child { border-bottom: 0; }
.h-mode { font-weight: 600; min-width: 72px; }
.h-title { color: var(--ink-2); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-date { color: var(--ink-3); font-family: var(--mono); font-size: 12px; }
.h-score { font-family: var(--mono); font-weight: 650; margin-left: auto; }

.empty {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--ink-2);
}
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 auto; max-width: 420px; font-size: 14px; }

/* ---------------- Loading Skeleton ---------------- */

.loading-box {
  text-align: center;
  padding: 56px 20px;
  color: var(--ink-2);
}
.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Footer ---------------- */

.footer {
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 18px 20px 30px;
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* ---------------- Toast, Dialog & Lightbox ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  background: #1b2028;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 120;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, #0b0f17 55%, transparent);
  backdrop-filter: blur(5px);
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.modal-card h2 { font-size: 18px; margin-bottom: 8px; }
.modal-card p { margin: 0; font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(9, 13, 22, .88);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.lightbox[hidden] { display: none; }
.lightbox-bar {
  position: fixed;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 112;
}
.lightbox-bar button {
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(20, 26, 38, .85);
  color: #fff;
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
}
.lightbox-bar button:hover { background: var(--accent); border-color: var(--accent); }
.lightbox-stage {
  max-width: 96vw;
  max-height: 86vh;
  overflow: auto;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.lightbox-stage img {
  display: block;
  transform-origin: top left;
  transition: width .15s ease;
  max-width: none;
}

.kbd-hint {
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}
kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--ink-2);
}

/* ---------------- Responsive (Mobile <= 760px) ---------------- */

@media (max-width: 860px) {
  .subj-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chapter-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-layout { grid-template-columns: 1fr; }
  .map-side { position: static; }
}

@media (max-width: 760px) {
  :root { --header-h: 54px; }
  h1 { font-size: 22px; }

  .topbar-inner {
    padding: 8px 14px;
    min-height: 54px;
    gap: 8px;
  }
  .brand-mark { width: 32px; height: 32px; font-size: 13px; }
  .brand-text em { display: none; }
  .brand-text strong { font-size: 14px; }
  .topbar .subject-tabs,
  .topbar .topnav { display: none; }
  .theme-switch { margin-left: auto; }
  .theme-switch button { padding: 4px 6px; font-size: 11.5px; }

  /* Compact non-sticky subject ribbon */
  .mobile-subbar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
  }
  .mobile-subbar .subtab {
    flex: 1;
    text-align: center;
    padding: 6px 10px;
    background: var(--surface-2);
    border-radius: 8px;
  }
  .mobile-subbar .subtab.is-on {
    background: var(--accent);
    color: var(--accent-ink);
  }

  /* Fixed Mobile Bottom Nav */
  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav button {
    border: 0;
    background: transparent;
    color: var(--ink-2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 5px 4px;
    border-radius: 9px;
    font-size: 11.5px;
    font-weight: 550;
  }
  .bottom-nav button.is-active {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 650;
  }
  .bottom-nav .bn-ico { font-family: var(--mono); font-size: 12px; font-weight: 700; }

  .view { padding: 16px 14px 88px; }
  .footer { padding-bottom: 84px; }
  .hero { padding: 20px 18px; }
  .qcard { padding: 18px 16px; }
  .subj-grid, .chapter-list { grid-template-columns: 1fr; }
  .prov-grid, .link-list { grid-template-columns: 1fr; }
  .paper-card { flex-direction: column; align-items: flex-start; }
  .paper-card .btn { width: 100%; }
  .brow { grid-template-columns: 1fr 80px; }
  .btrack { grid-column: 1 / -1; order: 3; }
  .kbd-hint { display: none; }
  .toast { bottom: 78px; }

  /* Mobile collapsible map bar */
  .mobile-map-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 9px 12px;
    margin-bottom: 10px;
    border-radius: 10px;
    border: 1px solid var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
    font-size: 13px;
  }
}
