:root {
  /* 主要顏色在 /shared/theme.css，依 <body data-theme> 分類 */
  --card: #fff; --error: #c0654f;
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 -apple-system, "PingFang TC", "Helvetica Neue", sans-serif; color: var(--text); background: var(--bg); }
button { font: inherit; padding: 6px 12px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
button:hover { background: #faf8f3; }
button.primary { background: var(--accent-fill); color: #fff; border-color: var(--accent-fill); font-weight: 600; }
button.primary:hover { background: var(--accent); border-color: var(--accent); }
button.wide { width: 100%; margin-top: 8px; }
button.small { padding: 2px 8px; font-size: 14px; }
input, select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fffdfb; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-fill); box-shadow: 0 0 0 3px var(--accent-bg); }
input[type=number] { width: 64px; }
label { display: block; font-size: 15px; color: var(--muted); margin: 6px 0 2px; }
label > input:not([type=checkbox]):not([type=radio]), label > select { display: block; width: 100%; color: var(--text); margin-top: 2px; }
label.inline { display: inline-flex; align-items: center; gap: 4px; margin: 0 8px 0 0; color: var(--text); }
label.inline > input[type=number] { width: 60px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; }
.label { font-size: 15px; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; font-weight: 400; }
.center { text-align: center; }

.toolbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.toolbar { flex-wrap: wrap; gap: 8px; }
.toolbar .brand { white-space: nowrap; }
.toolbar .actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.toolbar button { white-space: nowrap; }
.brand { font-weight: 600; font-size: 18px; color: var(--accent); }
.navlink { font-weight: 400; font-size: 15px; margin-left: 12px; color: var(--accent); text-decoration: none; }
.notes-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; padding: 16px; }
table.notes { width: 100%; border-collapse: collapse; font-size: 15px; background: #fff; }
table.notes th, table.notes td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.notes th { color: var(--muted); font-weight: 500; }
table.notes td.wrong { color: var(--error); }
table.notes td.correct { color: var(--accent); }
.pill { display: inline-block; font-size: 13px; padding: 1px 7px; border-radius: 10px; background: var(--accent-bg); color: var(--accent); }
textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; width: 100%; }
.actions { display: flex; gap: 6px; }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; padding: 16px; }
.sidebar { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.card h2 { font-size: 17px; margin: 0 0 8px; color: var(--accent); display: flex; justify-content: space-between; align-items: baseline; }

.layouts { display: flex; gap: 6px; }
.layout-opt { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 6px 4px; text-align: center; font-size: 13px; cursor: pointer; color: var(--text); }
.layout-opt input { display: none; }
.layout-opt:has(input:checked) { border: 2px solid var(--accent); background: var(--accent-bg); }
.thumb { height: 30px; margin-bottom: 4px; display: flex; gap: 2px; }
.thumb.one::before { content: ""; flex: 1; border: 1px solid #999; }
.thumb.two::before, .thumb.two::after { content: ""; flex: 1; border: 1px solid #999; }
.thumb.halves { flex-direction: column; }
.thumb.halves::before, .thumb.halves::after { content: ""; flex: 1; border: 1px solid #999; }

.tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.tabs button { padding: 3px 10px; border-radius: 14px; font-size: 14px; }
.tabs button.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.subtypes label { display: block; color: var(--text); margin: 2px 0; }
#units label { margin-right: 8px; color: var(--text); }

.section-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 15px; gap: 6px; }
.section-row .ops { display: flex; gap: 2px; }
.section-row[draggable] { cursor: grab; }
.section-row.dragging { opacity: .4; }
.section-row.over { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-bg); border-radius: 6px; }
.section-row.selected { background: var(--accent-bg); }
.sheet .sec, .sheet .q { cursor: pointer; }
.sheet .sec.selected, .sheet .q.selected { outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 2px; }
.sheet .q[draggable], .sheet .sec[draggable="true"] { cursor: grab; }
.sheet .sec.over { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-bg); }
.sheet .q.dragging { opacity: .4; }
.sheet .q.over { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-bg); }
@media print { .sheet .q.over { outline: none; background: none; } }
#e-fields input, #e-fields textarea { width: 100%; margin-bottom: 4px; }
@media print { .sheet .selected { outline: none; } }
.grip { display: inline-block; width: 10px; height: 12px; margin-right: 6px; vertical-align: -1px;
  background: repeating-linear-gradient(to bottom, #bbb 0 2px, transparent 2px 4px); }
.stats { font-size: 14px; max-height: 160px; overflow: auto; }
.stats div { display: flex; justify-content: space-between; padding: 1px 0; }
.stats .x { color: var(--error); }

.preview { display: flex; flex-direction: column; align-items: center; }
.paper { background: #fff; width: 210mm; min-height: 297mm; padding: 13mm; box-shadow: 0 1px 6px rgba(0,0,0,.12); color: #000;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(297mm - 1px), #b9cfb3 calc(297mm - 1px), #b9cfb3 297mm);
  background-origin: border-box; }
.paper::after { content: "每 A4 一頁的大約分頁位置（虛線）；實際列印不會把一題切成兩半"; display: block; margin-top: 8mm; font-size: 9pt; color: #999; text-align: center; }
@media print { .paper { background-image: none; } .paper::after { display: none; } }
.paper-answers { margin-top: 16px; }
.paper-answers[hidden] { display: none; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal[hidden] { display: none; }
.dialog { background: #fff; width: min(820px, 92vw); max-height: 88vh; border-radius: 10px; display: flex; flex-direction: column; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 12px 16px; overflow: auto; }
.imp-item { border-top: 1px solid var(--line); padding: 6px 0; font-size: 15px; display: grid; grid-template-columns: 24px 1fr; gap: 6px; }
.imp-item .opts label { display: inline-flex; margin-right: 10px; color: var(--text); gap: 3px; }
.imp-item .tag { color: var(--muted); font-size: 13px; margin-left: 6px; }
.imp-item.off { opacity: .45; }
.log-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin: 10px 0; }
.log-grid label { display: flex; align-items: center; justify-content: center; gap: 3px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; margin: 0; color: var(--text); font-size: 15px; }
.log-grid label:has(input:checked) { background: #fbeae6; border-color: var(--error); }

/* 考卷本體 */
.sheet { font-family: Calibri, "PingFang TC", "Microsoft JhengHei", sans-serif; font-size: 12pt; line-height: 1.45; }
.sheet .head { text-align: center; }
.sheet .head .t { font-size: 1.4em; font-weight: 700; }
.sheet .head .s { color: #444; }
.sheet .fields { margin: 6pt 0 10pt; }
.sheet .fields .fld { position: relative; display: inline-block; cursor: move; user-select: none; touch-action: none; }
.sheet .fields .fld:hover { outline: 1px dashed var(--accent-fill); }
@media print { .sheet .fields .fld:hover { outline: none; } }
.sheet .body.twocol { column-count: 2; column-gap: 9mm; column-rule: 0.5pt solid #999; }
.sheet .sec { font-weight: 700; margin: 8pt 0 3pt; break-after: avoid; }
.sheet .q { margin: 0 0 4pt; break-inside: avoid; }
.sheet .q .opts { padding-left: 1.5em; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.5em; }
.sheet .q .opts.c4 { grid-template-columns: repeat(4, max-content); }
.sheet .q .opts.c2 { grid-template-columns: repeat(2, max-content); }
.sheet .q .opts.c1, .sheet .q .opts.long { grid-template-columns: minmax(0, 1fr); }
.sheet .q .opts span { overflow-wrap: anywhere; }
.sheet .q .opts.measure span, .sheet .q .opts.c4 span, .sheet .q .opts.c2 span { white-space: nowrap; }
.sheet .q .opts.c1 > span, .sheet .q .opts.long > span { padding-left: 1.6em; text-indent: -1.6em; }
.sheet .q .sub { padding-left: 1.5em; }
.sheet .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10pt; }
.sheet .cut { border-top: 1pt dashed #888; margin: 10pt 0; text-align: center; font-size: 9pt; color: #666; line-height: 0; }
.sheet .cut span { background: #fff; padding: 0 6pt; }
.sheet .half { break-inside: avoid; }
.sheet .answers { column-span: all; }
.sheet .ans { color: #d00; font-weight: 700; }
.sheet .fill { color: #d00; font-weight: 700; border-bottom: 0.5pt solid #000; padding: 0 4pt; }
.sheet .blank { display: inline-block; border-bottom: 0.5pt solid #000; height: 1em; vertical-align: baseline; }
.sheet .paren { display: inline-block; }
.sheet .q.mcq { display: grid; grid-template-columns: 2.6em minmax(0, 1fr); column-gap: 0; }
.sheet .q.mcq .mcbody { min-width: 0; }
.sheet .line { border-bottom: 0.5pt solid #000; min-height: 1.6em; margin: 2pt 0 2pt 1.5em; }
.sheet .line .fill { border-bottom: none; }
.sheet .answers .t { font-weight: 700; margin-bottom: 6pt; }
.sheet .answers div { margin: 0 0 2pt; }
.sheet .boxes { font-size: 9pt; color: #444; margin-top: 6pt; }

@media print {
  @page { size: A4; margin: 13mm; }
  body { background: #fff; }
  .toolbar, .sidebar, .screen-only, .modal { display: none !important; }
  .layout { display: block; padding: 0; }
  .preview { display: block; }
  .paper { width: 100%; min-height: 0; padding: 0; margin: 0; box-shadow: none; }
  .paper-answers { margin: 0; break-before: page; page-break-before: always; }
}

.exam-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.exam-row .meta { color: var(--muted); font-size: 14px; }
.sheet .passage { white-space: pre-line; margin: 4pt 0 6pt; }
.sheet .wordbank { border: 0.5pt solid #666; padding: 3pt 6pt; margin: 2pt 0 6pt; }
.sheet .wordbank span { display: inline-block; margin-right: 1.4em; }


.sheet table.bilingual { width: 100%; border-collapse: collapse; margin: 2pt 0 6pt; font-size: 0.95em; }
.sheet table.bilingual td { border: 0.5pt solid #777; padding: 2pt 5pt; vertical-align: top; }
.sheet table.bilingual td.zh { width: 42%; }
.sheet .passage.boxed { border: 0.5pt solid #555; padding: 4pt 8pt; }
.sheet .q u.hint { text-decoration: none; border-bottom: 0.5pt solid #000; padding: 0 2pt; letter-spacing: 1pt; }

.dialog.wide { width: min(1100px, 94vw); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.tpl-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; display: flex; flex-direction: column; gap: 6px; }
.tpl-card h3 { margin: 0; font-size: 16px; }
.tpl-card .desc { font-size: 14px; color: var(--muted); min-height: 2.6em; }
.thumb-wrap { width: 100%; aspect-ratio: 210 / 297; overflow: hidden; border: 1px solid var(--line); background: #fff; position: relative; }
.thumb-sheet { position: absolute; left: 0; top: 0; width: 210mm; min-height: 297mm; padding: 13mm; background: #fff; transform-origin: top left; color: #000; }

.ribbon { width: 210mm; max-width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; position: sticky; top: 56px; z-index: 4; }
.ribbon[hidden] { display: none; }
.ribbon-head { display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.ribbon-title { font-weight: 600; font-size: 15px; }
.ribbon-head .muted { flex: 1; }
.ribbon.collapsed .ribbon-body { display: none; }
.ribbon.collapsed .ribbon-head { border-bottom: none; }
.ribbon-body { padding: 6px 12px 8px; }
.ribbon-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 4px 0; }
.ribbon-row.fields label { display: inline-flex; align-items: center; gap: 4px; margin: 0; color: var(--text); font-size: 14px; }
.ribbon-row.fields input { width: 200px; }
.ribbon-row.fields label:first-child input { width: 420px; }
#e-fields input, #e-fields textarea { margin-bottom: 0; }
@media print { .ribbon { display: none !important; } }

[hidden] { display: none !important; }
.n-input { width: 52px; padding: 2px 4px; font-size: 14px; }

.sheet .ed { outline: none; border-radius: 2px; }
.sheet .ed:hover { background: #fff6d6; }
.sheet .ed:focus { background: #fff1bf; box-shadow: 0 0 0 1px #e0b000; }
button:disabled { opacity: .45; cursor: default; }
@media print { .sheet .ed { background: none !important; box-shadow: none !important; } }

.card h2.collapsible { cursor: pointer; user-select: none; }
.card h2.collapsible::after { content: "收合"; font-size: 13px; color: var(--muted); font-weight: 400; margin-left: auto; }
.card.collapsed h2.collapsible::after { content: "展開"; }
.card.collapsed > *:not(h2) { display: none; }
.card.collapsed h2 { margin-bottom: 0; }

html[lang="en"] .card h2.collapsible::after { content: "Collapse"; }
html[lang="en"] .card.collapsed h2.collapsible::after { content: "Expand"; }
html[lang="en"] .paper::after { content: "Dashed lines show the approximate A4 page breaks; printing never splits a question."; }

/* 學生選單 */
.student-row { align-items: flex-end; gap: 8px; }
.student-row label { flex: 1; }
.student-row select { width: 100%; }
.student-row .navlink { white-space: nowrap; padding-bottom: 6px; }
.small-note { font-size: 14px; margin: 6px 0 0; }

/* 匯入會考題 */
.cap-text { white-space: pre-wrap; font: 15px/1.5 "Times New Roman", serif; background: var(--bg); padding: 8px; border-radius: 6px; }
.cap-q { margin-top: 4px; }

/* AI 出題審核 */
.draft { margin-bottom: 12px; }
.draft-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.draft-head label { margin-left: auto; }
.draft-opts { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 4px 0 6px; }
.draft-opts input { width: 150px; }
.draft-q { margin-top: 6px; }
.draft label.inline { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
