:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e3e6ea;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --accent: #3b5bdb;
  --accent-soft: #e7ecff;
  --good: #2b8a3e;
  --good-soft: #e6f4ea;
  --warn: #e67700;
  --warn-soft: #fff3e0;
  --bad: #c92a2a;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252d;
    --border: #2b323c;
    --text: #e6e9ee;
    --muted: #97a2b0;
    --accent: #7b93ff;
    --accent-soft: #1f2a4d;
    --good: #51cf66;
    --good-soft: #15301c;
    --warn: #ffa94d;
    --warn-soft: #3a2a12;
    --bad: #ff6b6b;
    --bad-soft: #3b1a1a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f252d;
  --border: #2b323c;
  --text: #e6e9ee;
  --muted: #97a2b0;
  --accent: #7b93ff;
  --accent-soft: #1f2a4d;
  --good: #51cf66;
  --good-soft: #15301c;
  --warn: #ffa94d;
  --warn-soft: #3a2a12;
  --bad: #ff6b6b;
  --bad-soft: #3b1a1a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75em; }
small, .muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 16px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: .8rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  text-decoration: none; color: var(--text); padding: 8px 10px; border-radius: 8px;
  display: flex; justify-content: space-between; align-items: center; font-size: .94rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-badge:not(:empty) {
  background: var(--bad); color: #fff; border-radius: 999px; font-size: .72rem;
  padding: 0 7px; font-weight: 700;
}
.mini-timer {
  margin-top: auto; background: var(--accent-soft); color: var(--accent); border-radius: 10px;
  padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.mini-timer strong { font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; min-width: 0; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center;
    padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand-sub, .brand-title { display: none; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .mini-timer { margin: 0; padding: 6px 10px; }
  .mini-timer span { display: none; }
  .main { padding: 18px 16px 60px; }
}

/* ---------- components ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); max-width: 720px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; min-width: 0;
}
.card + .card { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
[hidden] { display: none !important; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.section-gap { margin-top: 22px; }

.kpi .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.9rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .hint { font-size: .85rem; color: var(--muted); }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.subj-row { display: grid; grid-template-columns: 170px 1fr 48px; gap: 10px; align-items: center; padding: 6px 0; }
.subj-row .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
@media (max-width: 520px) { .subj-row { grid-template-columns: 110px 1fr 42px; } }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 13px; border-radius: 8px;
  cursor: pointer; font-size: .9rem; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.btn.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.btn.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn.sm { padding: 4px 9px; font-size: .82rem; }
.btn.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 999px;
  cursor: pointer; font-size: .88rem;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.tag { display: inline-block; font-size: .74rem; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.H { background: var(--bad-soft); color: var(--bad); }
.tag.M { background: var(--warn-soft); color: var(--warn); }
.tag.L { background: var(--good-soft); color: var(--good); }
.tag.acc { background: var(--accent-soft); color: var(--accent); }

input[type=text], input[type=number], input[type=date], input[type=time], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.field > span { font-weight: 600; }
.check { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.check.done span { color: var(--muted); text-decoration: line-through; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; background: var(--surface-2); position: sticky; top: 0; }
tr.today td { background: var(--accent-soft); }
tr.week-head td { background: var(--surface-2); font-weight: 700; }
tr.sunday td { color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- syllabus ---------- */
.topic { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.topic > summary {
  list-style: none; cursor: pointer; padding: 12px 14px; display: grid;
  grid-template-columns: 1fr auto; gap: 10px; align-items: center;
}
.topic > summary::-webkit-details-marker { display: none; }
.topic > summary:hover { background: var(--surface-2); }
.topic-title { font-weight: 650; }
.topic-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.topic-body { padding: 4px 16px 16px; border-top: 1px solid var(--border); }
.topic-prog { width: 110px; }
@media (max-width: 520px) { .topic-prog { width: 64px; } }
.sub-block { margin-top: 12px; }
.sub-block h4 { font-size: .9rem; margin-bottom: 4px; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
@media (max-width: 760px) { .info-grid { grid-template-columns: 1fr; } }
.info { background: var(--surface-2); border-radius: 10px; padding: 12px; font-size: .9rem; }
.info h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.info ul { margin: 0; padding-left: 18px; }
.info li { margin: 2px 0; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.stars button { border: 0; background: none; cursor: pointer; font-size: 1.15rem; padding: 0 1px; color: var(--border); }
.stars button.on { color: #f59f00; }
.counter { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; }
.counter input { width: 64px; padding: 4px 6px; }

/* ---------- pomodoro ---------- */
.pomo { text-align: center; padding: 26px 18px; }
.pomo-time { font-size: clamp(3.2rem, 12vw, 5.6rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -2px; line-height: 1.1; }
.pomo-mode { font-weight: 700; text-transform: uppercase; letter-spacing: .12em; font-size: .85rem; }
.pomo-mode.focus { color: var(--bad); }
.pomo-mode.break { color: var(--good); }
.ring { width: 100%; max-width: 260px; margin: 0 auto 8px; display: block; }

/* ---------- misc ---------- */
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-plain li:last-child { border-bottom: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 12px 14px; border-radius: 8px; font-size: .92rem; }
.callout.warn { border-color: var(--warn); background: var(--warn-soft); }
.callout.good { border-color: var(--good); background: var(--good-soft); }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }
.routine { display: grid; grid-template-columns: 110px 1fr auto; gap: 4px 12px; font-size: .92rem; }
.routine > div { padding: 6px 0; border-bottom: 1px solid var(--border); }
.routine .t { font-variant-numeric: tabular-nums; color: var(--muted); }
.routine .busy { color: var(--muted); font-style: italic; }
.routine .study { font-weight: 600; }
pre.prompt {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 420px; overflow: auto;
}
.heat { display: grid; gap: 6px; }
.heat-row { display: grid; grid-template-columns: 180px 1fr; gap: 10px; align-items: start; }
.heat-cells { display: flex; flex-wrap: wrap; gap: 5px; }
.heat-cell { font-size: .78rem; padding: 4px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.heat-cell.H { background: var(--bad-soft); color: var(--bad); }
.heat-cell.M { background: var(--warn-soft); color: var(--warn); }
.heat-cell.L { background: var(--good-soft); color: var(--good); }
.heat-cell.done { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
@media (max-width: 640px) { .heat-row { grid-template-columns: 1fr; } }
svg text { fill: var(--muted); font-size: 11px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0;
  transition: .25s; pointer-events: none; z-index: 50; font-size: .9rem; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.note-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.note-item .star { cursor: pointer; border: 0; background: none; font-size: 1.1rem; color: var(--border); }
.note-item .star.on { color: #f59f00; }

@media print {
  .side, .no-print, .btn, .chips { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; color: #000; }
}
