/* 課程網站樣式：沅創卡片風格（墨藍底、細邊框卡片、青綠小標、琥珀主要按鈕），淺色為預設，深色跟隨系統或使用者選擇 */
@font-face { font-family: "Sora"; src: url("fonts/sora-latin-wght.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter-latin-wght.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #F2EEE4;
  --surface: #FFFFFF;
  --surface-2: #F8F5EE;
  --border: rgba(29, 33, 55, .16);
  --border-strong: rgba(29, 33, 55, .32);
  --text: #2A3145;
  --heading: #141A2E;
  --muted: #5B6478;
  --accent: #0F7A6E;          /* 淺色底上的青綠，對比足夠 */
  --accent-soft: rgba(15, 122, 110, .12);
  --primary: #F6B85A;
  --primary-ink: #1A1408;
  --code-bg: #0D1929;
  --code-text: #DCE6F2;
  --code-comment: #8FA3BC;
  --input-bg: #FFFFFF;
  --input-text: #141A2E;
  --focus: #0F7A6E;
  --drop: rgba(15, 122, 110, .14);
  --tag-basic: #2C6BB3; --tag-advanced: #8A4FC4; --tag-live: #B5591A;
  --radius: 8px;
  --font-head: "Sora", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-body: "Inter", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "PingFang TC", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070918; --surface: #0D1929; --surface-2: #101F33;
    --border: rgba(138, 188, 245, .2); --border-strong: rgba(138, 188, 245, .42);
    --text: #CBD6E5; --heading: #F1F0EA; --muted: #93A1B5;
    --accent: #9BE7DB; --accent-soft: rgba(155, 231, 219, .12);
    --code-bg: #050714; --code-text: #DCE6F2; --code-comment: #7F93AD;
    --input-bg: #0A1424; --input-text: #F1F0EA; --focus: #9BE7DB; --drop: rgba(155, 231, 219, .12);
    --tag-basic: #7FB4F0; --tag-advanced: #C9A2F2; --tag-live: #F6B85A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #070918; --surface: #0D1929; --surface-2: #101F33;
  --border: rgba(138, 188, 245, .2); --border-strong: rgba(138, 188, 245, .42);
  --text: #CBD6E5; --heading: #F1F0EA; --muted: #93A1B5;
  --accent: #9BE7DB; --accent-soft: rgba(155, 231, 219, .12);
  --code-bg: #050714; --code-text: #DCE6F2; --code-comment: #7F93AD;
  --input-bg: #0A1424; --input-text: #F1F0EA; --focus: #9BE7DB; --drop: rgba(155, 231, 219, .12);
  --tag-basic: #7FB4F0; --tag-advanced: #C9A2F2; --tag-live: #F6B85A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.8 var(--font-body); }
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--heading); line-height: 1.3; margin: 0 0 .6em; }
h1 { font-size: clamp(1.9rem, 4.6vw, 3rem); letter-spacing: -.01em; }
h2 { font-size: clamp(1.35rem, 2.8vw, 1.75rem); }
h3 { font-size: 1.12rem; }
a { color: var(--accent); text-underline-offset: 3px; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--accent-soft); color: var(--heading); padding: .08em .35em; border-radius: 4px; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.eyebrow { font: 600 12px/1.4 var(--font-head); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin: 0 0 .5rem; }
.lede { font-size: 1.08rem; max-width: 46rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--primary); color: var(--primary-ink); padding: .5rem 1rem; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }

/* 頁首 */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-in { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--heading); text-decoration: none; font: 700 1rem var(--font-head); white-space: nowrap; }
.nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.nav a { color: var(--text); text-decoration: none; padding: .35rem .7rem; border-radius: 6px; white-space: nowrap; font-size: .95rem; }
.nav a:hover, .nav a[aria-current="page"] { background: var(--accent-soft); color: var(--heading); }
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--heading); border-radius: 7px; padding: .35rem .65rem; font: inherit; font-size: .9rem; cursor: pointer; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.theme-toggle .i-moon { fill: currentColor; stroke: none; }
.theme-toggle .i-sun, [data-effective="dark"] .theme-toggle .i-moon { display: none; }
[data-effective="dark"] .theme-toggle .i-sun { display: block; }
@media (max-width: 560px) { .theme-label { display: none; } .nav a { padding: .35rem .45rem; font-size: .88rem; } .brand span { display: none; } }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: .5rem 1.05rem; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--heading); font: 600 .95rem var(--font-body); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--primary); }
.btn-sm { min-height: 36px; padding: .3rem .8rem; font-size: .88rem; }
.btn-ghost { background: transparent; }
.btn-icon { min-height: 32px; min-width: 32px; padding: .2rem .45rem; font-size: .85rem; }

