/* 實體自習小組 · 共同守則 — styles.css
   Palette: teal (focus) · indigo (start/end rituals) · rose (warnings). No orange.
   Layout: mobile-first; grids respond to their own container width so phone,
   iPad portrait/landscape and desktop all get a sensible column count. */

/* ---------- tokens ---------- */
:root {
  color-scheme: light dark;
  --bg: #edf0f3; --surface: #ffffff; --surface-2: #e6ebef;
  --ink: #14202a; --ink-2: #42505c; --ink-3: #586571; --line: #d3dae0;
  --focus: #0d5c63; --on-focus: #ffffff; --focus-soft: #dcedee; --focus-ink: #0a4f56;
  --gate: #4a4db0; --on-gate: #ffffff; --gate-soft: #e6e7f7; --gate-ink: #383b97;
  --warn: #b0285a; --warn-soft: #f8e3eb; --warn-ink: #8f1f4a;
  --shadow: 0 1px 2px rgba(20, 32, 42, .05), 0 6px 20px rgba(20, 32, 42, .05);
  --r: 14px; --r-sm: 10px;
  --f-body: 'Noto Sans TC', 'PingFang HK', 'PingFang TC', 'Microsoft JhengHei', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-mono: 'IBM Plex Mono', 'Noto Sans TC', 'PingFang HK', 'Microsoft JhengHei', ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e151b; --surface: #16202a; --surface-2: #1f2b36;
    --ink: #e8eef2; --ink-2: #b4bfc9; --ink-3: #8f9ca8; --line: #2b3945;
    --focus: #4dbdc4; --on-focus: #062a2e; --focus-soft: #14353a; --focus-ink: #86d9de;
    --gate: #9a9df2; --on-gate: #14163f; --gate-soft: #22254d; --gate-ink: #b9bcfa;
    --warn: #f08bb0; --warn-soft: #3a1a27; --warn-ink: #f5aac6;
    --shadow: none;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e151b; --surface: #16202a; --surface-2: #1f2b36;
  --ink: #e8eef2; --ink-2: #b4bfc9; --ink-3: #8f9ca8; --line: #2b3945;
  --focus: #4dbdc4; --on-focus: #062a2e; --focus-soft: #14353a; --focus-ink: #86d9de;
  --gate: #9a9df2; --on-gate: #14163f; --gate-soft: #22254d; --gate-ink: #b9bcfa;
  --warn: #f08bb0; --warn-soft: #3a1a27; --warn-ink: #f5aac6;
  --shadow: none;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.7 var(--f-body);
  -webkit-font-smoothing: antialiased; overflow-wrap: break-word;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
a { color: var(--focus-ink); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
.muted { color: var(--ink-2); }
.lbl { font: 600 13px/1.4 var(--f-body); letter-spacing: .06em; color: var(--ink-3); }

.wrap {
  width: 100%; max-width: 1120px; margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.main { display: grid; gap: 20px; padding-block: 24px 40px; }
.main > * { min-width: 0; }
@media (min-width: 768px) { .main { gap: 24px; padding-block: 32px 56px; } }

/* ---------- header (not sticky: on a phone it would eat ~90px for no benefit) ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 14px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; width: 28px; height: 28px; color: var(--gate); }
.brand-name { font-size: clamp(17px, 4.8vw, 20px); font-weight: 800; line-height: 1.3; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 12px;
  border-radius: 99px; background: var(--gate-soft); color: var(--gate-ink);
  font: 600 13px var(--f-body); white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
@media (max-width: 399px) { .pill { display: none; } }

/* ---------- tones ---------- */
.tone-focus { --tone: var(--focus); --on-tone: var(--on-focus); --tone-ink: var(--focus-ink); }
.tone-gate  { --tone: var(--gate);  --on-tone: var(--on-gate);  --tone-ink: var(--gate-ink); }

/* ---------- hero ---------- */
.hero {
  container-type: inline-size; display: grid; gap: 20px;
  padding: clamp(20px, 4vw, 36px); border: 1px solid var(--line); border-radius: var(--r);
  background: linear-gradient(135deg, var(--focus-soft) 0%, var(--surface) 65%);
  box-shadow: var(--shadow);
}
.lead { font-size: clamp(21px, 3.6vw, 30px); line-height: 1.45; font-weight: 800; max-width: 22em; text-wrap: balance; }
.intro { max-width: 42em; color: var(--ink-2); text-wrap: pretty; }

.beats { display: grid; gap: 12px; counter-reset: beat; }
.beat {
  counter-increment: beat; position: relative; display: grid; gap: 4px; align-content: start;
  padding: 16px 16px 16px 66px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface);
}
.beat::before {
  content: counter(beat); position: absolute; left: 16px; top: 16px;
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--tone); color: var(--on-tone); font: 600 15px/1 var(--f-mono);
}
.beat .lbl { color: var(--tone-ink); }
.beat p { font-size: 15px; }
@container (min-width: 800px) {
  .beats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .beat { padding: 66px 18px 18px; }
}

/* ---------- headings ---------- */
.panel-h { display: grid; gap: 4px; }
.h2 { font-size: clamp(22px, 3.8vw, 28px); font-weight: 800; line-height: 1.25; text-wrap: balance; }
.h3 { font-size: 17px; font-weight: 700; line-height: 1.35; }
.panel-h .h3 { font-size: 20px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink);
  font: 600 14px/1.2 var(--f-body); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: scale(.98); }
