/* Excel Study Board — charcoal + orange, inspired by the book cover.
   Light/dark follow the OS setting. */
:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1f1f22;
  --ink-2: #55545a;
  --ink-3: #8a8890;
  --line: #e3dfd8;
  --accent: #d9741c;
  --accent-ink: #ffffff;
  --accent-soft: #fbe9d7;
  --bar: #2b2b2e;
  --bar-ink: #f1efe9;
  --ok: #2f8a4c;
  --ok-soft: #e1f2e6;
  --warn: #b7791f;
  --danger: #c0392b;
  --code-bg: #f1ede6;
  --p1: #4f7cac; --p2: #d9741c; --p3: #8e5bb5; --p4: #2f8a6f; --p5: #c2477b; --p6: #6b7280;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181a; --surface: #222225; --surface-2: #1d1d20; --ink: #ece9e3; --ink-2: #b4b1aa;
    --ink-3: #85837d; --line: #34343a; --accent: #ec8d3a; --accent-soft: #3a2a1b; --bar: #111113;
    --ok: #5cbf7c; --ok-soft: #1d3324; --code-bg: #2c2b2f;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.55 var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: .08em .35em; border-radius: 4px; overflow-wrap: anywhere; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.25rem;
  padding: .6rem 1.25rem; background: var(--bar); color: var(--bar-ink); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .55rem; color: inherit; text-decoration: none; font-weight: 650; letter-spacing: .01em; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; font-weight: 800; }