/* 首頁 */
.hero { padding: clamp(48px, 9vw, 104px) 0 clamp(32px, 6vw, 64px); border-bottom: 1px solid var(--border); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 1.5rem; }
.section { padding: clamp(36px, 6vw, 64px) 16px; }
.section-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 32px; margin-bottom: 1.25rem; }
.section-head .muted { max-width: 34rem; margin: 0; font-size: .92rem; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 1rem; }
.chips, .toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: .25rem .75rem; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 .9rem var(--font-body); cursor: pointer; }
.chip span { font-size: .78rem; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip[aria-pressed="true"] span { color: var(--primary-ink); }

/* 群組與卡片 */
.board { display: grid; gap: 18px; }
.group { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 12px; }
.group-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; min-height: 36px; }
.group-name { margin: 0; font-size: 1rem; }
.group-toggle { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--heading); font: 700 1rem var(--font-head); cursor: pointer; padding: .2rem .25rem; border-radius: 6px; }
.group-toggle::before { content: "▾"; color: var(--accent); transition: transform .15s; }
.group.is-collapsed .group-toggle::before { transform: rotate(-90deg); }
.count { font-size: .78rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 .55rem; }
.group-tools { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.group-rename { font: 600 1rem var(--font-head); padding: .3rem .5rem; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--input-bg); color: var(--input-text); min-width: 0; width: 12rem; max-width: 60vw; }
.group-rename:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.group.is-collapsed .card-list { display: none; }
.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; min-height: 64px; border-radius: 6px; }
.card-list.is-empty::after { content: "把卡片拖到這裡"; display: grid; place-items: center; min-height: 64px; grid-column: 1 / -1; border: 1.5px dashed var(--border-strong); border-radius: 6px; color: var(--muted); font-size: .9rem; }
.card-list.is-over { background: var(--drop); outline: 1.5px dashed var(--accent); outline-offset: 4px; }
.card { position: relative; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 12px; cursor: grab; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: border-color .15s; }
.card:hover { border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.card.is-hidden { display: none; }
.card.is-pressing { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card.is-dragging { position: fixed; z-index: 100; pointer-events: none; cursor: grabbing; border-color: var(--accent); box-shadow: 0 18px 40px rgba(0, 0, 0, .35), 0 0 0 2px var(--accent); transform: rotate(1.5deg); opacity: .97; }
.card.is-grabbed { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary); }
.card-placeholder { border: 2px dashed var(--accent); border-radius: var(--radius); background: var(--drop); }
.card-top { display: flex; align-items: center; gap: 8px; font-size: .8rem; }
.lv { font: 700 .82rem var(--font-head); color: var(--accent); letter-spacing: .04em; }
.tag { display: inline-block; font-size: .74rem; font-weight: 600; padding: 0 .5rem; border-radius: 4px; border: 1px solid currentColor; line-height: 1.6; }
.tag-basic { color: var(--tag-basic); } .tag-advanced { color: var(--tag-advanced); } .tag-live { color: var(--tag-live); }
.mins { color: var(--muted); margin-left: auto; }
.card-title { margin: 2px 0 0; font-size: 1.08rem; }
.card-summary { margin: 0; font-size: .92rem; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-keys { margin: 0; font-size: .82rem; color: var(--muted); }
.card-keys span { color: var(--accent); margin-right: .5em; font-weight: 600; }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.move { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.move select, .move select option { font: inherit; font-size: .85rem; color: var(--input-text); background: var(--input-bg); }
.move select { min-height: 34px; border: 1px solid var(--border-strong); border-radius: 6px; padding: .15rem .4rem; max-width: 9rem; }
.move select:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

/* 流程 */
.flow { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.flow li { display: flex; gap: 12px; padding: 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 0 -1px -1px 0; }
.flow strong { color: var(--heading); font-family: var(--font-head); }
.flow p { margin: .2rem 0 0; font-size: .9rem; line-height: 1.6; }
.step-n { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 700 .9rem var(--font-head); }

/* 表格 */
.table { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin: 1rem 0 1.4rem; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: .6rem .85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-family: var(--font-head); color: var(--heading); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
.stack th { color: var(--heading); white-space: nowrap; width: 1%; }

/* 關卡頁 */
.lesson { padding-top: 24px; padding-bottom: 48px; }
.crumbs { display: flex; gap: 8px; font-size: .9rem; color: var(--muted); }
.lesson-head { padding: 20px 0 24px; border-bottom: 1px solid var(--border); margin-bottom: 28px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--muted); font-size: .9rem; margin: 0; }
.lesson-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 40px; }
.toc { position: sticky; top: 84px; align-self: start; font-size: .9rem; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.toc a { display: block; padding: .25rem .8rem; color: var(--text); text-decoration: none; }
.toc a:hover { color: var(--accent); }
.prose { min-width: 0; max-width: 820px; }
.prose h2 { margin-top: 2.2rem; padding-top: .5rem; scroll-margin-top: 80px; }
.prose h3 { margin-top: 1.6rem; scroll-margin-top: 80px; }
.prose li { margin: .25rem 0; }
.prose blockquote { margin: 1rem 0; padding: .6rem 1rem; border-left: 3px solid var(--primary); background: var(--surface); border-radius: 0 6px 6px 0; }
@media (max-width: 860px) { .lesson-grid { grid-template-columns: 1fr; gap: 0; } .toc { position: static; margin-bottom: 20px; } .toc ol { display: flex; flex-wrap: wrap; border: 0; gap: 4px; } .toc a { border: 1px solid var(--border); border-radius: 6px; padding: .15rem .6rem; font-size: .85rem; } }

/* 程式碼 */
.code { margin: 1rem 0 1.4rem; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: .35rem .5rem .35rem .9rem; font: 500 .78rem var(--font-mono); color: var(--code-comment); border-bottom: 1px solid rgba(138, 188, 245, .16); }
.code pre { margin: 0; padding: .9rem 1rem; overflow-x: auto; }
.code code { background: none; padding: 0; color: var(--code-text); font-size: .86rem; line-height: 1.65; white-space: pre; }
.code .c { color: var(--code-comment); font-style: italic; }
.copy { border: 1px solid rgba(138, 188, 245, .3); background: transparent; color: #DCE6F2; border-radius: 6px; font: 500 .78rem var(--font-body); padding: .15rem .6rem; cursor: pointer; min-height: 28px; }
.copy:hover { border-color: #9BE7DB; color: #9BE7DB; }
.copy:focus-visible { outline: 2px solid #9BE7DB; }
.sample { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin: .8rem 0; }
.sample summary { cursor: pointer; padding: .6rem .9rem; font-weight: 600; color: var(--heading); }
.sample[open] summary { border-bottom: 1px solid var(--border); }
.sample .code { margin: 0; border: 0; border-radius: 0 0 var(--radius) var(--radius); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 2.5rem; }
.pager a { display: flex; flex-direction: column; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--heading); font-weight: 600; }
.pager a:hover { border-color: var(--accent); }
.pager a span { font-size: .8rem; color: var(--muted); font-weight: 500; }
.pager .next { text-align: right; }
@media (max-width: 560px) { .pager { grid-template-columns: 1fr; } .pager .next { text-align: left; } }

.notfound { padding: 80px 16px; }
.footer { border-top: 1px solid var(--border); padding: 24px 0 32px; font-size: .88rem; }
.footer p { margin: .2rem 0; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--heading); color: var(--bg); padding: .6rem 1rem; border-radius: 7px; font-size: .9rem; z-index: 200; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } .card.is-dragging { transform: none; } }
