/* Layout: one soft, centered column. Rounded panels, a highlighter-marked title, and a gently ruled upload area. */
:root {
  --bg: #FFF9F3;          /* 極淡的杏桃白 */
  --surface: #FFFFFF;
  --ink: #5A4036;         /* 柔和的暖棕 */
  --ink-soft: #876B5E;
  --grid: #FBEEE2;        /* 稿紙格線，很淡 */
  --line: #F2DDCC;
  --accent: #FFC59B;      /* 主要按鈕，蜜桃色 */
  --accent-ink: #B3501B;  /* 需要當文字、外框時用的深一點的橘 */
  --accent-deep: #F0A675; /* 按鈕底部厚度 */
  --on-accent: #5A2D12;
  --bar: #F9A870;         /* 分數長條 */
  --hi: #FFF0B8;          /* 螢光筆黃 */
  --coral: #CC4A68;       /* 老師的紅筆，偏玫瑰 */
  --coral-soft: #FFEDF0;
  --shadow: 0 8px 28px rgba(160, 110, 70, 0.10);
  color-scheme: light;  /* 固定為淺色，不跟隨裝置的深色模式 */

  --f-display: "LXGW WenKai TC", "Kaiti TC", "BiauKai", "DFKai-SB", serif;
  --f-body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
/* 手機上表單欄位不可撐出外框（iOS Safari 的搜尋框、長選項的下拉選單） */
input, select, textarea { max-width: 100%; min-width: 0; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.75;
  padding-inline: 16px;
  padding-block: 44px 28px;
}
.shell { max-width: 42rem; margin-inline: auto; }

/* Header */
.masthead { display: flex; flex-direction: column; gap: 12px; margin-bottom: 26px; text-align: center; align-items: center; }
h1 {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 7vw, 2.7rem);
  line-height: 1.3;
  letter-spacing: 0.03em;
  margin: 0;
  text-wrap: balance;
}
h1 .hl { background: linear-gradient(transparent 58%, var(--hi) 58%); padding-inline: 2px; }
.lede { margin: 0; color: var(--ink-soft); max-width: 30rem; text-wrap: balance; }

/* Form */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px;
  box-shadow: var(--shadow);
}
form { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-weight: 700; }
.opt { font-weight: 400; color: var(--ink-soft); }
.hint { margin: 0; font-size: 0.875rem; color: var(--ink-soft); }
select, input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  width: 100%;
  min-height: 48px;
}
select:focus-visible, input[type="text"]:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent-ink);
  outline-offset: 2px;
}
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* Upload area, faintly ruled like 作文稿紙 */
.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 30px 16px;
  border: 2px dashed var(--line);
  border-radius: 18px;
  cursor: pointer;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 26px 26px;
  background-position: center;
  transition: border-color 0.15s, transform 0.15s;
}
.drop:hover { border-color: var(--accent); }
.plus {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  font-size: 1.6rem; line-height: 1; font-weight: 400;
}
.drop strong { font-family: var(--f-display); font-size: 1.15rem; background: var(--bg); padding: 0 8px; border-radius: 6px; }
.drop span.sub { color: var(--ink-soft); font-size: 0.9rem; background: var(--bg); padding: 0 8px; border-radius: 6px; }
.drop.over { border-color: var(--accent); border-style: solid; transform: scale(1.01); }
.sr:focus-visible + .drop { border-color: var(--accent); border-style: solid; outline: 3px solid var(--accent-ink); outline-offset: 2px; }