.brand-lg { font-size: 1.25rem; color: var(--ink); }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { color: #cfcac1; text-decoration: none; padding: .35rem .7rem; border-radius: 7px; font-weight: 500; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav a.active { color: #fff; background: rgba(232,137,44,.22); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar-stat { margin-left: auto; font-size: .85rem; color: #cfcac1; }
.topbar-stat strong { color: #fff; }

.view { max-width: 1500px; margin: 0 auto; padding: 1.25rem; outline: none; }
.loading { color: var(--ink-2); }

/* ---------- buttons & inputs ---------- */
.btn { font: inherit; font-weight: 550; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: .45rem .9rem; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
.btn-ghost { background: transparent; border-color: transparent; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 160px; resize: vertical; line-height: 1.5; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: .2rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.chip.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---------- kanban ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: .9rem; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: .65rem .8rem; border-bottom: 1px solid var(--line); }
.col-head h2 { font-size: .9rem; text-transform: uppercase; letter-spacing: .06em; margin: 0; }
.col-count { font-size: .8rem; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 .5rem; }
.col-hint { font-size: .75rem; color: var(--warn); padding: .35rem .8rem 0; }
.col-body { padding: .6rem; display: flex; flex-direction: column; gap: .55rem; min-height: 120px; flex: 1; transition: background .15s; }
.col-body.drop { background: var(--accent-soft); border-radius: 0 0 var(--radius) var(--radius); }
.col[data-status="mastered"] .col-head h2 { color: var(--ok); }

.card { position: relative; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--pc, var(--accent)); border-radius: 8px; padding: .6rem .7rem .55rem; box-shadow: var(--shadow); cursor: grab; }
.card:active { cursor: grabbing; }
.card.dragging { opacity: .45; }
.card-top { display: flex; justify-content: space-between; gap: .5rem; font-size: .75rem; color: var(--ink-2); }
.card-title { display: block; font-weight: 600; color: var(--ink); text-decoration: none; margin: .15rem 0 .35rem; line-height: 1.3; }
.card-title:hover { color: var(--accent); }
.card-meta { display: flex; align-items: center; gap: .5rem; font-size: .75rem; color: var(--ink-2); }
.card-meta > span { white-space: nowrap; }
.card-move { margin-left: auto; font-size: .75rem; padding: .1rem .25rem; }
.meter { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: .45rem; }
.meter > span { display: block; height: 100%; background: var(--ok); width: 0; }
.tag { display: inline-block; font-size: .7rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; border-radius: 4px; padding: .05rem .35rem; background: var(--code-bg); color: var(--ink-2); }
.tag-core { background: var(--accent-soft); color: var(--accent); }
.tag-light, .tag-skim, .tag-optional { background: var(--code-bg); }
.tag-missing { background: transparent; border: 1px dashed var(--ink-3); }
.card.not-in-edition { opacity: .6; }

.p1 { --pc: var(--p1); } .p2 { --pc: var(--p2); } .p3 { --pc: var(--p3); }
.p4 { --pc: var(--p4); } .p5 { --pc: var(--p5); } .p6 { --pc: var(--p6); }

/* ---------- lessons list ---------- */
.part-block { margin-bottom: 1.5rem; }
.part-head { display: flex; align-items: baseline; gap: .75rem; border-bottom: 2px solid var(--pc); padding-bottom: .35rem; margin-bottom: .5rem; }
.part-head h2 { margin: 0; }
.lesson-row { display: grid; grid-template-columns: 3.2rem 1fr auto auto auto; gap: .75rem; align-items: center; padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; border-radius: 6px; }
.lesson-row:hover { background: var(--surface); }
.lesson-num { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 600; }
.lesson-row .ttl { font-weight: 550; }
.status-pill { font-size: .75rem; border-radius: 999px; padding: .1rem .55rem; border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.status-pill.s-reading, .status-pill.s-practicing, .status-pill.s-review { border-color: var(--accent); color: var(--accent); }
.status-pill.s-mastered { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.search { min-width: 240px; }

/* ---------- lesson page ---------- */
.lesson { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.5rem; align-items: start; }
.lesson-main > section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.lesson-main h2 { display: flex; align-items: center; gap: .5rem; }
.crumbs { font-size: .85rem; color: var(--ink-2); margin-bottom: .35rem; }
.crumbs a { color: var(--ink-2); }
.lesson-hero { border-left: 5px solid var(--pc); padding: .2rem 0 .2rem 1rem; margin-bottom: 1rem; }
.lesson-hero h1 { margin-bottom: .35rem; }
.chapter-ref { display: flex; gap: .5rem; flex-wrap: wrap; font-size: .85rem; }
.chapter-ref span { border: 1px solid var(--line); border-radius: 6px; padding: .1rem .5rem; background: var(--surface); color: var(--ink-2); }
.chapter-ref span.mine { border-color: var(--accent); color: var(--ink); font-weight: 600; }
.summary p { margin: 0 0 .7rem; }
ul.clean { margin: 0; padding-left: 1.15rem; } ul.clean li { margin: .3rem 0; }
.shortcuts { columns: 2 260px; }
.ex { display: grid; grid-template-columns: auto 1fr; gap: .7rem; padding: .8rem 0; border-top: 1px solid var(--line); }
.ex:first-of-type { border-top: 0; }
.ex input[type=checkbox] { width: 20px; height: 20px; margin-top: .15rem; accent-color: var(--ok); }
.ex-title { font-weight: 650; }
.ex.done .ex-title { color: var(--ok); }
.ex-body { margin: .25rem 0 0; color: var(--ink); }
.ex-files { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.ex-files a { font-size: .78rem; text-decoration: none; border: 1px solid var(--line); border-radius: 6px; padding: .05rem .45rem; color: var(--ink-2); }
.ex-files a::before { content: "↓ "; color: var(--accent); }
details.qa { border-top: 1px solid var(--line); padding: .6rem 0; }
details.qa:first-of-type { border-top: 0; }
details.qa summary { cursor: pointer; font-weight: 600; list-style: none; }
details.qa summary::-webkit-details-marker { display: none; }
details.qa summary::before { content: "▸"; color: var(--accent); display: inline-block; width: 1.1rem; transition: transform .15s; }
details.qa[open] summary::before { transform: rotate(90deg); }
details.qa p { margin: .4rem 0 0 1.1rem; color: var(--ink-2); }
.python { background: linear-gradient(0deg, var(--surface), var(--surface)), var(--surface); border-left: 4px solid #3776ab !important; }
.python h2::before { content: "🐍"; font-size: 1rem; }

.side { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.panel h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.seg { display: grid; grid-template-columns: 1fr; gap: .3rem; }
.seg button { text-align: left; font: inherit; font-size: .9rem; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: 7px; padding: .4rem .6rem; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.stars { display: flex; gap: .2rem; }
.stars button { font-size: 1.35rem; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--line); padding: 0 .05rem; }
.stars button.on { color: var(--accent); }
.save-state { font-size: .75rem; color: var(--ink-3); min-height: 1em; }
.pager { display: flex; justify-content: space-between; gap: .5rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; font-size: .88rem; }
.kv dt { color: var(--ink-2); } .kv dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------- progress ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stat .num { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: .8rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.bar-row { display: grid; grid-template-columns: 11rem 1fr 3.2rem; gap: .6rem; align-items: center; margin: .45rem 0; font-size: .9rem; }
.bar { height: 10px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--pc, var(--accent)); width: 0; }
.weeks { display: flex; align-items: flex-end; gap: .4rem; height: 140px; padding-top: .5rem; }
.week { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; height: 100%; justify-content: flex-end; font-size: .7rem; color: var(--ink-2); }
.week .col-bar { width: 100%; max-width: 38px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
.tbl th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }

.view > .panel, .view > .grid-2 { margin-bottom: 1rem; }

/* ---------- files ---------- */
.file-list { display: grid; gap: .6rem; }
.file { display: grid; grid-template-columns: 1fr auto; gap: .75rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.file.featured { border-color: var(--accent); background: var(--accent-soft); }
.file-name { font-family: var(--mono); font-weight: 600; font-size: .9rem; overflow-wrap: anywhere; }

/* ---------- settings / dialog / toast ---------- */
.form-grid { display: grid; gap: 1rem; max-width: 560px; }
.form-grid label, .dialog label { display: grid; gap: .3rem; font-weight: 550; font-size: .9rem; }
.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; background: var(--surface); color: var(--ink); width: min(440px, 92vw); }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog form { display: grid; gap: .8rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; visibility: hidden; pointer-events: none; background: var(--bar); color: #fff; padding: .55rem 1rem; border-radius: 8px; transition: transform .2s, opacity .2s, visibility .2s; z-index: 50; font-size: .9rem; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.callout { background: var(--accent-soft); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; font-size: .92rem; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: .75rem; margin-top: 1rem; }
.login-card input[type=password] { width: 100%; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--ink-2); }
.alert { background: #fdecea; color: #8a1f12; border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .board { grid-template-columns: repeat(5, 260px); overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .lesson { grid-template-columns: 1fr; }
  .side { position: static; order: -1; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .view { padding: 1rem; }
  .topbar { gap: .5rem; padding: .5rem .75rem; flex-wrap: nowrap; }
  .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: .35rem .55rem; }
  .brand-text { display: none; }
  .topbar-stat { display: none; }
  .lesson-row { grid-template-columns: 2.4rem 1fr auto; }
  .lesson-row .hide-sm { display: none; }
  .bar-row { grid-template-columns: 7rem 1fr 2.8rem; }
  .search { min-width: 0; width: 100%; }
  .lesson-main > section { padding: 1rem; }
}
@media print {
  .topbar, .side, .toolbar { display: none; }
  .lesson { display: block; }
  details.qa p { display: block; }
}
