:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --ink: #15171c;
  --muted: #6b7280;
  --line: #e4e6ee;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --accent-soft: #e7ebff;
  --good: #1f9d57;
  --warn: #c2410c;
  --bad: #d92d3a;
  --shadow: 0 1px 2px rgba(20,24,40,.06), 0 4px 14px rgba(20,24,40,.05);
  --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b22;
    --ink: #eceef4;
    --muted: #98a0b3;
    --line: #272b35;
    --accent: #7b93ff;
    --accent-ink: #0d1020;
    --accent-soft: #232a4d;
    --good: #46c27f;
    --warn: #f0a15c;
    --bad: #ff6b76;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- top ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 6px;
}
.weekbar { display: flex; align-items: center; gap: 6px; }
.week-title { flex: 1; text-align: center; min-width: 0; }
.week-title b { display: block; font-size: 17px; letter-spacing: -.01em; }
.week-title small { display: block; color: var(--muted); font-size: 12.5px; min-height: 1.2em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }
.pill {
  border: 0; border-radius: 999px; padding: 9px 14px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px;
}
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.day {
  border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 7px 0 8px; cursor: pointer; text-align: center; position: relative;
}
.day span { display: block; font-size: 11.5px; color: var(--muted); }
.day b { display: block; font-size: 17px; margin-top: 1px; }
.day i {
  position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: var(--accent); opacity: .85;
}
.day.today b { color: var(--accent); }
.day.on { background: var(--accent); border-color: var(--accent); }
.day.on span, .day.on b { color: var(--accent-ink); }
.day.on i { background: var(--accent-ink); }

/* ---------- content ---------- */
main { flex: 1; padding: 6px 16px calc(92px + env(safe-area-inset-bottom)); }
.tab > h2 { font-size: 22px; margin: 8px 0 12px; letter-spacing: -.02em; }
.dayhead { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 2px 10px; }
.dayhead h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.dayhead span { color: var(--muted); font-size: 14px; }

.lesson {
  display: flex; gap: 14px; background: var(--card); border-radius: var(--r);
  padding: 13px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  border: 1px solid transparent; cursor: pointer; text-align: left; width: 100%;
}
.lesson:active { transform: scale(.992); }
.lesson.now { border-color: var(--accent); }
.lesson.past { opacity: .55; }
.lt { width: 52px; flex: none; text-align: left; font-variant-numeric: tabular-nums; }
.lt b { display: block; font-size: 16px; }
.lt span { color: var(--muted); font-size: 13px; }
.lb { flex: 1; min-width: 0; }
.lb h3 { margin: 0 0 3px; font-size: 16px; line-height: 1.25; letter-spacing: -.005em; overflow-wrap: anywhere; }
.lb p { margin: 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.chip.gray { background: var(--line); color: var(--muted); }
.chip.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.note-line {
  margin-top: 8px; padding: 7px 10px; border-radius: 10px; font-size: 13.5px;
  background: color-mix(in srgb, var(--warn) 12%, transparent); overflow-wrap: anywhere;
}

.empty { text-align: center; color: var(--muted); padding: 56px 20px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }
.err {
  background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad);
  border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-size: 14px;
}
.err button { margin-top: 8px; }

/* ---------- homework ---------- */
.hw {
  display: flex; align-items: flex-start; gap: 12px; background: var(--card);
  border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.hw input[type=checkbox] { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.hw .body { flex: 1; min-width: 0; }
.hw .body b { display: block; overflow-wrap: anywhere; }
.hw .body small { color: var(--muted); display: block; overflow-wrap: anywhere; }
.hw.done .body { opacity: .5; text-decoration: line-through; }
.hw .del { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 0 4px; }
.sect { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; margin: 18px 4px 8px; }
.fab {
  position: fixed; right: max(16px, calc((100vw - 640px) / 2 + 16px));
  bottom: calc(80px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; font-size: 30px; line-height: 1;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px rgba(30,40,120,.35); cursor: pointer;
}

/* ---------- settings / forms ---------- */
.card { background: var(--card); border-radius: var(--r); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea, .sheet input, .sheet textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none; min-height: 44px;
}
.field input:focus, .field select:focus, .field textarea:focus, .sheet textarea:focus, .sheet input:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
details summary { cursor: pointer; font-weight: 600; font-size: 15px; }

/* ---------- tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center; gap: 0;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; max-width: 200px; border: 0; background: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11.5px; padding: 4px 0; position: relative;
}
.tabs button.on { color: var(--accent); font-weight: 600; }
.tabs .ti { font-size: 22px; line-height: 1.1; }
.tabs i {
  position: absolute; top: 0; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--bad); color: #fff; font-style: normal; font-size: 11px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

/* ---------- sheet ---------- */
dialog {
  border: 0; padding: 0; background: transparent; color: inherit;
  width: 100%; max-width: 640px; margin: auto auto 0; max-height: 92vh;
}
dialog::backdrop { background: rgba(8, 10, 18, .5); }
.sheet {
  background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow: auto;
}
.sheet h2 { margin: 0 0 2px; font-size: 19px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.sheet .grab { width: 38px; height: 4px; background: var(--line); border-radius: 2px; margin: -6px auto 12px; }
.sheet .field { margin-top: 10px; }
.sheet .row { margin-top: 12px; }
.sheet .row .btn { flex: 1; }

@media (prefers-reduced-motion: no-preference) {
  .lesson, .day, .btn { transition: transform .12s ease, background-color .15s ease; }
}
