/* Balance Our Day — design tokens and components (ported from the canvas mockup) */
:root, [data-theme="dark"] {
  --ground:#0F1513; --surface:#18201D; --ink:#E6ECEA; --ink-2:#B7C3BF; --muted:#93A19C;
  --border:#2A3531; --subtle:#222B28; --line:#3A4743; --line-2:#34403C; --past:#141B19; --dash:#5E6B67;
  --accent:#00695C; --accent-ink:#5ED3BF; --accent-ink-hover:#8FE3D4; --accent-soft:#143A34;
  --inverse-bg:#E6ECEA; --inverse-ink:#0F1513; --inverse-accent:#00695C;
  --warn-bg:#3A2C10; --warn-ink:#F5CD7A; --warn-line:#8A6A24; --ok-bg:#16301F; --ok-ink:#ABE5BF;
  --danger-bg:#3D1A17; --danger-ink:#F4A39A; --danger-line:#6B2E28; --danger:#B3261E;
  --pos:#F0A060; --neg:#7DB8F0; --shadow:0 12px 32px rgba(0,0,0,.35);
  /* category tints (see src/lib/colors.ts): background = colour mixed into the ground, text = colour mixed toward white/black */
  --cat-pastel-w: 0%; --cat-bg-pct: 34%; --cat-ink-pct: 88%; --cat-ink-base: #FFFFFF;
  color-scheme: dark;
}
[data-theme="light"] {
  --ground:#F4F6F5; --surface:#FFFFFF; --ink:#17201D; --ink-2:#3E4A46; --muted:#5A6662;
  --border:#E1E6E4; --subtle:#EEF1F0; --line:#C9D1CE; --line-2:#D3DAD7; --past:#F7F8F8; --dash:#9AA6A2;
  --accent-ink:#00695C; --accent-ink-hover:#004D43; --accent-soft:#E3F1EE;
  --inverse-bg:#17201D; --inverse-ink:#FFFFFF; --inverse-accent:#8FE3D4;
  --warn-bg:#FFF4E0; --warn-ink:#5C3B00; --warn-line:#E8B04A; --ok-bg:#E6F5EB; --ok-ink:#11432A;
  --danger-bg:#FDE4E1; --danger-ink:#A3271B; --danger-line:#E3A9A3;
  --pos:#9A4A0B; --neg:#1F5F99; --shadow:0 12px 32px rgba(0,0,0,.12);
  --cat-pastel-w: 100%; --cat-bg-pct: 100%; --cat-ink-pct: 32%; --cat-ink-base: #000000;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); }
body { font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); } a:hover { color: var(--accent-ink-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }
.muted { color: var(--muted); } .ink2 { color: var(--ink-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 28px; font-weight: 700; } h2 { font-size: 18px; font-weight: 600; }
p { margin: 0; }

/* ---------- layout ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1200px; margin: 0 auto; padding: 10px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 20px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.nav a { padding: 10px 14px; border-radius: 8px; color: var(--ink-2); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.grow { flex: 999 1 560px; min-width: 0; }
.side { flex: 1 1 300px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.hstack { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.bottomnav { display: none; }
@media (max-width: 760px) {
  .nav { display: none; }
  .topbar-in { padding: 10px 16px; }
  .page { padding: 16px 16px 110px; }
  .bottomnav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; color: var(--muted); text-decoration: none; font-size: 12px; }
  .bottomnav a[aria-current="page"] { color: var(--accent-ink); font-weight: 600; }
  h1 { font-size: 24px; }
}

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 22px; }
.card.tight { padding: 16px; }
.card-sub { background: var(--ground); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.chip.soft { background: var(--accent-soft); color: var(--accent-ink); }
.chip.gray { background: var(--subtle); color: var(--ink-2); }
.chip.inv { background: var(--inverse-bg); color: var(--inverse-ink); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.note { font-size: 13px; padding: 10px 12px; border-radius: 10px; }
.note.warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.note.ok { background: var(--ok-bg); color: var(--ok-ink); }
.note.err { background: var(--danger-bg); color: var(--danger-ink); }
.note.info { background: var(--subtle); color: var(--ink-2); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--dash); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 600; }
.btn.danger-ghost { color: var(--danger-ink); border-color: var(--danger-line); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent-ink); font-weight: 600; padding: 8px 4px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 40px; min-height: 40px; padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.input, select.input, textarea.input { width: 100%; font-size: 15px; font-weight: 400; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--ground); color: var(--ink); }
textarea.input { resize: vertical; min-height: 80px; }
.input:focus, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
.seg { display: inline-flex; gap: 4px; background: var(--subtle); padding: 4px; border-radius: 10px; }
.seg button { border: 0; background: transparent; color: var(--ink-2); padding: 7px 12px; min-height: 36px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.seg button[aria-pressed="true"], .seg button[aria-checked="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; }
.seg button:disabled { cursor: not-allowed; }
.lang { display: flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.lang button { border: 0; padding: 8px 12px; min-height: 36px; font-size: 13px; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--inverse-bg); color: var(--inverse-ink); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; text-decoration: none; flex: 0 0 auto; }
.switch { flex: 0 0 auto; width: 56px; height: 32px; border-radius: 999px; border: 0; padding: 3px; cursor: pointer; display: flex; background: var(--line); justify-content: flex-start; }
.switch[aria-checked="true"] { background: var(--accent); justify-content: flex-end; }
.switch span { width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: transparent; color: var(--ink-2); padding: 12px 16px; min-height: 44px; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; font-size: 15px; }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent-ink); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 10px 14px; }
td { padding: 10px 14px; border-top: 1px solid var(--border); }
td.num, th.num { text-align: right; font-family: 'IBM Plex Mono', monospace; }
table.compact th, table.compact td { padding: 8px 4px; }
table.compact th:first-child, table.compact td:first-child { padding-left: 0; }
table.compact th:last-child, table.compact td:last-child { padding-right: 0; }

/* ---------- dialogs & toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: var(--surface); border-radius: 18px; width: 100%; max-width: 780px; max-height: 92vh; overflow: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow); }
.dialog.narrow { max-width: 460px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--inverse-bg); color: var(--inverse-ink); border-radius: 12px; padding: 8px 8px 8px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast button { border: 0; background: transparent; color: var(--inverse-accent); font-weight: 600; padding: 10px 12px; cursor: pointer; }
@media (max-width: 760px) { .toast { bottom: 96px; } }

/* ---------- schedule grid ---------- */
.week { min-width: 680px; display: flex; flex-direction: column; gap: 2px; }
.week-row { display: grid; grid-template-columns: 52px repeat(7, minmax(0, 1fr)); gap: 2px; }
.week-head { font-size: 13px; font-weight: 600; text-align: center; padding: 8px 0; border-radius: 8px; color: var(--ink-2); }
.week-head.today { background: var(--accent); color: #fff; }
.week-hour { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--muted); display: flex; align-items: center; }
.cell { height: 28px; padding: 0 8px; border: 0; text-align: left; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; font-weight: 500; }
.cell:disabled { cursor: default; }
.cell.empty { outline: 1px dashed var(--dash); outline-offset: -1px; background: transparent; }
.cell.sel { box-shadow: inset 0 0 0 2px var(--ink); }
.cell.now { box-shadow: inset 0 0 0 2px var(--accent-ink); }
.mini { height: 18px; padding: 0 6px; font-size: 10px; line-height: 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-radius: 3px; }
.mini.changed { box-shadow: inset 0 0 0 2px var(--ink); font-weight: 600; }

/* ---------- balance bars ---------- */
.balrow { display: grid; grid-template-columns: minmax(90px, 140px) minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; }
.balrow .bal-label { font-size: 14px; font-weight: 500; }
.balrow .bal-num { font-size: 13px; text-align: right; min-width: 100px; }
@media (max-width: 560px) {
  .balrow { grid-template-columns: minmax(0, 1fr) auto; }
  .balrow .bar { grid-column: 1 / -1; grid-row: 2; }
  .balrow .bal-num { min-width: 0; }
}

/* ---------- misc ---------- */
.bar { height: 10px; border-radius: 999px; background: var(--subtle); overflow: hidden; position: relative; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.center-screen { min-height: 100vh; display: flex; flex-direction: column; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent-ink); animation: spin 0.8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; }

/* ---------- courses ---------- */
.cat-box { flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { font-size: 14px; padding: 8px 16px; min-height: 40px; border-radius: 999px; cursor: pointer; background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); }
.pill[aria-pressed="true"] { background: var(--inverse-bg); color: var(--inverse-ink); border-color: var(--inverse-bg); font-weight: 600; }
.ccard { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--ink); min-width: 0; }
a.ccard:hover { border-color: var(--dash); color: var(--ink); }
.ccard .t { font-weight: 600; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
.ccard .s { font-size: 13px; color: var(--muted); }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.pack-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.pack-steps a { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--ground); color: var(--ink); text-decoration: none; }
.pack-steps a:hover { border-color: var(--dash); color: var(--ink); }
.pack-steps a[aria-current="page"] { border-color: var(--accent-ink); }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.not_started { background: var(--subtle); color: var(--ink-2); }
.badge.in_progress { background: var(--accent-soft); color: var(--accent-ink); }
.badge.done { background: var(--ok-bg); color: var(--ok-ink); }
.badge.draft { background: var(--warn-bg); color: var(--warn-ink); }
.badge.private { background: var(--subtle); color: var(--ink-2); }
.bar.thin { height: 6px; }
.bar > span.fill { background: var(--accent); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: min(340px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.menu a { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.menu a:hover { background: var(--subtle); color: var(--ink); }
.menu a span { font-size: 13px; color: var(--muted); }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 14px; color: var(--muted); }
.crumbs a { text-decoration: none; }

/* lesson page */
.lesson-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
.outline { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.outline ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.outline a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; text-decoration: none; font-size: 14px; color: var(--ink-2); }
.outline a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.mark { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--subtle); color: var(--ink-2); }
.mark.done { background: var(--accent); color: #fff; }
.mark.skip { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
@media (max-width: 900px) { .lesson-layout { grid-template-columns: 1fr; } .outline { position: static; max-height: none; } }
.md { line-height: 1.7; overflow-wrap: anywhere; }
.md > * + * { margin-top: .8em; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3 { margin-top: 1.2em; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; }
.md ul, .md ol { padding-left: 1.4em; margin: 0; }
.md code { font-family: 'IBM Plex Mono', monospace; font-size: 13px; background: var(--subtle); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--ground); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--ink-2); }
.md table { border: 1px solid var(--border); border-radius: 10px; display: block; overflow-x: auto; }
.md th { background: var(--subtle); color: var(--ink); }
.md img { max-width: 100%; border-radius: 10px; }
.lesson-img { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.lesson-img img { max-width: 100%; border-radius: 12px; border: 1px solid var(--border); }
.lesson-img figcaption { font-size: 13px; color: var(--muted); }
.video { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.linkrow { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--ground); text-decoration: none; overflow-wrap: anywhere; }
fieldset.ex { border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
fieldset.ex legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.choice { text-align: left; padding: 12px 14px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--ground); cursor: pointer; }
.choice[aria-pressed="true"] { border-color: var(--accent-ink); background: var(--accent-soft); font-weight: 600; }
.choice.right { border-color: var(--ok-ink); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.answer { padding: 10px 12px; border-radius: 10px; background: var(--ground); border: 1px solid var(--border); white-space: pre-wrap; font-size: 14px; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } }
.editor-preview { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
@media (max-width: 1000px) { .editor-preview { position: static; max-height: none; } }
textarea.code { font-family: 'IBM Plex Mono', monospace; font-size: 13px; line-height: 1.5; min-height: 420px; white-space: pre; tab-size: 2; }
.issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.issues code { font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.lesson-edit { border: 1px solid var(--border); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--ground); }
.lesson-edit > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.lesson-edit > summary::-webkit-details-marker { display: none; }
.ex-edit { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.guide-box { max-height: 340px; overflow: auto; font-family: 'IBM Plex Mono', monospace; font-size: 12px; white-space: pre-wrap; background: var(--ground); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
