:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  touch-action: manipulation;
  transition: transform 0.06s ease, background-color 0.15s ease, border-color 0.15s ease;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.2rem;
}

/* ---------------- General Pages ---------------- */
.page {
  max-width: 980px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 24px max(36px, env(safe-area-inset-bottom));
}

h1 {
  margin: 8px 0 6px;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

h2 {
  margin: 26px 0 12px;
  font-size: 1.18rem;
  font-weight: 700;
}

.sub {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 4px 0;
}

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.streak {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
}

.today {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  color: #fff;
  border-radius: 22px;
  padding: 24px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.24);
  margin-bottom: 22px;
}

.today h2 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}

.today p {
  margin: 4px 0;
}

.today .sub {
  color: rgba(255, 255, 255, 0.86);
}

.today .primary {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.14);
}

.modes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.modes.five {
  grid-template-columns: repeat(5, 1fr);
}

.mode {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}

.mode:hover {
  border-color: var(--primary);
}

.mode span {
  font-size: 1.8rem;
  line-height: 1.2;
}

.mode b {
  font-size: 1.08rem;
}

.mode small {
  color: var(--muted);
  font-size: 0.85rem;
}

.units {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.unit {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  text-align: left;
  box-shadow: var(--shadow);
}

.unit.cur {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.u-num {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.u-name {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 2px 0 10px;
}

.bar {
  position: relative;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.bar .tried {
  position: absolute;
  inset: 0 auto 0 0;
  background: #93c5fd;
  border-radius: 999px;
}

.bar .mast {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ok);
  border-radius: 999px;
}

.u-foot {
  font-size: 0.82rem;
  color: var(--muted);
}

.foot {
  margin-top: 28px;
  display: flex;
  justify-content: center;
}

/* ---------------- Buttons & Chips ---------------- */
.primary {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  border-radius: 14px;
  padding: 12px 22px;
}

.primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.ghost {
  background: var(--card);
  border: 1.5px solid var(--line);
  color: var(--ink);
  font-weight: 600;
  border-radius: 14px;
  padding: 10px 18px;
}

.ghost:hover:not(:disabled) {
  border-color: #94a3b8;
}

.danger {
  background: var(--bad-soft);
  color: var(--bad);
  border: 1.5px solid #fecaca;
  font-weight: 700;
  border-radius: 14px;
  padding: 10px 18px;
}

.big {
  font-size: 1.08rem;
  padding: 14px 26px;
}

.huge {
  font-size: 1.2rem;
  padding: 16px 34px;
  border-radius: 16px;
  white-space: nowrap;
}

.filebtn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 22px;
}

.chip {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.96rem;
}

.chip.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

/* ---------------- Training Screen (Tablet-first) ---------------- */
.run {
  min-height: 100dvh;
  max-width: 1120px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 20px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.run-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.run-title {
  font-size: 1.05rem;
  color: var(--muted);
  text-align: center;
}

.run-title b {
  color: var(--primary);
}

.run-count {
  font-weight: 800;
  font-size: 1.1rem;
  min-width: 72px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  background: var(--primary);
  transition: width 0.25s ease;
}

.timebar {
  position: relative;
  height: 28px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timebar > div {
  position: absolute;
  inset: 0 auto 0 0;
  background: #bbf7d0;
  transition: width 0.1s linear, background-color 0.2s ease;
}

.timebar > div.warn {
  background: #fde68a;
}

.timebar > div.over {
  background: #fecaca;
}

.timebar > span {
  position: relative;
  z-index: 1;
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.quiz-clock {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary-dark);
  background: var(--primary-soft);
  padding: 8px 16px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.quiz-clock.warn {
  background: var(--bad-soft);
  color: var(--bad);
}

.run-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 20px;
  align-items: stretch;
  min-height: 0;
}

.run-body.choice,
.run-body.judge {
  grid-template-columns: 1.15fr 1fr;
}

.qcard {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  padding: 24px 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.qmeta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 0.84rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
}

.tag.u {
  background: #f1f5f9;
  color: #475569;
}

.stars {
  margin-left: auto;
  color: #f59e0b;
  letter-spacing: 1px;
  font-size: 0.95rem;
}

.stem {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
  margin: auto 0;
}

.stem.oral {
  font-size: 2.5rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.answer-box {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  background: #f8fafc;
  border: 2.5px solid var(--primary);
  border-radius: 16px;
  padding: 14px 20px;
  min-height: 72px;
}

.disp {
  font-size: 2.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  color: var(--primary-dark);
}

.unit {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--muted);
}

/* ---------------- Keypad / Choices / Judge ---------------- */
.pad {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.key {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  min-height: 72px;
  font-size: 1.75rem;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.05);
  font-variant-numeric: tabular-nums;
}

.key:hover {
  background: #f8fafc;
}

.key.clear {
  background: #f1f5f9;
  color: var(--muted);
  font-size: 1.15rem;
}

.key.enter {
  grid-column: span 2;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-size: 1.35rem;
}

.key.enter:hover {
  background: var(--primary-dark);
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.choice {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  font-size: 1.15rem;
  box-shadow: var(--shadow);
}

.choice b {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  flex-shrink: 0;
  font-size: 1.1rem;
}

.choice.sel,
.jbtn.sel {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.judge {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.jbtn {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 22px;
  min-height: 150px;
  font-size: 1.8rem;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.jbtn.ok {
  color: var(--ok);
}

.jbtn.no {
  color: var(--bad);
}

.quiz-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

/* ---------------- Feedback Overlay ---------------- */
.feedback {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  backdrop-filter: blur(2px);
}

.feedback.hidden {
  display: none;
}

.fb-inner {
  background: var(--card);
  border-radius: 24px;
  padding: 26px 30px;
  max-width: 640px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.24);
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 85dvh;
  overflow-y: auto;
}

.fb-inner.fast {
  border-top: 8px solid var(--ok);
}

.fb-inner.slow {
  border-top: 8px solid var(--warn);
}

.fb-inner.wrong {
  border-top: 8px solid var(--bad);
}

.fb-big {
  font-size: 1.65rem;
  font-weight: 800;
}

.fb-inner .right {
  color: var(--ok);
}

.analysis {
  background: #f8fafc;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 0.98rem;
  line-height: 1.65;
  color: #334155;
  user-select: text;
  -webkit-user-select: text;
}

/* ---------------- Stats / Results / Lists ---------------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.stat {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 18px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat b {
  display: block;
  font-size: 1.85rem;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 0.88rem;
  color: var(--muted);
}

.great {
  background: var(--ok-soft);
  color: #166534;
  font-weight: 700;
  font-size: 1.15rem;
  padding: 20px;
  border-radius: 18px;
  text-align: center;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
}

.item summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}

.item summary::-webkit-details-marker {
  display: none;
}

.item-stem {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-t {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.item-body {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.badge {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 800;
  flex-shrink: 0;
}

.badge.wrong {
  background: var(--bad-soft);
  color: var(--bad);
}

.badge.slow {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.fast {
  background: var(--ok-soft);
  color: var(--ok);
}

.days {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 18px 16px 12px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 180px;
  overflow-x: auto;
}

.day {
  flex: 1;
  min-width: 52px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.day .col {
  width: 24px;
  min-height: 6px;
  background: var(--primary);
  border-radius: 6px 6px 2px 2px;
}

.day small {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.tbl th,
.tbl td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.tbl th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.88rem;
}

.settings {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px 28px;
  align-items: center;
}

.settings label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.settings select {
  font: inherit;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ---------------- Phase 2: Figures, Blanks, Self-eval, Stages, Lightbox ---------------- */
.tag.ocr {
  background: var(--warn-soft);
  color: var(--warn);
}

.qfig {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}

.qfig img {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 10px;
  cursor: zoom-in;
  background: #fff;
}

.fig-tip {
  font-size: 0.8rem;
  color: var(--muted);
}

.fig-desc {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.92rem;
}

.fig-desc summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary-dark);
}

.mini-fig {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: zoom-in;
  align-self: flex-start;
  background: #fff;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 96vw;
  max-height: 86vh;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.lb-tip {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
}

.blank-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.slot {
  background: #f8fafc;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 112px;
}

.slot small {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.slot b {
  font-size: 1.35rem;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.slot.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.slot.filled:not(.active) {
  border-color: #93c5fd;
  background: #fff;
}

.slot-hint {
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
}

.cmp-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.cmp-pad .jbtn {
  min-height: 120px;
  font-size: 2.2rem;
  color: var(--primary-dark);
}

.bdiff {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bd {
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.bd.ok {
  background: var(--ok-soft);
  color: #166534;
}

.bd.bad {
  background: var(--bad-soft);
  color: #991b1b;
}

.self-clock {
  text-align: center;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  background: #eef2ff;
  padding: 6px 14px;
  border-radius: 999px;
}

.subs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8fafc;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 1rem;
}

.sub-item {
  display: flex;
  gap: 8px;
}

.self-box {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.self-guide {
  font-size: 1.08rem;
  font-weight: 600;
  color: #334155;
}

.self-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hint-card {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: 14px;
  padding: 14px 16px;
  color: #92400e;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.self-ans {
  font-size: 1.15rem;
}

.self-ans b {
  color: var(--ok);
}

.eval-title {
  font-weight: 700;
  text-align: center;
  margin-top: 4px;
}

.eval-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.eval {
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #fff;
}

.eval span {
  font-size: 1.5rem;
}

.eval small {
  font-size: 0.78rem;
  color: var(--muted);
}

.eval.ok:hover { border-color: var(--ok); background: var(--ok-soft); }
.eval.warn:hover { border-color: var(--warn); background: var(--warn-soft); }
.eval.bad:hover { border-color: var(--bad); background: var(--bad-soft); }

.stage-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.stage-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage-card.cleared {
  border-color: #86efac;
  background: #f0fdf4;
}

.stage-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.stage-idx {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  display: grid;
  place-items: center;
  font-weight: 800;
  flex-shrink: 0;
}

.stage-card.cleared .stage-idx {
  background: var(--ok-soft);
}

.stage-pill {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  white-space: nowrap;
}

.stage-pill.ok {
  background: var(--ok-soft);
  color: #166534;
}

.stage-acts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stage-banner {
  padding: 16px 20px;
  border-radius: 16px;
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.stage-banner.pass {
  background: var(--ok-soft);
  color: #166534;
  border: 1.5px solid #86efac;
}

.stage-banner.try {
  background: var(--warn-soft);
  color: #92400e;
  border: 1.5px solid #fcd34d;
}

.self-review-row {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sr-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sr-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sr-btns .chip {
  padding: 6px 12px;
  font-size: 0.86rem;
}

/* ---------------- Tablet Portrait / Narrower Screens ---------------- */
@media (max-width: 820px) {
  .modes,
  .modes.five,
  .units {
    grid-template-columns: repeat(2, 1fr);
  }
  .stage-list {
    grid-template-columns: 1fr;
  }
  .stat-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .run-body,
  .run-body.choice,
  .run-body.judge {
    grid-template-columns: 1fr;
  }
  .qcard {
    padding: 18px 20px;
  }
  .stem {
    font-size: 1.22rem;
  }
  .stem.oral {
    font-size: 2.1rem;
  }
  .key {
    min-height: 64px;
  }
  .jbtn {
    min-height: 108px;
  }
  .today {
    flex-direction: column;
    align-items: stretch;
  }
  .today .huge {
    width: 100%;
    text-align: center;
  }
}


/* ---------------- Phase 3 & 4: Compact Home, Badges, Dual Charts, Printable A4 ---------------- */
.page.compact {
  padding-top: max(14px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.page.compact .home-head {
  margin-bottom: 12px;
}

.page.compact .today {
  padding: 18px 24px;
  margin-bottom: 16px;
}

.page.compact h2 {
  margin: 18px 0 10px;
}

.page.compact .foot {
  margin-top: 18px;
  gap: 12px;
  flex-wrap: wrap;
}

.head-pills {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill-badge {
  background: #fefce8;
  color: #a16207;
  border: 1px solid #fde047;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.96rem;
  font-weight: 700;
  white-space: nowrap;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.badge-unlock {
  background: linear-gradient(135deg, #fefce8 0%, #fef3c7 100%);
  border: 1.5px solid #facc15;
  color: #854d0e;
  border-radius: 16px;
  padding: 14px 18px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 1.02rem;
}

.ach-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.ach {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ach span {
  font-size: 1.75rem;
  line-height: 1.2;
}

.ach b {
  font-size: 0.92rem;
}

.ach small {
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.3;
}

.ach.on {
  border-color: #facc15;
  background: #fefce8;
  box-shadow: var(--shadow);
}

.ach.off {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.dual-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.day .col.ok {
  background: var(--ok);
}

/* ---------------- Phase 4: Printable Worksheet Preview & @media print ---------------- */
.print-controls {
  margin: 14px 0 22px;
}

.sheet {
  background: #ffffff;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 28px 34px;
  box-shadow: var(--shadow);
  color: #111827;
  user-select: text;
  -webkit-user-select: text;
}

.sheet.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 24px;
}

.p-head {
  text-align: center;
  border-bottom: 2px solid #1e293b;
  padding-bottom: 12px;
  margin-bottom: 18px;
}

.p-head h2 {
  margin: 0 0 8px;
  font-size: 1.32rem;
  color: #111827;
}

.p-meta {
  font-size: 0.94rem;
  color: #334155;
}

.p-sec {
  margin-bottom: 18px;
}

.p-sec h3 {
  margin: 0 0 10px;
  font-size: 1.06rem;
  font-weight: 800;
  color: #0f172a;
}

.p-q {
  margin-bottom: 12px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.p-stem {
  font-size: 0.98rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.p-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 6px;
  padding-left: 20px;
  font-size: 0.95rem;
}

.p-fig {
  margin-top: 8px;
  padding-left: 16px;
}

.p-fig img {
  max-width: 72%;
  max-height: 220px;
  object-fit: contain;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.p-space.med {
  height: 52px;
}

.p-space.tall {
  height: 110px;
}

.p-answers {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 2px dashed #94a3b8;
  break-before: page;
  page-break-before: always;
}

.p-ans-item {
  margin-bottom: 10px;
  font-size: 0.92rem;
  line-height: 1.55;
  break-inside: avoid;
}

.p-ans-val {
  color: #166534;
  font-weight: 700;
}

.p-ans-x {
  color: #475569;
  padding-left: 18px;
  margin-top: 2px;
}

@media (max-width: 820px) {
  .ach-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .dual-charts {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 14mm 15mm;
  }
  html, body {
    background: #fff !important;
    font-size: 11pt;
  }
  .no-print {
    display: none !important;
  }
  .page, .print-page {
    max-width: none;
    padding: 0;
    margin: 0;
  }
  .sheet {
    border: none;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
  }
  .p-fig img {
    max-height: 160px;
  }
  .p-answers {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
  }
}
