:root {
  color-scheme: light;
  --ink: #27313d;
  --muted: #64707e;
  --paper: #fcfbf7;
  --blue: #2f5d8a;
  --blue-soft: #e8eff6;
  --red: #c9503e;
  --line: #dfe3e8;
  --white: #ffffff;
  font-family: "Noto Sans TC", ui-sans-serif, system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    repeating-linear-gradient(180deg, transparent 0 31px, rgba(47, 93, 138, 0.05) 31px 32px),
    var(--paper);
  color: var(--ink);
}
a { color: inherit; text-decoration: none; }
p, li { line-height: 1.8; }

.site-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  width: min(1020px, calc(100% - 40px)); margin: 0 auto; padding: 14px 0;
  background: rgba(252, 251, 247, 0.92); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px;
  border: 2px solid var(--red); border-radius: 10px;
  color: var(--red); font-size: 22px; font-weight: 900;
  background: var(--white);
}
.brand strong, .brand small { display: block; line-height: 1.1; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.site-header nav { display: flex; gap: 20px; color: var(--muted); font-size: 14px; font-weight: 800; }
.site-header nav a:hover, .site-header nav a[aria-current="page"] { color: var(--blue); }

main { width: min(1020px, calc(100% - 40px)); margin: 0 auto; padding: 40px 0 90px; }

.kicker { margin: 0 0 12px; color: var(--red); font-size: 13px; font-weight: 900; }
.hero { padding: 40px 0 30px; }
.hero h1 { margin: 0 0 20px; font-size: clamp(38px, 6vw, 60px); line-height: 1.18; letter-spacing: -0.02em; }
.hero-text { max-width: 560px; margin: 0; color: var(--muted); font-size: 19px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }

.button {
  display: inline-flex; align-items: center; gap: 8px; padding: 13px 26px;
  border: 2px solid var(--blue); border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 16px; font-weight: 900; cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
}
.button:hover { background: #274d73; transform: translateY(-1px); }
.button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.button-outline { background: transparent; color: var(--blue); }
.button-outline:hover { background: var(--blue-soft); }
.button-red { border-color: var(--red); background: var(--red); }
.button-red:hover { background: #b04434; }

.tool-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-top: 42px; }
.tool-card {
  display: flex; flex-direction: column; gap: 10px; padding: 26px 28px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--white);
  box-shadow: 0 10px 30px rgba(47, 93, 138, 0.07);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.tool-card:hover { transform: translateY(-3px); box-shadow: 0 16px 40px rgba(47, 93, 138, 0.12); }
.tool-card-tag { margin: 0; color: var(--red); font-size: 13px; font-weight: 900; }
.tool-card h2 { margin: 0; font-size: 24px; }
.tool-card p { margin: 0; color: var(--muted); }
.tool-card-cta { margin-top: 6px; color: var(--blue); font-weight: 900; }

.notes { margin-top: 64px; padding: 28px 30px; border: 1px solid var(--line); border-radius: 14px; background: var(--white); }
.notes h2 { margin: 0 0 14px; font-size: 24px; }
.notes ol { margin: 0; padding-left: 22px; }
.notes li { margin-bottom: 6px; }
.notes-sub { margin: 16px 0 0; color: var(--muted); font-size: 14px; }

.site-footer {
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  padding: 34px 20px 44px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 14px; text-align: center;
}
.site-footer strong { color: var(--ink); }

/* ----- Generator pages ----- */
.gen-shell { width: min(860px, 100%); margin: 0 auto; }
.gen-hero { padding: 26px 0 8px; }
.gen-hero h1 { margin: 0 0 14px; font-size: clamp(30px, 5vw, 44px); line-height: 1.22; letter-spacing: -0.02em; }
.gen-hero .intro { max-width: 640px; margin: 0; color: var(--muted); font-size: 17px; }

.gen-form {
  margin-top: 26px; padding: 24px 26px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--white);
  box-shadow: 0 10px 30px rgba(47, 93, 138, 0.07);
}
.gen-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.gen-field { display: block; }
.gen-field > span { display: block; margin-bottom: 8px; color: var(--blue); font-size: 13px; font-weight: 900; }
.gen-field select, .gen-field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper); color: var(--ink); font: inherit; font-size: 15px;
}
.gen-field select:focus-visible, .gen-field textarea:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.gen-field textarea { min-height: 74px; resize: vertical; letter-spacing: 0.35em; }
.gen-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); font-weight: 700; }
.gen-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }
.gen-hint { margin: 14px 0 0; color: var(--muted); font-size: 13px; }

