:root {
  color-scheme: dark;
  --bg: #05070b;
  --panel: rgba(15, 23, 42, .92);
  --panel-strong: #111827;
  --line: #263244;
  --line-bright: #3b4b63;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --blue: #38bdf8;
  --blue-strong: #2563eb;
  --amber: #fbbf24;
  --green: #22c55e;
  --pink: #f472b6;
  --shadow: 0 18px 52px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 0%, rgba(30, 64, 175, .42), transparent 30rem),
    radial-gradient(circle at 92% 9%, rgba(8, 145, 178, .2), transparent 28rem),
    linear-gradient(180deg, #070b12 0, var(--bg) 48rem);
  color: var(--text);
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: #bae6fd; }

.ka-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 7, 11, .88);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .28);
  backdrop-filter: blur(14px);
}
.topbar-inner {
  max-width: 1220px;
  min-height: 64px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.ka-brand { font-size: 19px; font-weight: 950; white-space: nowrap; }
.ka-brand a { color: inherit; text-decoration: none; }
.ka-brand span { margin-left: 5px; color: #7dd3fc; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill-link {
  padding: 7px 12px;
  border: 1px solid #334155;
  border-radius: 999px;
  background: #0b1220;
  color: #dbeafe;
  text-decoration: none;
  font-size: 13px;
  font-weight: 900;
}
.source-link { color: #fde68a; border-color: rgba(251, 191, 36, .35); }

main { max-width: 1220px; margin: 0 auto; padding: 34px 20px 72px; }
.hero {
  min-height: 370px;
  padding: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(310px, .65fr);
  align-items: center;
  gap: 34px;
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(135deg, rgba(30, 41, 59, .98), rgba(15, 23, 42, .9)),
    var(--panel-strong);
  box-shadow: var(--shadow);
}
.hero::after {
  content: "CAP";
  position: absolute;
  right: -16px;
  top: -52px;
  color: rgba(125, 211, 252, .055);
  font: 950 250px/1 "Segoe UI", sans-serif;
  letter-spacing: -.08em;
  pointer-events: none;
}
.hero-copy, .hero-stats { position: relative; z-index: 1; }
.eyebrow, .panel-kicker {
  color: #7dd3fc;
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .14em;
}
h1 { max-width: 700px; margin: 9px 0 14px; font-size: clamp(35px, 5vw, 58px); line-height: 1.08; letter-spacing: -.045em; }
h2 { margin: 5px 0 8px; font-size: 24px; line-height: 1.3; }
.hero p { max-width: 720px; margin: 0; color: #cbd5e1; font-size: 16px; line-height: 1.85; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: white;
  text-decoration: none;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  transition: transform .16s, filter .16s, border-color .16s, background .16s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.07); }
.btn:focus-visible, select:focus-visible, input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid rgba(56, 189, 248, .42); outline-offset: 2px; }
.btn-primary { background: linear-gradient(135deg, #2563eb, #0284c7); box-shadow: 0 9px 24px rgba(2, 132, 199, .23); }
.btn-ghost { border-color: #3b4b63; background: #0b1220; color: #e2e8f0; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  min-height: 112px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid rgba(125, 211, 252, .18);
  border-radius: 20px;
  background: rgba(2, 6, 23, .5);
  backdrop-filter: blur(8px);
}
.stat strong { color: #f8fafc; font-size: 32px; line-height: 1; }
.stat span { margin-top: 8px; color: var(--muted); font-size: 13px; font-weight: 800; }

.integrity-panel, .source-note, .filter-panel, .tray-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(0, 0, 0, .22);
}
.integrity-panel {
  padding: 20px 22px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  border-color: rgba(251, 191, 36, .3);
  background: linear-gradient(135deg, rgba(120, 53, 15, .32), rgba(15, 23, 42, .94));
}
.integrity-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: #78350f;
  color: #fde68a;
  font-size: 26px;
  font-weight: 950;
}
.integrity-panel .panel-kicker { color: #fbbf24; }
.integrity-panel h2 { margin: 3px 0 5px; font-size: 19px; }
.integrity-panel p, .source-note p { margin: 0; color: #cbd5e1; font-size: 13px; line-height: 1.7; }
.integrity-tags { display: flex; flex-direction: column; gap: 7px; align-items: flex-end; }
.integrity-tags span { padding: 6px 9px; border-radius: 999px; background: rgba(2, 6, 23, .55); color: #fde68a; font-size: 11px; font-weight: 900; white-space: nowrap; }
.source-note { padding: 15px 20px; display: flex; gap: 13px; align-items: baseline; }
.source-note strong { color: #f8fafc; white-space: nowrap; }
.source-note a { margin: 0 3px; }

.practice-panel {
  margin-top: 28px;
  padding: 26px;
  border: 1px solid rgba(34, 197, 94, .34);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(6, 78, 59, .26), rgba(15, 23, 42, .96) 42%);
  box-shadow: var(--shadow);
  scroll-margin-top: 82px;
}
.practice-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.practice-head p { max-width: 760px; margin: 5px 0 0; color: #cbd5e1; font-size: 13px; line-height: 1.7; }
.practice-badge { padding: 7px 11px; border: 1px solid rgba(34, 197, 94, .35); border-radius: 999px; background: rgba(20, 83, 45, .55); color: #bbf7d0; font-size: 12px; font-weight: 950; white-space: nowrap; }
.practice-controls { margin-top: 20px; display: grid; grid-template-columns: 1fr 1.35fr 1.75fr .65fr auto; align-items: end; gap: 12px; }
.practice-controls label { display: flex; flex-direction: column; gap: 7px; }
.practice-controls label > span { color: #cbd5e1; font-size: 12px; font-weight: 900; }
.practice-pdf-actions { margin-top: 11px; display: flex; align-items: end; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.practice-pdf-actions label { min-width: 190px; display: flex; flex-direction: column; gap: 7px; }
.practice-pdf-actions label > span { color: #cbd5e1; font-size: 12px; font-weight: 900; }
.practice-pdf-actions p { width: 100%; margin: 0; color: #64748b; font-size: 11px; text-align: right; }
.practice-method { margin: 17px 0; padding: 12px; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; border: 1px dashed rgba(125, 211, 252, .26); border-radius: 14px; background: rgba(2, 6, 23, .34); }
.practice-method span { color: #bae6fd; font-size: 11px; font-weight: 900; }
.practice-breakdown { margin: -7px 0 17px; color: #94a3b8; font-size: 12px; line-height: 1.65; text-align: center; }
.practice-grid { display: grid; gap: 14px; }
.practice-question { padding: 21px; border: 1px solid #304158; border-radius: 18px; background: rgba(2, 6, 23, .7); box-shadow: 0 12px 32px rgba(0, 0, 0, .22); }
.practice-question-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.adapted-source { color: #86efac; font-size: 11px; font-weight: 950; }
.evidence-chip { margin-left: 7px; padding: 2px 7px; border: 1px solid rgba(250, 204, 21, .42); border-radius: 999px; background: rgba(113, 63, 18, .48); color: #fde68a; font-size: 9px; font-weight: 950; white-space: nowrap; }
.fidelity-chip { border-color: rgba(52, 211, 153, .45); background: rgba(6, 78, 59, .58); color: #a7f3d0; }
.practice-question h3 { margin: 5px 0 0; color: #f8fafc; font-size: 18px; }
.progress-chip { padding: 5px 9px; border-radius: 999px; background: #0c4a6e; color: #bae6fd; font-size: 10px; font-weight: 900; white-space: nowrap; }
.practice-stem { margin-top: 18px; color: #f1f5f9; font-size: 17px; font-weight: 700; line-height: 1.85; }
.math-fraction { min-width: 1.4em; margin: 0 .13em; display: inline-flex; flex-direction: column; align-items: stretch; line-height: 1.05; text-align: center; vertical-align: middle; }
.math-fraction span:first-child { padding: 0 .16em .08em; border-bottom: 1px solid currentColor; }
.math-fraction span:last-child { padding: .08em .16em 0; }
.practice-system { margin: 0 5px; display: inline-flex; padding-left: 12px; flex-direction: column; position: relative; vertical-align: middle; line-height: 1.45; }
.practice-system::before { content: "{"; position: absolute; left: -4px; top: 50%; transform: translateY(-52%) scaleY(1.75); font-size: 26px; font-weight: 400; }
.practice-visual { margin: 15px 0; }
.cap-fidelity-svg { width: min(100%, 620px); max-height: 285px; margin: 0 auto; display: block; color: #e2e8f0; }
.cap-fidelity-svg text { fill: currentColor; font: 700 12px system-ui, sans-serif; }
.cap-fidelity-table { width: min(100%, 680px); margin: 9px auto; color: #e2e8f0; text-align: center; }
.cap-fidelity-table > b { display: block; margin-bottom: 5px; color: #bae6fd; font-size: 12px; }
.cap-fidelity-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cap-fidelity-table th, .cap-fidelity-table td { padding: 8px 10px; border: 1px solid #475569; }
.cap-fidelity-table th { background: #1e293b; color: #f8fafc; }
.cap-fidelity-table td { background: rgba(15, 23, 42, .78); }
.cap-screen, .cap-promo { width: min(100%, 520px); margin: 0 auto; padding: 16px 18px; display: grid; gap: 6px; border: 1px solid #475569; border-radius: 14px; background: #111827; color: #e2e8f0; text-align: center; }
.cap-screen strong, .cap-promo strong { color: #7dd3fc; font-size: 17px; }
.cap-screen span, .cap-promo span { font-weight: 850; }
.cap-screen small, .cap-promo small { color: #94a3b8; }
.cap-card-row, .cap-process { width: min(100%, 620px); margin: 8px auto; padding: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; border: 1px solid #475569; border-radius: 13px; background: #111827; color: #e2e8f0; }
.cap-card-row b { min-width: 150px; color: #bae6fd; }
.cap-card-row span, .cap-card-row i { width: 38px; height: 50px; display: grid; place-items: center; border: 1px solid #64748b; border-radius: 7px; background: #f8fafc; color: #111827; font-style: normal; font-weight: 950; }
.cap-card-row i { background: repeating-linear-gradient(45deg,#334155,#334155 5px,#475569 5px,#475569 10px); color: white; }
.cap-process span, .cap-process b { padding: 8px 11px; border-radius: 9px; background: #1e293b; }
.practice-svg { width: min(100%, 560px); max-height: 280px; margin: 0 auto; display: block; overflow: visible; }
.practice-svg line, .practice-svg polyline, .practice-svg polygon, .practice-svg rect, .practice-svg circle { vector-effect: non-scaling-stroke; }
.practice-svg text { fill: #e2e8f0; font: 700 12px system-ui, sans-serif; }
.practice-svg line, .practice-svg polyline { fill: none; stroke: #cbd5e1; stroke-width: 2; }
.practice-svg circle { fill: #38bdf8; stroke: #e0f2fe; stroke-width: 1.5; }
.practice-svg .diagram-shape { fill: rgba(30, 41, 59, .42); stroke: #e2e8f0; stroke-width: 2.2; }
.practice-svg .diagram-circle { fill: rgba(56, 189, 248, .08); stroke: #7dd3fc; stroke-width: 2; }
.practice-svg .diagram-guide { stroke: #94a3b8; stroke-width: 1.5; }
.practice-svg .diagram-accent { stroke: #facc15; stroke-width: 2.7; }
.practice-svg .diagram-dashed { stroke-dasharray: 6 5; }
.practice-svg .diagram-grid { stroke: #334155; stroke-width: 1; }
.practice-svg .chart-bar { fill: #38bdf8; stroke: #bae6fd; stroke-width: 1; }
.practice-svg .chart-bar.negative { fill: #fb7185; stroke: #fecdd3; }
.practice-svg .chart-line { fill: none; stroke: #facc15; stroke-width: 3; }
.practice-data-table { width: min(100%, 680px); margin: 0 auto; border-collapse: collapse; overflow: hidden; border-radius: 12px; color: #e2e8f0; font-size: 13px; text-align: center; }
.practice-data-table caption { padding: 8px; color: #bae6fd; font-size: 12px; font-weight: 900; }
.practice-data-table th, .practice-data-table td { padding: 8px 10px; border: 1px solid #475569; }
.practice-data-table th { background: #1e293b; color: #f8fafc; }
.practice-data-table td { background: rgba(15, 23, 42, .78); }
.practice-bags { display: flex; gap: 10px; flex-wrap: wrap; }
.practice-bags span { padding: 10px 13px; border: 1px solid #3b4b63; border-radius: 12px; background: #111827; color: #e2e8f0; font-weight: 850; }
.practice-price { max-width: 620px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid #475569; border-radius: 13px; overflow: hidden; }
.practice-price span { padding: 11px; display: flex; flex-direction: column; gap: 4px; text-align: center; background: #111827; color: #f8fafc; }
.practice-price span + span { border-left: 1px solid #475569; }
.practice-price b { color: #7dd3fc; font-size: 11px; }
.practice-triangle { width: 260px; height: 140px; margin: 0 auto; position: relative; }
.practice-triangle::before { content: ""; position: absolute; left: 35px; bottom: 18px; width: 130px; height: 94px; border-left: 3px solid #e2e8f0; border-bottom: 3px solid #e2e8f0; transform: skewX(-28deg); transform-origin: bottom left; }
.practice-triangle i { position: absolute; left: 164px; bottom: 18px; width: 78px; border-top: 3px solid #e2e8f0; }
.practice-triangle span { position: absolute; color: #fde68a; font-weight: 950; }
.practice-triangle span:nth-child(1) { left: 53px; top: 3px; }
.practice-triangle span:nth-child(2) { left: 19px; bottom: 0; }
.practice-triangle span:nth-child(3) { left: 159px; bottom: 0; }
.practice-choices { margin-top: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.practice-choice { min-height: 50px; padding: 9px 12px; display: flex; align-items: center; gap: 10px; border: 1px solid #334155; border-radius: 12px; background: #111827; color: #e2e8f0; text-align: left; cursor: pointer; }
.practice-choice:hover:not(:disabled) { border-color: #38bdf8; background: #172033; }
.practice-choice > span { width: 27px; height: 27px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 8px; background: #1e293b; color: #bae6fd; font-size: 12px; font-weight: 950; }
.practice-choice b { font-size: 14px; line-height: 1.45; }
.practice-choice.correct { border-color: #22c55e; background: rgba(20, 83, 45, .58); }
.practice-choice.wrong { border-color: #ef4444; background: rgba(127, 29, 29, .5); }
.practice-choice:disabled { color: inherit; opacity: 1; cursor: default; }
.practice-feedback { margin-top: 14px; padding: 13px 15px; border-radius: 13px; font-size: 13px; line-height: 1.65; }
.practice-feedback.is-correct { border: 1px solid rgba(34, 197, 94, .42); background: rgba(20, 83, 45, .32); color: #dcfce7; }
.practice-feedback.is-wrong { border: 1px solid rgba(248, 113, 113, .42); background: rgba(127, 29, 29, .27); color: #fee2e2; }
.practice-feedback p { margin: 3px 0 8px; }
.practice-solution { padding-top: 8px; border-top: 1px solid rgba(148, 163, 184, .24); color: #e2e8f0; }
.practice-question-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 5px; }

.filter-panel { margin-top: 28px; padding: 24px; scroll-margin-top: 82px; }
.filter-head, .results-head, .tray-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.filter-head h2, .results-head h2, .tray-head h2 { margin-bottom: 0; }
.text-btn { border: 0; background: transparent; color: #7dd3fc; font-weight: 900; cursor: pointer; padding: 7px; }
.filter-grid { margin-top: 20px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; }
.filter-grid label { display: flex; flex-direction: column; gap: 7px; }
.filter-grid label > span { color: #cbd5e1; font-size: 12px; font-weight: 900; }
select, input[type="search"] {
  width: 100%;
  min-height: 43px;
  padding: 9px 11px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #0b1220;
  color: var(--text);
}
.search-field { grid-column: span 2; }
.composer-row { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.result-count { color: #f8fafc; font-size: 16px; font-weight: 950; }
.composer-controls { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.composer-controls label { color: var(--muted); font-size: 13px; font-weight: 800; }
.composer-controls select { width: auto; min-width: 66px; }
#trayCount { min-width: 21px; height: 21px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 999px; background: #334155; font-size: 11px; }

.tray-panel { padding: 24px; border-color: rgba(56, 189, 248, .34); }
.tray-head p { margin: 5px 0 0; color: var(--muted); }
.tray-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tray-list { margin-top: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tray-item { min-width: 0; padding: 11px 12px; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 13px; background: rgba(2, 6, 23, .5); }
.tray-index { width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; background: #0c4a6e; color: #bae6fd; font-size: 12px; font-weight: 950; }
.tray-copy { min-width: 0; flex: 1; }
.tray-source { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #f8fafc; font-size: 13px; font-weight: 900; text-align: left; }
.tray-unit { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; color: var(--muted); font-size: 11px; text-align: left; }
.tray-remove { width: 30px; height: 30px; flex: 0 0 auto; border: 0; border-radius: 9px; background: #1e293b; color: #cbd5e1; cursor: pointer; }

.results-section { margin-top: 34px; }
.results-head { align-items: flex-end; margin-bottom: 16px; }
.results-head p { margin: 0; color: var(--muted); font-size: 13px; }
.question-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.progress-heading { grid-column: 1 / -1; margin-top: 12px; padding: 12px 15px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-left: 4px solid #38bdf8; border-radius: 0 12px 12px 0; background: linear-gradient(90deg, rgba(12, 74, 110, .72), rgba(15, 23, 42, .35)); }
.progress-heading strong { color: #f8fafc; font-size: 19px; }
.progress-heading span { color: #bae6fd; font-size: 11px; font-weight: 850; }
.question-card {
  min-width: 0;
  padding: 17px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(17, 24, 39, .9);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  transition: transform .16s, border-color .16s, box-shadow .16s;
}
.question-card:hover { transform: translateY(-2px); border-color: #3b82f6; box-shadow: 0 16px 40px rgba(0, 0, 0, .3); }
.question-card.is-selected { border-color: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, .14), 0 16px 40px rgba(0, 0, 0, .3); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.source-badge { max-width: calc(100% - 40px); padding: 5px 8px; border-radius: 8px; background: #172554; color: #bfdbfe; font-size: 11px; font-weight: 950; line-height: 1.35; }
.add-button { width: 34px; height: 34px; flex: 0 0 auto; border: 1px solid #334155; border-radius: 10px; background: #0b1220; color: #cbd5e1; cursor: pointer; font-size: 18px; font-weight: 900; }
.question-card.is-selected .add-button { border-color: #15803d; background: #14532d; color: #bbf7d0; }
.question-card h3 { margin: 15px 0 7px; color: #f8fafc; font-size: 18px; line-height: 1.35; }
.card-meta { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.card-tags { min-height: 55px; margin-top: 13px; display: flex; align-content: flex-start; flex-wrap: wrap; gap: 6px; }
.card-tags span { padding: 5px 8px; border: 1px solid #2e3c50; border-radius: 999px; background: #0b1220; color: #cbd5e1; font-size: 10px; font-weight: 850; }
.card-tags .visual-tag { border-color: rgba(251, 191, 36, .32); background: rgba(120, 53, 15, .3); color: #fde68a; }
.card-actions { margin-top: auto; padding-top: 14px; display: flex; gap: 8px; }
.card-actions .btn { width: 100%; min-height: 38px; padding: 7px 11px; font-size: 12px; }
.empty-state { padding: 64px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; border: 1px dashed #334155; border-radius: 18px; color: var(--muted); text-align: center; }
.empty-state strong { color: #f8fafc; font-size: 18px; }

.question-dialog { width: min(1000px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 1px solid #3b4b63; border-radius: 22px; background: #0b1220; color: var(--text); box-shadow: 0 28px 90px rgba(0, 0, 0, .7); }
.question-dialog::backdrop { background: rgba(2, 6, 23, .82); backdrop-filter: blur(6px); }
.dialog-shell { display: flex; flex-direction: column; max-height: calc(100vh - 30px); }
.dialog-head { padding: 18px 20px; display: flex; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 4px 0 2px; font-size: 20px; }
.modal-source { color: #7dd3fc; font-size: 12px; font-weight: 950; }
.modal-meta { color: var(--muted); font-size: 12px; }
.dialog-close { width: 38px; height: 38px; border: 1px solid #334155; border-radius: 11px; background: #111827; color: #e2e8f0; font-size: 25px; line-height: 1; cursor: pointer; }
.image-stage { min-height: 280px; padding: 18px; overflow: auto; position: relative; display: grid; place-items: center; background: #111827; }
.image-stage img { display: block; max-width: 100%; height: auto; border-radius: 5px; background: white; box-shadow: 0 12px 34px rgba(0, 0, 0, .36); }
.image-loading { position: absolute; color: var(--muted); font-weight: 800; }
.dialog-actions { padding: 14px 18px; display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 90; max-width: 330px; padding: 11px 14px; border: 1px solid #3b4b63; border-radius: 12px; background: #111827; color: #f8fafc; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); font-size: 13px; font-weight: 850; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

.site-footer { max-width: 1220px; margin: 0 auto; padding: 0 20px 36px; display: flex; justify-content: space-between; gap: 15px; color: #64748b; font-size: 12px; }
.site-footer a { color: #94a3b8; }
.print-sheet { display: none; }

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; min-height: auto; padding: 32px; }
  .hero-stats { grid-template-columns: repeat(4, 1fr); }
  .stat { min-height: 90px; padding: 14px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .question-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .integrity-panel { grid-template-columns: auto 1fr; }
  .integrity-tags { grid-column: 2; align-items: flex-start; }
  .practice-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
  .topbar-inner { align-items: flex-start; padding: 9px 14px; }
  .ka-brand { padding-top: 7px; font-size: 15px; }
  .top-actions { justify-content: flex-end; }
  .pill-link { font-size: 11px; padding: 6px 9px; }
  main { padding: 20px 13px 54px; }
  .hero { padding: 25px 20px; border-radius: 22px; }
  h1 { font-size: 35px; }
  .hero p { font-size: 14px; }
  .hero-stats { grid-template-columns: 1fr 1fr; }
  .integrity-panel { padding: 17px; grid-template-columns: 1fr; }
  .integrity-icon { display: none; }
  .integrity-tags { grid-column: auto; }
  .source-note { align-items: flex-start; flex-direction: column; gap: 5px; }
  .practice-panel { padding: 20px 15px; }
  .practice-head, .practice-question-head { flex-direction: column; }
  .practice-controls { grid-template-columns: 1fr; }
  .practice-pdf-actions { align-items: stretch; flex-direction: column; }
  .practice-pdf-actions label { width: 100%; }
  .practice-pdf-actions p { text-align: left; }
  .practice-choices { grid-template-columns: 1fr; }
  .practice-price { grid-template-columns: 1fr; }
  .practice-price span + span { border-left: 0; border-top: 1px solid #475569; }
  .filter-panel, .tray-panel { padding: 18px 15px; }
  .filter-grid { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .composer-row, .filter-head, .results-head, .tray-head { align-items: stretch; flex-direction: column; }
  .composer-controls { justify-content: flex-start; }
  .question-grid, .tray-list { grid-template-columns: 1fr; }
  .results-head p { line-height: 1.5; }
  .dialog-actions { align-items: stretch; flex-direction: column; }
  .site-footer { flex-direction: column; }
}

@media print {
  :root { color-scheme: light; }
  .no-print { display: none !important; }
  body { background: white !important; color: #111827; }
  .print-sheet { display: block !important; }
  .print-cover { margin-bottom: 8mm; padding-bottom: 4mm; border-bottom: 2px solid #111827; }
  .print-cover h1 { margin: 0 0 2mm; font-size: 18pt; letter-spacing: 0; }
  .print-cover p { margin: 1mm 0; color: #333; font-size: 9pt; line-height: 1.5; }
  .print-question { margin: 0 0 7mm; break-inside: avoid; page-break-inside: avoid; }
  .print-label { margin-bottom: 2mm; padding-bottom: 1.5mm; border-bottom: 1px solid #777; font-size: 10pt; font-weight: 900; }
  .print-question img { display: block; max-width: 100%; max-height: 245mm; margin: 0 auto; object-fit: contain; }
  .print-adapted-question { margin: 0 0 8mm; padding-bottom: 5mm; border-bottom: 1px solid #9ca3af; break-inside: avoid; page-break-inside: avoid; }
  .print-adapted-head { margin-bottom: 3mm; display: flex; align-items: baseline; justify-content: space-between; gap: 5mm; }
  .print-adapted-head strong { color: #111827; font-size: 12pt; }
  .print-adapted-head span { color: #4b5563; font-size: 7.5pt; text-align: right; }
  .print-adapted-stem { color: #111827; font-size: 10.5pt; font-weight: 650; line-height: 1.65; }
  .print-adapted-visual { margin: 3mm 0; }
  .print-adapted-visual .practice-svg { width: min(100%, 118mm); max-height: 62mm; }
  .print-adapted-visual .practice-svg text { fill: #111827 !important; }
  .print-adapted-visual .practice-svg line, .print-adapted-visual .practice-svg polyline { stroke: #111827; }
  .print-adapted-visual .practice-svg circle { fill: white; stroke: #111827; }
  .print-adapted-visual .practice-svg .diagram-shape { fill: #f3f4f6; stroke: #111827; }
  .print-adapted-visual .practice-svg .diagram-circle { fill: white; stroke: #111827; }
  .print-adapted-visual .practice-svg .diagram-guide { stroke: #6b7280; }
  .print-adapted-visual .practice-svg .diagram-accent { stroke: #111827; }
  .print-adapted-visual .practice-svg .diagram-grid { stroke: #d1d5db; }
  .print-adapted-visual .practice-svg .chart-bar { fill: #d1d5db; stroke: #111827; }
  .print-adapted-visual .practice-svg .chart-bar.negative { fill: #9ca3af; stroke: #111827; }
  .print-adapted-visual .practice-svg .chart-line { stroke: #111827; }
  .print-adapted-visual .practice-data-table { color: #111827; font-size: 8.5pt; }
  .print-adapted-visual .practice-data-table caption { color: #111827; }
  .print-adapted-visual .practice-data-table th, .print-adapted-visual .practice-data-table td { padding: 1.5mm 2mm; border-color: #6b7280; background: white; color: #111827; }
  .print-adapted-visual .cap-fidelity-svg { width: min(100%, 145mm); max-height: 64mm; color: #111827; }
  .print-adapted-visual .cap-fidelity-svg text { fill: #111827 !important; }
  .print-adapted-visual .cap-fidelity-table { color: #111827; }
  .print-adapted-visual .cap-fidelity-table > b { color: #111827; }
  .print-adapted-visual .cap-fidelity-table th, .print-adapted-visual .cap-fidelity-table td { padding: 1.5mm 2mm; border-color: #6b7280; background: white; color: #111827; }
  .print-adapted-visual .cap-screen, .print-adapted-visual .cap-promo { padding: 2.5mm; border-color: #6b7280; background: white; color: #111827; }
  .print-adapted-visual .cap-screen strong, .print-adapted-visual .cap-promo strong { color: #111827; }
  .print-adapted-visual .cap-card-row, .print-adapted-visual .cap-process { padding: 2mm; border-color: #6b7280; background: white; color: #111827; }
  .print-adapted-choices { margin-top: 3mm; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2.2mm 6mm; }
  .print-adapted-choice { display: flex; align-items: flex-start; gap: 2mm; color: #111827; font-size: 9.5pt; line-height: 1.45; }
  .print-adapted-choice b { flex: 0 0 auto; }
  .print-answer-section { break-before: page; page-break-before: always; }
  .print-answer-section h2 { margin: 0 0 2mm; padding-bottom: 2mm; border-bottom: 2px solid #111827; font-size: 16pt; }
  .print-answer-note { margin: 0 0 5mm; color: #4b5563; font-size: 8.5pt; }
  .print-answer-item { margin-bottom: 5mm; padding-bottom: 3mm; border-bottom: 1px solid #d1d5db; break-inside: avoid; page-break-inside: avoid; }
  .print-answer-item h3 { margin: 0 0 1.5mm; color: #111827; font-size: 10.5pt; }
  .print-answer-item p { margin: 1mm 0; color: #111827; font-size: 8.5pt; line-height: 1.5; }
  .print-answer-item details { color: #111827; font-size: 8pt; }
  .print-answer-item summary { font-weight: 800; }
  .print-answer-item ul { margin: 1mm 0 0 5mm; padding-left: 4mm; }
  .print-answer-item li { margin: .7mm 0; line-height: 1.4; }
  @page { size: A4 portrait; margin: 12mm; }
}
