:root {
  --bg: #0f1712; --panel: #17231b; --panel2: #1e2d23; --line: #2c3f32;
  --text: #e6efe8; --muted: #94a89a; --accent: #6fcf8f; --accent-ink: #0b1a10;
  --warn: #f2c14e; --bad: #ef7d6d; --info: #7cb8f2; --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 -apple-system, "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* 頂部及底部導航 */
.topbar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; background: rgba(15,23,18,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
[hidden] { display: none !important; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; }
.brand img { width: 30px; height: 30px; }
#nav { display: flex; gap: 4px; flex: 1; }
#nav a, .tabbar a { color: var(--muted); padding: 6px 12px; border-radius: 8px; }
#nav a.on { color: var(--text); background: var(--panel2); }
.userbtn { background: none; border: 1px solid var(--line); color: var(--text); border-radius: 20px; padding: 5px 14px; cursor: pointer; font: inherit; font-size: .9rem; }
.tabbar { display: none; }
main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }

@media (max-width: 760px) {
  #nav { display: none; }
  .topbar { padding: 8px 16px; justify-content: space-between; }
  main { padding: 16px 16px 90px; }
  .tabbar:not([hidden]) { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: rgba(15,23,18,.96); border-top: 1px solid var(--line); padding: 4px 0 calc(4px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; text-align: center; font-size: .72rem; padding: 4px 0; display: flex; flex-direction: column; align-items: center; }
  .tabbar a .ico { font-size: 1.3rem; line-height: 1.3; }
  .tabbar a.on { color: var(--accent); }
}

/* 卡片及版面 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.hero { background: linear-gradient(135deg, #1d3526, #17231b); }

/* 進度條 */
.bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }

/* 單元列表 */
.lessons { list-style: none; margin: 0; padding: 0; }
.lessons li a { display: flex; align-items: center; gap: 12px; padding: 12px 6px; border-top: 1px solid var(--line); color: var(--text); }
.lessons li:first-child a { border-top: 0; }
.lessons li a:hover { background: var(--panel2); }
.dot { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem;
  border: 2px solid var(--line); color: var(--muted); }
.dot.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.dot.part { border-color: var(--warn); color: var(--warn); }
.lessons .t { flex: 1; min-width: 0; }
.code { font-family: ui-monospace, Menlo, monospace; color: var(--muted); font-size: .8rem; margin-right: 6px; }

/* 標籤 */
.tag { display: inline-block; font-size: .75rem; padding: 2px 9px; border-radius: 10px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.tag.ok { background: rgba(111,207,143,.15); color: var(--accent); }
.tag.warn { background: rgba(242,193,78,.15); color: var(--warn); }
.tag.bad { background: rgba(239,125,109,.15); color: var(--bad); }
.tag.info { background: rgba(124,184,242,.15); color: var(--info); }

/* 按鈕及表單 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); border-radius: 10px; padding: 9px 16px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 110px; resize: vertical; }
.form2 { display: grid; gap: 0 14px; grid-template-columns: 1fr 1fr; }
.form3 { display: grid; gap: 0 14px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 600px) { .form2, .form3 { grid-template-columns: 1fr; } }
.err { color: var(--bad); min-height: 1.4em; font-size: .9rem; }

/* 登入 */
.auth { max-width: 400px; margin: 6vh auto; }
.auth .logo { text-align: center; margin-bottom: 20px; }
.auth .logo img { width: 64px; }
.switch { display: flex; background: var(--panel2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.switch button { flex: 1; background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; font: inherit; cursor: pointer; }
.switch button.on { background: var(--panel); color: var(--text); }

/* 影片 */
.player { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.player video { display: block; width: 100%; max-height: 70vh; }
.notes li { margin-bottom: 8px; }
.placeholder { border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted); margin-bottom: 16px; }

/* 小測 */
.qitem { padding: 14px 0; border-top: 1px solid var(--line); }
.qitem:first-child { border-top: 0; }
.qitem .qtext { font-weight: 600; margin-bottom: 8px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 6px 0; border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; color: var(--text); font-size: 1rem; }
.opt input { width: auto; margin: 0; accent-color: var(--accent); }
.opt.right { border-color: var(--accent); background: rgba(111,207,143,.1); }
.opt.wrong { border-color: var(--bad); background: rgba(239,125,109,.1); }
.explain { font-size: .9rem; color: var(--muted); margin-top: 6px; }
.result { padding: 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 600; }
.result.ok { background: rgba(111,207,143,.12); color: var(--accent); }
.result.bad { background: rgba(239,125,109,.12); color: var(--bad); }
.timer { position: sticky; top: 60px; z-index: 5; font-variant-numeric: tabular-nums; }

/* 簽核清單 */
.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.check:first-child { border-top: 0; }
.check .box { flex: none; width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; margin-top: 2px; font-size: .8rem; }
.check .box.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check .body { flex: 1; }

/* 表格 */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel2); }

/* 地圖 */
.map { height: 340px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); margin-bottom: 16px; background: var(--panel2); }
.leaflet-container { font: inherit; }
.drop { border: 1px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 12px; }
.drop:hover { border-color: var(--accent); color: var(--text); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 2000; background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.bad { border-color: var(--bad); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: .9rem; }
