/* 版面：左側固定章節導覽（手機改為頂部橫向捲動），右側單欄學習區；
   色彩概念：鈉燈 589 nm 的琥珀色為強調色，R＝藍、S＝洋紅，冷灰為中性色 */
:root {
  --bg: #f3f6f8; --surface: #ffffff; --surface-2: #e9eef2; --ink: #142029; --muted: #566673; --line: #d5dee5;
  --accent: #b36b00; --accent-fill: #f2a81d; --accent-soft: #fdf1d9;
  --r: #1265a8; --r-soft: #e1eefa; --s: #b52a63; --s-soft: #fae3ed;
  --ok: #1d7a46; --ok-soft: #dff3e7; --bad: #b3261e; --bad-soft: #fbe4e2;
  --c-C: #3b434c; --c-H: #e8ecef; --c-O: #d8352a; --c-N: #2f5fd0; --c-S: #e0b11c; --c-Br: #9a3b1f; --c-Cl: #2f9e44; --c-F: #7cc47a;
  --canvas: #f8fafb;
  --f-display: "Noto Serif TC", "Songti TC", serif;
  --f-body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141a; --surface: #151d25; --surface-2: #1c2631; --ink: #e3eaef; --muted: #93a3b0; --line: #29353f;
    --accent: #f4b740; --accent-fill: #f4b740; --accent-soft: #3a2c10;
    --r: #63b3f0; --r-soft: #15304a; --s: #f27aa8; --s-soft: #45182c;
    --ok: #5fd08f; --ok-soft: #123323; --bad: #ff8a80; --bad-soft: #3d1715;
    --c-C: #9aa5b0; --c-H: #f2f5f7; --c-O: #ff5d4f; --c-N: #6f98ff; --c-S: #f2c94c; --c-Br: #d0704c; --c-Cl: #5bd17a; --c-F: #a6e3a1;
    --canvas: #111921; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141a; --surface: #151d25; --surface-2: #1c2631; --ink: #e3eaef; --muted: #93a3b0; --line: #29353f;
  --accent: #f4b740; --accent-fill: #f4b740; --accent-soft: #3a2c10;
  --r: #63b3f0; --r-soft: #15304a; --s: #f27aa8; --s-soft: #45182c;
  --ok: #5fd08f; --ok-soft: #123323; --bad: #ff8a80; --bad-soft: #3d1715;
  --c-C: #9aa5b0; --c-H: #f2f5f7; --c-O: #ff5d4f; --c-N: #6f98ff; --c-S: #f2c94c; --c-Br: #d0704c; --c-Cl: #5bd17a; --c-F: #a6e3a1;
  --canvas: #111921; color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.7; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; line-height: 1.3; margin: 0; }
p { margin: 0; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-fill); outline-offset: 2px; }
.mono, .num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
sub { font-size: .72em; line-height: 0; }

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: env(safe-area-inset-top, 0px); align-self: start; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line); padding-block: 28px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: 18px; display: flex; flex-direction: column; gap: 22px; }
.brand { display: flex; flex-direction: column; gap: 4px; }
.brand-mark { font-family: var(--f-display); font-size: 1.35rem; font-weight: 700; letter-spacing: .02em; }
.brand-sub { color: var(--muted); font-size: .82rem; }
.brand-hands { font-family: var(--f-mono); font-size: .78rem; color: var(--muted); display: flex; gap: 8px; }
.brand-hands b { font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: baseline; padding: 7px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: .93rem; }
.nav a .n { font-family: var(--f-mono); font-size: .78rem; color: var(--muted); }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); font-weight: 600; }
.nav a[aria-current="page"] .n { color: var(--accent); }
.nav a .done { color: var(--ok); font-size: .75rem; margin-left: 4px; }
.side-foot { margin-top: auto; color: var(--muted); font-size: .78rem; line-height: 1.6; }

