:root {
  --ink: #2b2b2b;          /* 鉛筆灰：內文 */
  --muted: #646a73;
  --line: #d9dce1;
  --bg: #f3f4f6;
  --paper: #ffffff;
  --orange: #fd8225;       /* 品牌橘：色塊、線條 */
  --orange-text: #b35300;  /* 橘色文字 */
  --orange-soft: #fff1e4;
  --red: #e4572e;          /* 教練紅筆 */
  --red-text: #b4381a;
  --green: #2e7d4f;
  --hand: "LXGW WenKai TC", "Kaiti TC", "DFKai-SB", cursive;
  --sans: "Microsoft JhengHei", "微軟正黑體", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 var(--sans);
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }

/* ---------- 頂部 ---------- */
.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px 0;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "brand meta" "tabs tabs";
  gap: 10px 32px;
  align-items: center;
}
.brand { grid-area: brand; display: flex; flex-direction: column; }
.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.3;
  padding-left: 14px;
  border-left: 6px solid var(--orange);
}
.saved { font-size: 13px; color: var(--muted); padding-left: 20px; min-height: 1.4em; }
.saved.warn { color: var(--red-text); }
.meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: flex-end; }
.meta label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.meta input {
  border: 0; border-bottom: 1.5px solid var(--line);
  padding: 4px 2px; min-width: 0; width: 15em; background: transparent; color: var(--ink);
}
.meta .m-date input { width: 10em; }
.meta input:focus { border-bottom-color: var(--orange); outline: none; }
.tabs { grid-area: tabs; display: flex; gap: 4px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 10px 16px; font-size: 15px; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab[aria-current="page"] { color: var(--ink); font-weight: 700; border-bottom-color: var(--orange); }

/* ---------- 逐條檢核 ---------- */
.check {
  max-width: 1200px; margin: 0 auto; padding: 24px;
  display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 24px; align-items: start;
}
.rulelist {
  position: sticky; top: 16px;
  max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 0 12px;
}
.list-toggle { display: none; }
.group-name { font-size: 13px; font-weight: 700; color: var(--orange-text); margin: 12px 16px 4px; }
.rules { list-style: none; margin: 0; padding: 0; }
.rule-btn {
  width: 100%; display: grid; grid-template-columns: 2em 1fr 28px; gap: 6px; align-items: center;
  text-align: left; background: none; border: 0; cursor: pointer;
  padding: 7px 16px; font-size: 14px; line-height: 1.45;
  border-left: 4px solid transparent;
}
.rule-btn:hover { background: #f7f8fa; }
.rule-btn.current { background: var(--orange-soft); border-left-color: var(--orange); font-weight: 700; }
.rule-btn .no { font-family: var(--hand); color: var(--muted); font-size: 16px; }

/* 檢核記號：像老師在學習單上打的記號 */
.mk { width: 24px; height: 24px; display: inline-grid; place-items: center; font-family: var(--hand); font-size: 15px; font-weight: 700; justify-self: end; }
.mk-todo { border: 1.5px dashed #b9bec6; border-radius: 50%; width: 18px; height: 18px; }
.mk-pass { color: var(--green); font-size: 19px; }
.mk-na { color: var(--muted); }
.mk-issue { color: var(--red-text); border: 2px solid var(--red); border-radius: 52% 46% 55% 44% / 47% 55% 45% 53%; transform: rotate(-6deg); }

.sheet {
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  padding: 28px 36px 32px; min-width: 0;
}
.sheet-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--muted); }
.sheet-no { font-family: var(--hand); font-size: 17px; color: var(--orange-text); }
.sheet-title { font-size: 26px; line-height: 1.4; margin: 6px 0 10px; }
.sheet-title:focus { outline: none; }
.desc { margin: 0 0 18px; max-width: 42em; }
.qs { background: #f7f8fa; border-left: 4px solid var(--line); padding: 12px 18px; margin: 0 0 14px; max-width: 46em; }
.qs h3 { margin: 0 0 4px; font-size: 15px; }
.qs ul { margin: 0; padding-left: 1.2em; }
.example { margin: 0 0 18px; max-width: 46em; }
.example summary { cursor: pointer; color: var(--orange-text); font-weight: 700; }
.example p { font-family: var(--hand); font-size: 18px; margin: 6px 0 0; color: #3a3a3a; }

.ex { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0 0 12px; max-width: 52em; }
.ex > div { border-radius: 4px; padding: 10px 14px; font-size: 15px; line-height: 1.6; }
.ex b { display: block; font-size: 14px; margin-bottom: 2px; font-family: var(--hand); font-size: 17px; }
.ex-good { background: #eef7f1; border: 1px solid #c2ddc9; }
.ex-good b { color: var(--green); }
.ex-bad { background: #fdf0ec; border: 1px solid #ecc9bd; }
.ex-bad b { color: var(--red-text); }
.basis { font-size: 13px; color: var(--muted); margin: 0 0 8px; max-width: 52em; }
@media (max-width: 640px) { .ex { grid-template-columns: 1fr; } }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; }
.status { margin: 22px 0 8px; padding-top: 18px; border-top: 1px solid var(--line); }
.st-row { display: flex; flex-wrap: wrap; gap: 10px; }
.st { position: relative; cursor: pointer; }
.st input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.st span {
  display: inline-block; padding: 8px 22px; border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--paper); font-weight: 700; color: var(--muted);
}
.st input:focus-visible + span { outline: 3px solid var(--orange); outline-offset: 2px; }
.st-pass input:checked + span { border-color: var(--green); color: var(--green); background: #eef7f1; }
.st-issue input:checked + span { border-color: var(--red); color: var(--red-text); background: #fdf0ec; }
.st-na input:checked + span { border-color: var(--muted); color: var(--ink); background: #f0f1f3; }
.st input:disabled + span { opacity: .45; cursor: not-allowed; }
.hint { font-size: 14px; color: var(--muted); margin: 8px 0 0; }

.findings { margin-top: 18px; }
.findings h3 { font-size: 17px; margin: 0 0 10px; }
.finding {
  border: 1.5px solid var(--line); border-left: 4px solid var(--red); border-radius: 4px;
  padding: 14px 18px 16px; margin-bottom: 14px;
}
.finding h4 { margin: 0 0 6px; font-family: var(--hand); font-size: 18px; color: var(--red-text); }
.fld { display: block; font-size: 14px; font-weight: 700; margin: 10px 0; }
.fld textarea, .fld input {
  display: block; width: 100%; margin-top: 4px; font-weight: 400; font-size: 16px;
  border: 1.5px solid var(--line); border-radius: 4px; padding: 8px 10px; background: var(--paper); resize: vertical;
}
.fld textarea:focus, .fld input:focus { border-color: var(--orange); outline: none; }
.note { margin-top: 22px; }

.sevs { margin: 12px 0 6px; }
.sevs legend { font-size: 14px; }
.sevs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.sevs legend { grid-column: 1 / -1; }
.sev { position: relative; display: flex; gap: 8px; align-items: center; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: 4px; padding: 8px 10px; font-size: 14px; line-height: 1.3; }
.sev input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.sev-l small { display: block; color: var(--muted); font-size: 12px; }
.sev:has(input:checked) { border-color: var(--red); background: #fdf0ec; }
.sev:has(input:focus-visible) { outline: 3px solid var(--orange); outline-offset: 2px; }

/* 嚴重度數字：紅筆圈起來 */
.sev-n {
  flex: none; width: 30px; height: 30px; display: inline-grid; place-items: center;
  font-family: var(--hand); font-weight: 700; font-size: 18px; line-height: 1;
  border: 2px solid currentColor; border-radius: 52% 46% 55% 44% / 47% 55% 45% 53%;
  transform: rotate(-5deg);
}
.sev-n.sev-1, .sev-1 .sev-n { color: #8a8f98; }
.sev-n.sev-2, .sev-2 .sev-n { color: var(--orange-text); }
.sev-n.sev-3, .sev-3 .sev-n { color: var(--red-text); }
.sev-n.sev-4, .sev-4 .sev-n { color: #fff; background: var(--red); border-color: var(--red); }

.btn, .btn-add, .btn-ghost {
  cursor: pointer; border-radius: 4px; font-weight: 700; padding: 9px 18px;
  border: 1.5px solid var(--ink); background: var(--paper);
}
.btn-primary { background: var(--orange); border-color: var(--orange); color: #1f1300; }
.btn-primary:hover { background: #ee7210; }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-add { border-style: dashed; border-color: var(--red); color: var(--red-text); width: 100%; }
.btn-ghost { border-color: transparent; background: none; color: var(--muted); padding: 6px 8px; text-decoration: underline; text-underline-offset: 3px; }
.btn-ghost:hover { color: var(--ink); }
.btn-ghost.danger { color: var(--red-text); }
.pager { display: flex; justify-content: space-between; margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- 摘要 ---------- */
.summary { max-width: 1100px; margin: 0 auto; padding: 24px; }
.report { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 28px 36px 32px; }
.report h2 { margin: 0; font-size: 26px; }
.report h3 { font-size: 17px; margin: 26px 0 10px; }
.report-meta { color: var(--muted); margin: 4px 0 18px; font-size: 14px; }
.tally { display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.tally > div { display: flex; align-items: baseline; gap: 6px; }
.tally b { font-size: 28px; font-family: var(--hand); }
.tally span { color: var(--muted); font-size: 14px; }
.tally .t-sev { align-items: center; }
.tally .t-sev .sev-n { width: 26px; height: 26px; font-size: 15px; }
.warn-box { border-left: 4px solid var(--red); background: #fdf0ec; padding: 2px 16px 12px; margin-top: 18px; }
.warn-box h3 { color: var(--red-text); margin-top: 12px; }
.todo p { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; }
.link { border: 0; background: none; padding: 0; cursor: pointer; color: var(--orange-text); text-decoration: underline; text-underline-offset: 3px; text-align: left; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; vertical-align: top; padding: 10px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 13px; color: var(--muted); font-weight: 700; white-space: nowrap; }
td:nth-child(2) { min-width: 12em; }
.c-sev { width: 4em; }
.empty { color: var(--muted); }
.methods details { border-left: 4px solid var(--orange); background: var(--orange-soft); padding: 8px 14px; max-width: 52em; }
.methods summary { cursor: pointer; font-weight: 700; color: var(--orange-text); }
.methods p { margin: 6px 0; font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.actions.secondary { margin-top: 10px; gap: 4px 12px; }
.act-msg { min-height: 1.5em; color: var(--green); font-size: 14px; }

/* ---------- 手機 ---------- */
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr; grid-template-areas: "brand" "meta" "tabs"; padding: 12px 16px 0; }
  .meta { justify-content: flex-start; }
  .meta label { width: 100%; }
  .meta input, .meta .m-date input { flex: 1; width: auto; }
  .check { grid-template-columns: 1fr; padding: 12px 16px; gap: 12px; }
  .rulelist { position: static; max-height: none; padding: 0; }
  .list-toggle {
    display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
    padding: 12px 16px; font-weight: 700;
  }
  .list-toggle::after { content: "展開"; float: right; color: var(--orange-text); font-weight: 400; }
  .rulelist.open .list-toggle::after { content: "收合"; }
  .rulelist-body { display: none; border-top: 1px solid var(--line); padding-bottom: 8px; }
  .rulelist.open .rulelist-body { display: block; }
  .sheet, .report { padding: 20px 16px 24px; }
  .sheet-title { font-size: 22px; }
  .sevs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { padding: 12px 16px; }
}

/* ---------- 列印：只印摘要 ---------- */
@media print {
  body { background: #fff; font-size: 12pt; }
  .topbar, .check, .actions, .act-msg, .todo { display: none !important; }
  .summary { display: block !important; padding: 0; max-width: none; }
  .report { border: 0; padding: 0; }
  .link { color: inherit; text-decoration: none; }
  tr { break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