.faq { margin-top: 56px; }
.faq h2 { margin: 0 0 16px; font-size: 26px; }
.faq details { margin-bottom: 10px; padding: 15px 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); }
.faq summary { font-weight: 800; cursor: pointer; }
.faq p { margin: 10px 0 0; color: var(--muted); }

.breadcrumbs { display: flex; gap: 8px; margin: 6px 0 18px; color: var(--muted); font-size: 13px; }
.breadcrumbs a:hover { text-decoration: underline; }

/* ----- Preview & print sheets ----- */
.preview { margin-top: 34px; }
.preview:empty { display: none; }
.sheet {
  margin: 0 auto 26px; padding: 46px 52px; width: 100%; max-width: 760px;
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
  box-shadow: 0 12px 34px rgba(39, 49, 61, 0.1);
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
  margin-bottom: 8px;
}
.sheet-head h2 { margin: 0; font-size: 21px; letter-spacing: 0.02em; }
.sheet-meta { display: flex; gap: 18px; color: var(--ink); font-size: 13px; }
.sheet-rule { height: 2px; margin: 10px 0 24px; background: var(--ink); }

.problem-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 40px; }
.problem { display: flex; gap: 8px; align-items: baseline; font-size: 19px; }
.problem .idx { min-width: 34px; color: var(--muted); font-size: 13px; }
.problem .blank { display: inline-block; min-width: 64px; border-bottom: 1.5px solid var(--ink); }

.problem-grid.vertical { grid-template-columns: repeat(4, 1fr); gap: 30px 22px; }
.vproblem { justify-self: center; min-width: 96px; font-size: 21px; font-variant-numeric: tabular-nums; }
.vproblem .idx { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.vproblem .row { display: flex; justify-content: flex-end; gap: 10px; padding: 1px 4px; }
.vproblem .op { color: var(--ink); }
.vproblem .vline { height: 2px; margin-top: 4px; background: var(--ink); }
.vproblem .answer-space { height: 40px; }

.answer-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 24px; font-size: 16px; }
.answer-grid .idx { color: var(--muted); font-size: 12px; margin-right: 6px; }

/* Handwriting grids */
.char-row { display: grid; gap: 0; margin-bottom: 14px; }
.char-cell { position: relative; border: 1.5px solid var(--red); aspect-ratio: 1; }
.char-cell + .char-cell { border-left: none; }
.char-cell.tian::before, .char-cell.tian::after,
.char-cell.mi::before, .char-cell.mi::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.char-cell.tian::before { border-top: 1px dashed rgba(201, 80, 62, 0.45); top: 50%; height: 0; }
.char-cell.tian::after { border-left: 1px dashed rgba(201, 80, 62, 0.45); left: 50%; width: 0; }
.char-cell.mi::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 0.5px), rgba(201, 80, 62, 0.45) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(to right, transparent calc(50% - 0.5px), rgba(201, 80, 62, 0.45) 50%, transparent calc(50% + 0.5px));
}
.char-cell.mi::after {
  background:
    linear-gradient(45deg, transparent calc(50% - 0.5px), rgba(201, 80, 62, 0.3) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(-45deg, transparent calc(50% - 0.5px), rgba(201, 80, 62, 0.3) 50%, transparent calc(50% + 0.5px));
}
.char-glyph {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: "Kaiti TC", "DFKai-SB", "BiauKai", "標楷體", "TW-Kai", serif;
  font-size: 200%; line-height: 1;
}
.char-glyph.trace { color: rgba(39, 49, 61, 0.28); }
.char-glyph.solid { color: var(--ink); }

@media (max-width: 640px) {
  .sheet { padding: 26px 20px; }
  .problem-grid { grid-template-columns: 1fr; }
  .problem-grid.vertical { grid-template-columns: repeat(2, 1fr); }
  .answer-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ----- Print ----- */
@media print {
  body { background: #fff; }
  .site-header, .site-footer, .gen-hero, .gen-form, .faq, .breadcrumbs, .no-print { display: none !important; }
  main { width: 100%; padding: 0; }
  .preview { margin: 0; }
  .sheet {
    max-width: none; margin: 0; padding: 8mm 10mm; border: none; border-radius: 0; box-shadow: none;
    page-break-after: always;
  }
  .sheet:last-child { page-break-after: auto; }
}
@page { size: A4 portrait; margin: 12mm; }

[hidden] { display: none !important; }

.brand-logo { border-radius: 10px; }