main { min-width: 0; padding-block: 32px 64px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px)); }
.module { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.mod-head { display: flex; flex-direction: column; gap: 8px; }
.eyebrow { font-family: var(--f-mono); font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.mod-head h2 { font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.1rem); }
.lede { color: var(--muted); max-width: 68ch; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.grid2.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.label { font-size: .78rem; color: var(--muted); letter-spacing: .04em; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: .9rem; line-height: 1.4; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { opacity: .9; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-fill); }
.btn:disabled { opacity: .45; cursor: default; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 11px; font-size: .86rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .k { font-family: var(--f-mono); font-size: .72rem; opacity: .65; margin-right: 4px; }
select.sel { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 8px; }

.canvas-wrap { position: relative; background: var(--canvas); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.canvas-wrap canvas:active { cursor: grabbing; }
.cv-lg { aspect-ratio: 4 / 3.1; }
.cv-md { aspect-ratio: 1 / 1; }
.cv-hint { position: absolute; left: 10px; bottom: 8px; font-size: .74rem; color: var(--muted); pointer-events: none; }
.cv-tag { position: absolute; left: 10px; top: 8px; font-size: .78rem; font-weight: 600; pointer-events: none; }

.callout { border-left: 3px solid var(--accent-fill); background: var(--accent-soft); padding: 12px 14px; border-radius: 0 8px 8px 0; font-size: .92rem; }
.callout b { font-weight: 700; }
.key { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.key > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: .9rem; }
.key h3 { font-size: .98rem; margin-bottom: 4px; }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; border-radius: 999px; font-family: var(--f-mono); font-size: .78rem; font-weight: 600; background: var(--ink); color: var(--bg); padding: 0 6px; }
.cfg { font-family: var(--f-mono); font-weight: 700; }
.cfg-R { color: var(--r); } .cfg-S { color: var(--s); }
.big-cfg { font-family: var(--f-display); font-size: 3rem; line-height: 1; font-weight: 700; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: .8rem; font-weight: 600; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.r { background: var(--r-soft); color: var(--r); } .pill.s { background: var(--s-soft); color: var(--s); }
.pill.n { background: var(--surface-2); color: var(--muted); }
.fb { border-radius: 8px; padding: 10px 12px; font-size: .92rem; }
.fb.ok { background: var(--ok-soft); } .fb.bad { background: var(--bad-soft); } .fb.n { background: var(--surface-2); }
.prio-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.prio-list li { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.formula { font-family: var(--f-mono); }

/* 模組 1 */
.mol2d { width: 100%; height: auto; display: block; }
.mol2d .bond { stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; }
.mol2d .hetero { font-family: var(--f-mono); font-size: 15px; font-weight: 600; }
.mol2d .hit { fill: transparent; cursor: pointer; }
.mol2d .vtx:hover .ring { stroke: var(--muted); }
.mol2d .ring { fill: none; stroke: transparent; stroke-width: 2.4; }
.mol2d .vtx.sel .ring { stroke: var(--accent-fill); fill: var(--accent-soft); fill-opacity: .55; }
.mol2d .vtx.good .ring { stroke: var(--ok); fill: var(--ok-soft); fill-opacity: .7; }
.mol2d .vtx.miss .ring { stroke: var(--ok); stroke-dasharray: 4 3; }
.mol2d .vtx.wrong .ring { stroke: var(--bad); fill: var(--bad-soft); fill-opacity: .7; }
.mol2d .vtx.focus .ring { stroke-width: 3.4; }
.mol2d .nb-hl { fill: var(--accent-fill); fill-opacity: .35; }

/* 模組 2 */
.cip-table { overflow-x: auto; }
.cip-grid { display: grid; grid-template-columns: 70px repeat(4, minmax(150px, 1fr)); gap: 0; min-width: 680px; }
.cip-grid > div { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.cip-grid .hd { font-weight: 600; background: var(--surface-2); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cip-grid .lv { font-family: var(--f-mono); font-size: .8rem; color: var(--muted); }
.cip-grid .cell.decided { background: var(--accent-soft); }
.set { display: inline-flex; gap: 3px; align-items: center; margin: 2px 6px 2px 0; padding: 1px 4px; border-radius: 6px; }
.set::before { content: "("; color: var(--muted); } .set::after { content: ")"; color: var(--muted); }
.set.single::before, .set.single::after { content: ""; }
.at { font-family: var(--f-mono); font-size: .82rem; font-weight: 600; min-width: 20px; text-align: center; padding: 0 3px; border-radius: 4px; border: 1px solid transparent; }
.at.dup { border: 1px dashed var(--muted); }
.at.ph { color: var(--muted); font-weight: 400; opacity: .6; }
.at-O { color: var(--c-O); } .at-N { color: var(--c-N); } .at-S { color: var(--c-S); } .at-Br { color: var(--c-Br); } .at-Cl { color: var(--c-Cl); } .at-F { color: var(--c-F); }
.cip-log { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; }

/* 模組 4 */
.mirror-pair { display: grid; grid-template-columns: minmax(0, 1fr) 2px minmax(0, 1fr); gap: 14px; align-items: stretch; }
.mirror-line { background: repeating-linear-gradient(to bottom, var(--muted) 0 6px, transparent 6px 12px); opacity: .6; }
.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent-fill); border-radius: 999px; transition: width .2s; }

/* 模組 5 */
.fischer { width: 100%; max-width: 320px; height: auto; display: block; margin: 0 auto; }
.fischer .ln { stroke: var(--ink); stroke-width: 2.4; }
.fischer .grp { cursor: pointer; }
.fischer .grp rect { fill: var(--surface); stroke: var(--line); stroke-width: 1.2; }
.fischer .grp:hover rect { stroke: var(--muted); }
.fischer .grp.sel rect { stroke: var(--accent-fill); stroke-width: 2.4; fill: var(--accent-soft); }
.fischer text { font-family: var(--f-mono); font-size: 15px; font-weight: 600; fill: var(--ink); }
.fischer .pr { font-size: 11px; fill: var(--bg); }
.fischer .prc { fill: var(--ink); }
.log { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; max-height: 220px; overflow-y: auto; }
.log div { display: flex; gap: 8px; align-items: center; }

/* 模組 6 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.mcard { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.mcard:hover { border-color: var(--muted); }
.mcard[aria-pressed="true"] { border-color: var(--accent-fill); box-shadow: 0 0 0 1px var(--accent-fill); }
.mcard .nm { font-weight: 600; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.trio span { text-align: center; border-radius: 6px; background: var(--surface-2); font-family: var(--f-mono); font-size: .85rem; padding: 2px 0; }
.trio-h { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: .7rem; color: var(--muted); text-align: center; }
.cmp-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.cmp-table th, .cmp-table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.cmp-table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tbl-wrap { overflow-x: auto; }

/* 模組 7 */
.bench { aspect-ratio: 16 / 6.2; }
.slider-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 76px; gap: 10px; align-items: center; font-size: .9rem; }
.slider-row input[type=range] { width: 100%; accent-color: var(--accent-fill); }
.slider-row output { font-family: var(--f-mono); text-align: right; font-variant-numeric: tabular-nums; }
.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.readout > div { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.readout .v { font-family: var(--f-mono); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.eq { font-family: var(--f-mono); font-size: .95rem; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; overflow-x: auto; white-space: nowrap; }
.hplc { aspect-ratio: 16 / 7; }
.methods { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.methods > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font-size: .9rem; display: flex; flex-direction: column; gap: 6px; }
.methods h3 { font-size: 1rem; }
.methods .what { font-size: .78rem; color: var(--accent); font-family: var(--f-mono); letter-spacing: .04em; }

/* 模組 8 */
.score { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; }
.score .v { font-family: var(--f-mono); font-size: 1.6rem; font-weight: 600; }
.qbox { display: flex; flex-direction: column; gap: 14px; }
.qtitle { font-size: 1.1rem; font-weight: 600; }
.answers { display: flex; flex-wrap: wrap; gap: 8px; }
.answers .btn { min-width: 64px; font-weight: 600; }
.answers .btn.right { background: var(--ok-soft); border-color: var(--ok); }
.answers .btn.wrongsel { background: var(--bad-soft); border-color: var(--bad); }
.order-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.order-pick .btn { font-family: var(--f-mono); }
.order-pick .btn .badge { margin-right: 6px; }
.typebar { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 12px; padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); border-right: 0; border-bottom: 1px solid var(--line); background: var(--bg); overflow-x: auto; overflow-y: hidden; }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bg); }
  .brand-sub, .brand-hands, .side-foot { display: none; }
  .brand-mark { font-size: 1rem; white-space: nowrap; }
  .nav { flex-direction: row; gap: 4px; }
  .nav a { white-space: nowrap; grid-template-columns: auto auto; padding: 5px 9px; font-size: .86rem; }
  main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 20px 48px; }
  .grid2, .grid2.even { grid-template-columns: minmax(0, 1fr); }
  .mirror-pair { grid-template-columns: minmax(0, 1fr); }
  .mirror-line { height: 2px; background: repeating-linear-gradient(to right, var(--muted) 0 6px, transparent 6px 12px); }
  .slider-row { grid-template-columns: 92px minmax(0, 1fr) 64px; }
  .big-cfg { font-size: 2.4rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- YTLab Learn More：英文字型、站內連結（← Learn More、語言切換、logo） ---- */
html[lang="en"] { --f-display: "Noto Serif", Georgia, serif; --f-body: "Noto Sans", system-ui, -apple-system, sans-serif; }
.site-links { display: flex; align-items: center; gap: 10px; font-size: .82rem; }
.site-links a { color: var(--muted); text-decoration: none; }
.site-links a:hover { color: var(--ink); text-decoration: underline; }
.site-links .spacer { flex: 1; }
.site-links .lang { border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; background: var(--surface); color: var(--ink); }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-row .logo { flex: none; }
.brand-row .logo img { display: block; width: 40px; height: 40px; border-radius: 10px; }
@media (max-width: 860px) {
  .site-links { flex: none; font-size: .78rem; white-space: nowrap; }
  .brand-row .logo img { width: 30px; height: 30px; border-radius: 8px; }
}