@media (pointer: coarse) { .btn { min-height: 44px; padding-inline: 20px; } }

/* ---------- rules ---------- */
.rules-sec { container-type: inline-size; display: grid; gap: 16px; }
.rules { display: grid; gap: 12px; }
.rule {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; padding: 18px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow);
}
.rule-n { font: 600 22px/1.4 var(--f-mono); color: var(--focus-ink); min-width: 1.7em; }
.rule-b { display: grid; align-content: start; min-width: 0; }
.rule-t { font-size: 18px; font-weight: 700; line-height: 1.45; text-wrap: balance; }
.rule-d { margin-top: 4px; max-width: 40em; }
@container (max-width: 420px) {
  .rule { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .rule-n { font-size: 18px; line-height: 1.2; }
}
@container (min-width: 860px) {
  .rules { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
}

/* disclosure (rules + sources): 44px tap target, custom chevron */
details { max-width: 44em; }
summary {
  display: flex; align-items: center; gap: 8px; width: fit-content; min-height: 44px; padding-block: 4px;
  cursor: pointer; list-style: none; font-weight: 600; color: var(--focus-ink);
  -webkit-tap-highlight-color: transparent;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: ""; flex: none; width: 7px; height: 7px; margin-top: -3px;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s;
}
details[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
.panel > details { max-width: none; }
.rule details p {
  margin: 2px 0 4px; padding: 12px 14px; border-left: 3px solid var(--focus);
  border-radius: 0 var(--r-sm) var(--r-sm) 0; background: var(--focus-soft); color: var(--ink-2); font-size: 15px;
}

/* ---------- panels ---------- */
.panel {
  container-type: inline-size; display: grid; gap: 16px; padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow);
}

/* rhythm tips */
.tips { display: grid; gap: 20px; }
.tips > div { display: grid; gap: 6px; align-content: start; padding-top: 14px; border-top: 3px solid var(--focus); }
.tips .lbl { color: var(--focus-ink); }
@container (min-width: 800px) { .tips { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; } }

/* comparison table: real table on wide containers, stacked cards on narrow ones */
.tbl-wrap { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
thead th { border-top: 0; background: var(--surface-2); color: var(--ink-3); font: 600 13px var(--f-body); letter-spacing: .06em; }
thead th:first-child { border-top-left-radius: var(--r-sm); }
thead th:last-child { border-top-right-radius: var(--r-sm); }
tbody th { font-weight: 700; }
tbody td:nth-child(2) { background: color-mix(in srgb, var(--focus-soft) 55%, transparent); }
@container (max-width: 639px) {
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  tbody tr { margin-bottom: 10px; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
  tbody th { border-top: 0; background: var(--surface-2); }
  td { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 10px; }
  td::before { content: attr(data-label); font-weight: 600; color: var(--ink-3); }
}
.callout {
  padding: 14px 16px; border-left: 4px solid var(--gate); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--gate-soft);
}

/* failure modes */
.watch { display: grid; gap: 12px; }
.watch li {
  display: grid; gap: 6px; align-content: start; padding: 14px 16px;
  border-top: 3px solid var(--warn); border-radius: var(--r-sm); background: var(--warn-soft);
}
.watch strong { color: var(--warn-ink); line-height: 1.5; }
@container (min-width: 560px) { .watch { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (min-width: 900px) { .watch { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* sources */
.src { display: grid; gap: 0; padding-top: 6px; }
.src li { font-size: 15px; overflow-wrap: anywhere; }
.src a { display: inline-block; padding-block: 9px; }

/* ---------- footer / toast / helpers ---------- */
.foot { padding-top: 0; padding-bottom: max(32px, env(safe-area-inset-bottom, 0px)); color: var(--ink-3); font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom, 0px)); z-index: 60;
  max-width: min(520px, calc(100% - 32px)); padding: 10px 16px; border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg); font-weight: 600;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.copy-buffer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; font-size: 16px; }

/* 404 page */
.nf { justify-items: start; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- print: force light tokens (dark-mode users would otherwise print pale text on white) ---------- */
@media print {
  :root:not([data-theme="print-none"]), :root[data-theme="dark"] {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #eef1f3; --ink: #14202a; --ink-2: #42505c; --ink-3: #586571; --line: #c9d1d7;
    --focus: #0d5c63; --focus-soft: #dcedee; --focus-ink: #0a4f56;
    --gate: #4a4db0; --on-gate: #fff; --gate-soft: #e6e7f7; --gate-ink: #383b97;
    --warn: #b0285a; --warn-soft: #f8e3eb; --warn-ink: #8f1f4a;
    --shadow: none;
  }
  body { background: #fff; }
  .btn, .toast { display: none !important; }
  .hero, .panel, .rule, .beat, .watch li { box-shadow: none; break-inside: avoid; }
  .hero { background: #fff; }
}