#filelist { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
#filelist:empty { display: none; }
.file {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
}
.thumb {
  width: 54px; height: 54px; border-radius: 10px; overflow: hidden;
  display: grid; place-items: center;
  background: var(--hi);
  font-weight: 700; font-size: 0.8rem; color: var(--ink);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.meta { min-width: 0; }
.meta .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.meta .sub { font-size: 0.8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tools button {
  font: inherit; font-size: 0.85rem;
  min-width: 44px; min-height: 40px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.tools button:disabled { opacity: 0.35; cursor: default; }
.tools .rm { color: var(--coral); }

#msg { margin: 0; color: var(--coral); font-weight: 500; }
#msg:empty { display: none; }

.actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.primary {
  font: inherit; font-weight: 700; font-size: 1.05rem; letter-spacing: 0.06em;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  min-height: 54px;
  padding: 0 44px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-deep);
  transition: transform 0.1s, box-shadow 0.1s;
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 5px 0 var(--accent-deep); }
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-deep); }
.linkbtn {
  font: inherit; font-size: 0.9rem;
  background: none; border: 0; padding: 8px 4px;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Loading */
#loading { text-align: center; padding-block: 56px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.dots { display: flex; gap: 10px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); animation: hop 1.1s ease-in-out infinite; }
.dots i:nth-child(2) { background: var(--hi); animation-delay: 0.15s; }
.dots i:nth-child(3) { background: var(--coral); animation-delay: 0.3s; }
@keyframes hop { 0%, 70%, 100% { transform: translateY(0); } 35% { transform: translateY(-14px); } }
#loading h2 { font-family: var(--f-display); font-size: 1.4rem; margin: 0; }
#loading p { margin: 0; color: var(--ink-soft); font-variant-numeric: tabular-nums; max-width: 24rem; }

/* Result */
#result { display: flex; flex-direction: column; gap: 22px; }
.demo-note {
  background: var(--hi); color: var(--ink);
  border-radius: 14px; padding: 10px 16px; font-size: 0.9rem; font-weight: 500;
}
.res-head { display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.res-head h2 { font-family: var(--f-display); font-size: 1.8rem; margin: 0; line-height: 1.3; }
.res-meta { margin: 4px 0 0; color: var(--ink-soft); font-size: 0.9rem; }
.res-meta.band-note { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--coral-soft); color: var(--coral); max-width: 34em; }
.score {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 8rem; aspect-ratio: 1;
  max-width: 100%;
  border: 3px solid var(--coral);
  background: var(--coral-soft);
  border-radius: 50%;
  color: var(--coral);
  transform: rotate(-6deg);
  font-family: var(--f-display);
  line-height: 1;
}
.score b { font-size: 3.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.score small { font-size: 0.85rem; margin-top: 4px; }

.block {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.block h3 { font-family: var(--f-display); font-size: 1.25rem; margin: 0; }
.block h3 span { background: linear-gradient(transparent 62%, var(--hi) 62%); padding-inline: 2px; }
.block p { margin: 0; }
.rows { display: flex; flex-direction: column; gap: 18px; }
.row-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 700; margin-bottom: 4px; }
.lv {
  flex: none;
  min-width: 4.5em; padding: 2px 12px;
  border-radius: 999px; text-align: center;
  font-family: var(--f-display); font-size: 1rem;
}
.lv-優 { background: var(--coral-soft); color: var(--coral); }
.lv-良 { background: var(--hi); color: var(--ink); }
.lv-可 { background: var(--grid); color: var(--accent-ink); }
.lv-待加強 { background: var(--bg); color: var(--ink-soft); border: 1.5px dashed var(--line); }
.row-note { color: var(--ink-soft); font-size: 0.95rem; }
.teacher { font-family: var(--f-display); font-size: 1.15rem; line-height: 1.9; color: var(--coral); }
.ending { background: var(--bg); border-radius: 14px; padding: 12px 14px; font-family: var(--f-display); font-size: 1.1rem; }

.fix { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--bg); border-radius: 14px; }
.fix .line { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.fix .o { color: var(--coral); text-decoration: line-through; text-decoration-thickness: 2px; }
.fix .n { color: var(--accent-ink); font-weight: 700; }
.fix .why { font-size: 0.9rem; color: var(--ink-soft); }
.fix .ctype { font-size: 0.75rem; font-weight: 700; color: var(--ink-soft); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; background: var(--surface); }

.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 12px; }
.pair > div { background: var(--bg); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.pair .tag { display: block; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-soft); margin-bottom: 4px; }
.pair .after { background: var(--grid); }
.pair .after .tag { color: var(--accent-ink); }

details { border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
summary { cursor: pointer; padding: 14px 20px; font-weight: 700; }
.script { padding: 0 20px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.unsure { margin: 0; padding: 0 20px 18px 40px; font-size: 0.9rem; color: var(--ink-soft); }
mark { background: var(--coral-soft); color: var(--coral); padding: 0 4px; border-radius: 4px; font-weight: 700; }
.caution { font-size: 0.9rem; color: var(--ink-soft); text-align: center; }
.again { align-self: center; }

/* Footer */
footer {
  max-width: 42rem; margin: 40px auto 0; padding-top: 16px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 18px;
  font-size: 0.85rem; color: var(--ink-soft); text-align: center;
}

@media (max-width: 480px) {
  .panel { padding: 20px 16px; }
  .block { padding: 18px 16px; }
  .primary { width: 100%; }
  .actions { flex-direction: column; align-items: stretch; gap: 4px; }
  .linkbtn { text-align: center; }
  .res-head { justify-content: center; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  .dots i { animation: none; }
  .primary, .drop { transition: none; }
}

/* ── 登入後的共用頂列 ───────────────────────────── */
input[type="password"] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 14px;
  padding: 10px 14px; width: 100%; min-height: 48px;
}
input[type="password"]:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: -24px 0 28px; font-size: 0.9rem;
}
.topbar .brand { font-family: var(--f-display); font-size: 1.15rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.topbar .who { display: flex; align-items: center; gap: 12px; color: var(--ink-soft); }
.topbar form { display: inline; }
.topbar .linkbtn { padding: 0; }
a { color: var(--accent-ink); }

/* 登入頁 */
.login { max-width: 24rem; margin-inline: auto; }
.login form { gap: 18px; }
.login .primary { width: 100%; }

/* 首頁 */
.stack { display: flex; flex-direction: column; gap: 22px; }
.quota { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.quota .big { font-family: var(--f-display); font-size: 2.4rem; line-height: 1; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.quota .big small { font-size: 1rem; color: var(--ink-soft); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px; border-radius: 18px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
}
a.card:hover { border-color: var(--accent); }
.card strong { font-family: var(--f-display); font-size: 1.2rem; }
.card span { font-size: 0.9rem; color: var(--ink-soft); }
.card.soon { background: var(--bg); box-shadow: none; border-style: dashed; }
.card .tag { align-self: flex-start; font-size: 0.75rem; font-weight: 700; padding: 0 8px; border-radius: 999px; background: var(--grid); color: var(--accent-ink); }

/* 批改紀錄列表 */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history a {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  padding: 10px 14px; border-radius: 14px; background: var(--bg); color: var(--ink); text-decoration: none;
}
.history a:hover { background: var(--grid); }
.history .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .d { grid-column: 1; font-size: 0.8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.history .s { grid-row: 1 / span 2; grid-column: 2; font-family: var(--f-display); font-size: 1.3rem; color: var(--coral); font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { font-family: var(--f-body); font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line); }
.empty { color: var(--ink-soft); margin: 0; }

/* 預檢未通過 */
.reject { display: flex; flex-direction: column; gap: 14px; }
.reject .actions { justify-content: flex-start; }

/* 批改詳情的原稿縮圖 */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: 10px; }
.pages a { display: block; border-radius: 12px; overflow: hidden; border: 1.5px solid var(--line); background: var(--bg); aspect-ratio: 3 / 4; }
.pages img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pages .pdf { display: grid; place-items: center; height: 100%; font-weight: 700; color: var(--ink); text-decoration: none; background: var(--hi); }
.back { font-size: 0.9rem; }
.back-row { margin: 0 0 8px; }

/* ── 老師介面 ─────────────────────────────────── */
input[type="number"], input[type="email"] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 14px;
  padding: 10px 14px; width: 100%; min-height: 48px;
}
input[type="number"]:focus-visible, input[type="email"]:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
.topbar .role { font-family: var(--f-body); font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--coral-soft); color: var(--coral); vertical-align: middle; }

.flash { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.flash li { padding: 10px 16px; border-radius: 14px; background: var(--hi); font-weight: 500; }
.flash .flash-error { background: var(--coral-soft); color: var(--coral); }

a.primary { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.primary.small { min-height: 44px; padding: 0 22px; font-size: 0.95rem; letter-spacing: 0.02em; }
.danger {
  font: inherit; font-weight: 700; min-height: 44px; padding: 0 22px; border-radius: 999px; cursor: pointer;
  background: var(--surface); color: var(--coral); border: 1.5px solid var(--coral);
}
.danger:hover { background: var(--coral-soft); }
.actions.left { justify-content: flex-start; }
.form-stack { gap: 18px; }
.field-error { margin: 0; color: var(--coral); font-size: 0.9rem; font-weight: 500; }
.field .hint ul { margin: 4px 0 0; padding-left: 20px; }

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

.stats { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 10px; }
.stats div { background: var(--bg); border-radius: 14px; padding: 12px 14px; }
.stats dt { font-size: 0.85rem; color: var(--ink-soft); }
.stats dd { margin: 2px 0 0; font-family: var(--f-display); font-size: 1.8rem; line-height: 1.2; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.stats dd small { font-size: 0.9rem; color: var(--ink-soft); }

.filters { display: flex; flex-direction: row; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input { flex: 1 1 12rem; width: auto; }
.filters select { flex: 0 1 14rem; width: auto; }

.roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.roster a {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; align-items: center;
  padding: 12px 14px; border-radius: 14px; background: var(--bg); color: var(--ink); text-decoration: none;
}
.roster a:hover { background: var(--grid); }
.roster a.off { opacity: 0.6; }
.roster .who { display: flex; flex-direction: column; min-width: 0; }
.roster .who strong { font-size: 1.05rem; }
.roster .sub { font-size: 0.8rem; color: var(--ink-soft); }
.roster .nums { display: flex; gap: 14px; font-family: var(--f-display); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.roster .nums span { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.roster .nums small { font-family: var(--f-body); font-size: 0.7rem; color: var(--ink-soft); }
.roster .flags { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.roster .flags:empty { display: none; }
.badge.warn { background: var(--coral-soft); color: var(--coral); border-color: var(--coral-soft); }

@media (max-width: 480px) {
  .roster a { grid-template-columns: 1fr; }
  .roster .nums { justify-content: space-between; }
}

/* 錯誤頁（404／500／403） */
.errorpage { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding-block: 40px; }
.errorpage .code { margin: 0; font-family: var(--f-display); font-size: 4rem; line-height: 1; color: var(--coral); transform: rotate(-4deg); }
.errorpage h1 { font-size: clamp(1.6rem, 6vw, 2.1rem); }

/* 訂正全文：原字畫刪除線，紅字加底線（只靠顏色分不出時也看得出來） */
.corrected { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 2; background: var(--bg); border-radius: 14px; padding: 12px 14px; }
.corrected del { color: var(--ink-soft); text-decoration: line-through; text-decoration-color: var(--coral); text-decoration-thickness: 1.5px; }
.corrected ins { color: var(--coral); font-weight: 700; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px; }

/* ── 額度、題庫、短文 ─────────────────────────── */
.quota-box { display: flex; flex-direction: column; gap: 10px; }
.quota-items { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 10px; }
.quota-items > div { display: flex; flex-direction: column; background: var(--bg); border-radius: 14px; padding: 10px 14px; }
.quota-items .big { font-family: var(--f-display); font-size: 2rem; line-height: 1.2; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.quota-items .big small { font-size: 0.9rem; color: var(--ink-soft); }
.ql { font-size: 0.85rem; color: var(--ink-soft); font-weight: 700; }

.kind { font-size: 0.72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; vertical-align: middle; }
.kind-long { background: var(--grid); color: var(--accent-ink); }
.kind-short { background: var(--hi); color: var(--ink); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { padding: 8px 16px; border-radius: 999px; background: var(--surface); border: 1.5px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 500; font-size: 0.9rem; }
.tab:hover { border-color: var(--accent); }

.topic-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 10px; }
.topic-list a { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 14px; border-radius: 14px; background: var(--bg); color: var(--ink); text-decoration: none; border: 1.5px solid transparent; }
.topic-list a:hover { border-color: var(--accent); }
.topic-list strong { font-family: var(--f-display); font-size: 1.1rem; }
.topic-list span:not(.badge) { font-size: 0.88rem; color: var(--ink-soft); }

.topic-card { margin-bottom: 22px; }
.hints { margin: 4px 0 0; padding-left: 20px; color: var(--ink); }
.hints li { margin: 2px 0; }

textarea {
  font: inherit; font-size: 1.05rem; line-height: 1.9; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; width: 100%; resize: vertical; min-height: 14rem;
}
textarea:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
/* 二選一的切換（作文類型、交件方式）：外觀沿用 .tab */
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field > legend { padding: 0; margin-bottom: 6px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg .tab { cursor: pointer; padding: 10px 20px; font-size: 1rem; }
.seg .tab:focus-within { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
.counter { margin: 0; font-size: 0.9rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.counter.ok { color: #3f7a3a; font-weight: 700; }
.counter.over { color: var(--coral); font-weight: 700; }
.primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 var(--accent-deep); }

.polished { white-space: pre-wrap; line-height: 2; }
.good { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 12px; }
.good .copy { font-family: var(--f-display); font-size: 1.15rem; line-height: 1.9; color: var(--ink); }

/* 老師端：分類統計表、點數紀錄 */
.kind-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.kind-table th, .kind-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.kind-table thead th { color: var(--ink-soft); font-weight: 700; font-size: 0.8rem; }
.ledger { box-shadow: none; margin-top: 6px; overflow-x: auto; }
.ledger .kind-table { min-width: 34rem; }
@media (max-width: 480px) {
  .block .kind-table { display: block; overflow-x: auto; }
  .block .kind-table th[scope="row"] { white-space: nowrap; }
}
.field input[type="checkbox"] { width: 1.2rem; height: 1.2rem; }

/* 頂列在手機寬度時整塊換行，不要把名字或額度切成兩半 */
.topbar .who { flex-wrap: wrap; justify-content: flex-end; row-gap: 2px; }
.topbar .who > * { white-space: nowrap; }

/* ── 老師介面：左側選單版面 ───────────────────── */
.shell.wide { max-width: 72rem; }
footer { max-width: 72rem; }
.console { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: 28px; align-items: start; }
.sidenav {
  position: sticky; top: 16px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.sidenav a {
  display: block; padding: 10px 14px; border-radius: 12px;
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.sidenav a:hover { background: var(--bg); }
.sidenav a[aria-current="page"] { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.sidenav-note { margin-top: 6px; padding: 4px 14px; font-size: 0.75rem; color: var(--coral); font-weight: 700; }
.console-main { min-width: 0; }
.console-main .masthead { align-items: flex-start; text-align: left; margin-bottom: 20px; }
.console-main h1 { font-size: clamp(1.6rem, 5vw, 2.1rem); }

@media (max-width: 760px) {
  .console { grid-template-columns: 1fr; gap: 16px; }
  .sidenav { position: static; flex-direction: row; overflow-x: auto; padding: 6px; scrollbar-width: none; }
  .sidenav a { flex: none; padding: 8px 14px; }
  .sidenav-note { display: none; }
}

/* 總覽頁的學生資訊卡 */
.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 16px; }
.insights .block { height: 100%; }
.insights .wide-block { grid-column: 1 / -1; }
.mini { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mini a {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 12px; background: var(--bg); color: var(--ink); text-decoration: none;
}
.mini a:hover { background: var(--grid); }
.mini .n { font-family: var(--f-display); font-size: 1.15rem; color: var(--accent-ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini .tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.count-badge { font-family: var(--f-body); font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); margin-left: 6px; }
.section-title { font-family: var(--f-display); font-size: 1.2rem; margin: 8px 0 0; }
.kind-table tr.picked { background: var(--hi); }

/* 學生端左側選單：內容欄維持原本適合閱讀的寬度 */
.student-main { max-width: 44rem; }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }

/* 搜尋框：和其他輸入框同樣的圓角與底色，左側加放大鏡 */
input[type="search"] {
  font: inherit; color: var(--ink);
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23876B5E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px center; background-size: 18px;
  border: 1.5px solid var(--line); border-radius: 14px;
  padding: 10px 14px 10px 42px; width: 100%; min-height: 48px;
  -webkit-appearance: none; appearance: none;
}
input[type="search"]::placeholder { color: var(--ink-soft); opacity: 0.8; }
input[type="search"]:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }

/* ── 難易度標籤：簡易淡綠、中等土黃、較難紅 ─────── */
.diff { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.diff-easy { background: #E2F3DF; color: #2E6B2A; }
.diff-medium { background: #F3E4B8; color: #7A5A12; }
.diff-hard { background: #FBDCDC; color: #B3261E; }
/* 文體：棕底白字，形狀和難易度標籤相同；題目卡上放在右上角 */
.genre { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; background: #8B5A3C; color: #fff; }
.topic-head .genre { margin-left: auto; }
.topic-list span.genre { color: #fff; font-size: 0.75rem; }
.topic-card .genre { margin-right: 6px; }

/* 題庫管理：拖拉排序 */
.sortable { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sort-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 14px; background: var(--bg); border: 1.5px solid transparent;
}
.sort-item:hover { border-color: var(--line); }
.handle { cursor: grab; color: var(--ink-soft); font-size: 1.1rem; letter-spacing: -3px; padding: 4px 6px; user-select: none; touch-action: none; }
.handle:active { cursor: grabbing; }
.sort-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; color: var(--ink); text-decoration: none; }
.sort-body .t { font-weight: 500; }
.diffs { display: flex; flex-wrap: wrap; gap: 4px; }
.sort-tools { display: flex; align-items: center; gap: 4px; }
.sort-tools .move {
  font: inherit; width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1.5px solid var(--line);
}
.sort-tools .move:hover { border-color: var(--accent); }
.sort-ghost { opacity: 0.4; background: var(--hi); }
.sort-status {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  margin: 0; padding: 10px 18px; border-radius: 999px; background: var(--ink); color: #fff;
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 10;
}
.sort-status.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sort-status.error { background: var(--coral); }
@media (max-width: 480px) {
  .sort-item { grid-template-columns: auto minmax(0, 1fr); }
  .sort-tools { grid-column: 2; justify-content: flex-start; }
}

/* 學生端：難易度篩選 */
.topic-list .diff { align-self: flex-start; }
.topic-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tab.tab-easy.on { background: #E2F3DF; border-color: #9CCB95; color: #2E6B2A; }
.tab.tab-medium.on { background: #F3E4B8; border-color: #D6BB6B; color: #7A5A12; }
.tab.tab-hard.on { background: #FBDCDC; border-color: #E59A9A; color: #B3261E; }
.topic-card .diff { margin-right: 6px; }
.sort-drag { opacity: 0.9 !important; box-shadow: var(--shadow); background: var(--surface); }

/* ── 學習歷程（學生端）：以鼓勵為主，沿用網站原本的區塊、列表與標籤 ── */
.kind-poem { background: var(--coral-soft); color: #A83652; }
.month-cheer { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.cheer-body { flex: 1; min-width: 12rem; }
.month-pick select { width: auto; }
@media (max-width: 560px) { .month-pick { flex-basis: 100%; } .month-pick select { width: 100%; } }
.cheer-icon { flex: none; display: grid; place-items: center; width: 3.4rem; height: 3.4rem; border-radius: 50%; background: var(--hi); font-size: 1.7rem; }
.cheer-title { margin: 0; font-family: var(--f-display); font-size: 1.3rem; font-weight: 700; }
.cheer-text { margin: 2px 0 0; color: var(--ink-soft); }
.growth-sub { margin: 14px 0 8px; font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.medal-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 10px; }
.medal-grid a { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 10px; align-items: center; padding: 10px 12px; border-radius: 14px; background: var(--bg); color: var(--ink); text-decoration: none; }
.medal-grid a:hover { background: var(--grid); }
.medal-grid .medal { grid-row: 1 / span 2; font-size: 1.8rem; line-height: 1; }
.medal-grid .mt { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.medal-grid .md { font-size: 0.78rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.praise { margin: 8px 0 0; padding: 12px 14px; border-radius: 14px; background: var(--hi); }
.good-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.good-list li { background: var(--bg); border-radius: 14px; padding: 10px 14px; border-left: 4px solid var(--accent); }
.good-list p { margin: 0; }
.good-list .copy { font-family: var(--f-display); font-size: 1.05rem; }
.good-list .from { font-size: 0.78rem; color: var(--ink-soft); }
.works .t { white-space: normal; }
.works .cheer { grid-column: 1; font-size: 0.8rem; font-weight: 700; color: var(--accent-ink); }
.works .s { font-size: 1.6rem; }

/* ── 學習歷程（老師端）：沿用老師端的數字小格與區塊；圖表線用深橘、長條用分數長條色 ── */
.range-pick { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-direction: row; }
.range-pick label { font-weight: 700; font-size: 0.9rem; }
.range-pick select { width: auto; }
.tags-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.stats dd.note { font-family: var(--f-body); font-size: 0.8rem; color: var(--ink-soft); line-height: 1.6; }
.period-bars { list-style: none; margin: 0; padding: 0; display: flex; align-items: flex-end; gap: 6px; overflow-x: auto; }
.period-bars li { flex: 1 0 2.6rem; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--ink-soft); }
.period-bars .n { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 700; }
.period-bars .bar { display: flex; align-items: flex-end; width: 100%; max-width: 2.4rem; height: 6rem; background: var(--grid); border-radius: 6px; }
.period-bars .bar span { display: block; width: 100%; background: var(--bar); border-radius: 6px; min-height: 2px; }
.period-bars .l { white-space: nowrap; }
.growth-chart { width: 100%; height: auto; display: block; overflow: visible; margin-top: 4px; }
.dim-title { margin: 14px 0 8px; font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; list-style: none; margin: 0; padding: 0; font-weight: 400; font-size: 0.8rem; color: var(--ink-soft); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dim-rows { display: flex; flex-direction: column; gap: 8px; }
.dim-row { display: grid; grid-template-columns: 7rem minmax(0, 1fr) 4.8rem; gap: 10px; align-items: center; font-size: 0.85rem; }
.dim-row .dn { color: var(--ink-soft); font-size: 0.8rem; text-align: right; }
.level-stack, .band-bar { display: flex; gap: 2px; height: 14px; }
.level-stack span { border-radius: 4px; min-width: 4px; }
.band-bar { background: var(--grid); border-radius: 4px; }
.band-bar span { background: var(--bar); border-radius: 4px; }
.fix-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fix-bars li { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) 2rem; gap: 10px; align-items: center; font-size: 0.85rem; }
.fix-bars .b span { display: block; height: 14px; background: var(--bar); border-radius: 0 4px 4px 0; }
.fix-bars .n { text-align: right; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.chart-tip { position: absolute; z-index: 20; background: var(--ink); color: #fff; font-size: 0.8rem; padding: 5px 9px; border-radius: 8px; pointer-events: none; max-width: 16rem; }
/* 「進步」標籤；不用 .good，那是好句抄寫列表的樣式 */
.badge.trend-up { background: #E2F3DF; color: #2E6B2A; border-color: #E2F3DF; }
@media (max-width: 480px) {
  .dim-row { grid-template-columns: 5.5rem minmax(0, 1fr) 4rem; }
  .range-pick { justify-content: flex-start; }
}
.stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 640px) { .stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 480px) { .stats.three div { padding: 10px; } .stats.three dd { font-size: 1.5rem; } }
.roster .nums .emo { font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; font-size: 1.15rem; line-height: 1.3; }

/* 老師會怎麼寫：像稿紙上的示範作文，題目前空四格、每段開頭空兩格 */
.model-essay { background: var(--bg); border-radius: 14px; padding: 14px 16px; font-family: var(--f-display); font-size: 1.08rem; line-height: 2; }
.model-essay p { margin: 0 0 6px; text-indent: 2em; }
.model-essay .me-title { text-indent: 4em; font-weight: 700; margin-bottom: 10px; }
.model-essay .waiting { font-family: var(--f-body); font-size: 0.9rem; text-indent: 0; }

/* 作文模範生排行榜：學生首頁一個、老師端國小組與國中組並排 */
.board-head { text-align: center; }
.board-title { font-family: var(--f-display); font-size: 1.6rem; margin: 0; letter-spacing: 0.08em; }
.board-title::before, .board-title::after { content: "✦"; color: var(--accent-deep); font-size: 0.9rem; margin: 0 10px; vertical-align: middle; }
.board-sub { margin: 4px 0 0; color: var(--ink-soft); font-size: 0.9rem; }
.board-table th, .board-table td { text-align: center; }
.board-table th[scope="row"] { font-weight: 700; }
.board-table .rank { width: 4em; font-weight: 700; }
.board-table .rank .emo { font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; font-size: 1.3rem; line-height: 1; }
.board-table tbody tr:nth-child(-n+3) { background: #FFFBF2; }
.board-table tr.me, .board-table tbody tr.me { background: var(--hi); box-shadow: inset 4px 0 0 var(--accent-ink); }
.board-table .me-tag { color: var(--accent-ink); font-size: 0.85rem; margin-left: 2px; }
.board-table a { color: var(--ink); }
.board-empty, .board-mine { text-align: center; }
.board-mine { color: var(--accent-ink); font-weight: 700; font-size: 0.95rem; }
.boards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 900px) { .boards { grid-template-columns: 1fr; } }
.board-month { display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 10px; }
.board-month label { white-space: nowrap; }
@media (max-width: 560px) { .block.board .board-table { display: table; } .board-table th, .board-table td { padding: 8px 6px; } }
