:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --text: #1c1c21;
  --muted: #6d6c72;
  --border: #e3e1da;
  --accent: #5b4de0;
  --accent-soft: #ecebfd;
  --accent-text: #ffffff;
  --good: #1f8a5c;
  --good-soft: #e5f5ec;
  --bad: #c2412d;
  --bad-soft: #fcebe7;
  --warn: #b46b00;
  --shadow: 0 1px 2px rgba(20, 20, 30, .04), 0 4px 16px rgba(20, 20, 30, .05);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16161a; --surface: #1f1f25; --surface-2: #28282f; --text: #ececf0; --muted: #9b9aa3;
    --border: #33333b; --accent: #8f84ff; --accent-soft: #2b2850; --accent-text: #15131f;
    --good: #4cc38a; --good-soft: #193427; --bad: #ff7a66; --bad-soft: #3d1f1a; --warn: #f0a93b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16161a; --surface: #1f1f25; --surface-2: #28282f; --text: #ececf0; --muted: #9b9aa3;
  --border: #33333b; --accent: #8f84ff; --accent-soft: #2b2850; --accent-text: #15131f;
  --good: #4cc38a; --good-soft: #193427; --bad: #ff7a66; --bad-soft: #3d1f1a; --warn: #f0a93b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: .4em 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pre { white-space: pre-wrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left)); padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
/* backdrop-filter делает шапку контейнером для position:fixed, поэтому только на ПК, где меню внутри шапки */
@media (min-width: 860px) {
  .top { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); }
.sync { margin-left: auto; width: 10px; height: 10px; border-radius: 50%; background: var(--good); flex: none; transition: background .2s; }
.sync.saving { background: var(--warn); }
.sync.offline { background: var(--bad); }
.main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; min-width: 0;
}
.tabs a.active { color: var(--accent); font-weight: 600; }
.tab-icon { font-size: 1.25rem; line-height: 1; }
@media (min-width: 860px) {
  .tabs { position: static; height: auto; padding: 0; background: none; border: 0; justify-content: flex-start; gap: 4px; }
  .tabs a { flex: none; flex-direction: row; gap: 6px; padding: 8px 12px; border-radius: 10px; font-size: .95rem; }
  .tabs a:hover { background: var(--surface-2); }
  .tabs a.active { background: var(--accent-soft); }
  .tab-icon { font-size: 1rem; }
  .main { padding-bottom: 48px; }
}

/* ---------- карточки ---------- */
.hero { padding: 8px 2px 12px; }
.hero p { margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card > *:last-child { margin-bottom: 0; }
.kicker { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.card > .kicker:first-child, .row > div > .kicker:first-child, .row > .kicker { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row.small { margin: 12px 0 6px; }
.book { font-weight: 500; }
.nudge { border-color: var(--accent); background: linear-gradient(0deg, var(--accent-soft), var(--accent-soft)) , var(--surface); }
.nudge { background: var(--accent-soft); }
.entry .kicker { margin-top: 10px; }
.entry.due { border-color: var(--warn); }
.disclaimer { padding: 0 4px; }

.learn-cta {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 16px 18px; margin-bottom: 14px; cursor: pointer;
  border: 1px dashed var(--accent); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.learn-cta:hover { background: var(--accent-soft); }
.learn-cta > span:last-child { display: flex; flex-direction: column; }
.learn-icon { font-size: 1.6rem; }

.status { font-size: 1.15rem; font-weight: 600; }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }
.big-num { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat-label { font-size: .75rem; color: var(--muted); }
.stat-value { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
@media (max-width: 520px) { .stats { grid-template-columns: 1fr 1fr; } .stats .stat:last-child { grid-column: span 2; } }
.advice { background: var(--bad-soft); border-radius: 12px; padding: 12px; margin: 12px 0; }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

.tag { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.badge { display: inline-block; margin-left: 8px; font-size: .7rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--bad-soft); color: var(--bad); }

/* ---------- кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font-size: .95rem; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.link { border: 0; background: none; padding: 8px 0; color: var(--accent); min-height: 0; }
.btn.wide { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.btn-row.center { justify-content: center; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 6px 8px; border-radius: 8px; font-size: .95rem; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: .85rem; font-weight: 600; }
.hint { font-size: .78rem; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; min-height: 42px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- задания ---------- */
.tasks { list-style: none; padding: 0; margin: 8px 0; }
.tasks li { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tasks li:last-child { border-bottom: 0; }
.tasks input[type=checkbox] { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.tasks label { flex: 1; cursor: pointer; }
.tasks li.done label { color: var(--muted); text-decoration: line-through; }
.task-actions { display: flex; gap: 2px; flex: none; }
.add-row { display: flex; gap: 8px; }
.plain { margin: 6px 0; padding-left: 20px; }
.next { list-style: none; padding: 0; margin: 0; }
.next li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.next li > span:nth-child(2) { flex: 1; }

/* материалы */
.resources { list-style: none; padding: 0; margin: 6px 0 10px; }
.res { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.res:last-child { border-bottom: 0; }
.res > input[type=checkbox] { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.res-icon { width: 22px; text-align: center; flex: none; }
.res-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.res-main a { font-weight: 500; }

/* ---------- модули ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chip { flex: none; padding: 6px 14px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .9rem; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.module { padding: 0; overflow: hidden; }
.module .bar { margin: 0 18px 14px; }
.module.is-current { border-color: var(--accent); }
.module.is-done .t { color: var(--muted); }
.module-head { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 18px 8px; background: none; border: 0; cursor: pointer; text-align: left; }
.num { width: 32px; height: 32px; border-radius: 50%; border: 2px solid; display: grid; place-items: center; font-weight: 700; font-size: .9rem; flex: none; }
.module-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.module-title .t { font-weight: 600; }
.chev { color: var(--muted); }
.module-body { padding: 0 18px 18px; border-top: 1px solid var(--border); padding-top: 12px; }

/* ---------- графики ---------- */
.chart-wrap { position: relative; }
.weekchart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.wcol { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.wtrack { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.wbar { width: 100%; background: var(--border); border-radius: 6px 6px 2px 2px; }
.wbar.hit { background: var(--accent); }
.wval { font-size: .72rem; color: var(--muted); height: 16px; font-variant-numeric: tabular-nums; }
.wlabel { font-size: .68rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.goal-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--muted); opacity: .5; pointer-events: none; }
.goal { padding: 12px 0; border-bottom: 1px solid var(--border); }
.goal:last-child { border-bottom: 0; }
.goal .btn-row { margin: 8px 0 0; }
.goal-mini { margin: 6px 0; }
.goal-mini .row.small { margin: 6px 0 0; }
details summary { cursor: pointer; margin-top: 8px; }

.calc-result { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 8px; }
@media (max-width: 520px) { .calc-result { grid-template-columns: 1fr; } }
.legend { display: flex; gap: 16px; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.own, .cown { background: var(--border); }
.sw.grow, .cgrow { background: var(--good); }
.calc-chart { display: flex; align-items: flex-end; gap: 4px; height: 170px; }
.cwrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.ccol { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.cgrow { border-radius: 4px 4px 0 0; }

/* ---------- сегменты ---------- */
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.segmented button { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 9px; cursor: pointer; font-size: .9rem; color: var(--muted); }
.segmented button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- модалки и тосты ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10, 10, 15, .45); display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@media (min-width: 600px) { .overlay { align-items: center; } .modal { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.modal-head h3 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.center-col { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 12px 0; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .modal { animation: none; } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; transition: .25s;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100% - 32px);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; }
.logo { color: var(--accent); display: flex; justify-content: center; }
.logo svg { width: 44px; height: 44px; }
.error { color: var(--bad); min-height: 1.5em; margin: 0; }

/* ---------- привычки ---------- */
.habit-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.habit-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .95rem; }
.habit-chip.on { background: var(--good-soft); border-color: var(--good); }
.habit h3 { margin: 0 0 2px; }
.habit-toggle { flex: none; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--accent); background: var(--surface); color: var(--accent); font-weight: 600; cursor: pointer; }
.habit-toggle.on { background: var(--good); border-color: var(--good); color: #fff; }
.hgrid-head, .hgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.hgrid-head { margin-top: 12px; font-size: .7rem; color: var(--muted); text-align: center; }
.hcell { aspect-ratio: 1; max-height: 44px; border-radius: 8px; border: 0; background: var(--surface-2); color: var(--muted); font-size: .75rem; cursor: pointer; padding: 0; }
.hcell.on { background: var(--good); color: #fff; }
.hcell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.hcell.future { opacity: .3; cursor: default; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.grid-emoji { display: grid; grid-template-columns: 80px 1fr; gap: 12px; }

/* ---------- карточки ---------- */
.flash { min-height: 220px; display: flex; flex-direction: column; gap: 12px; }
.flash-front { font-size: 1.25rem; font-weight: 600; margin: 8px 0; }
.flash-sep { border-top: 1px dashed var(--border); margin: 4px 0 8px; }
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grade-row .btn { padding: 8px 4px; font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- ещё, поиск, статистика ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.tile > span:last-child { display: flex; flex-direction: column; }
.tile:hover { border-color: var(--accent); }
.tile-icon { font-size: 1.6rem; }
.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { flex: 1; }
input[type=search], input[type=time] { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; min-height: 42px; }
input[type=time] { width: auto; }
.back { display: inline-block; margin-bottom: 6px; text-decoration: none; font-size: .9rem; }
.list { list-style: none; padding: 0; margin: 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: var(--surface-2); }
.stats.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 520px) { .stats.four { grid-template-columns: 1fr 1fr; } .stats.four .stat:last-child { grid-column: auto; } }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.ach { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: var(--surface-2); opacity: .55; }
.ach.ok { opacity: 1; background: var(--accent-soft); }
.ach-icon { font-size: 1.5rem; width: 32px; text-align: center; }
.ai-box { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.status.ok { color: var(--warn); }

/* ---------- напоминания ---------- */
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.indent { padding-left: 30px; display: flex; flex-direction: column; gap: 8px; }
.day-row { display: flex; gap: 4px; flex-wrap: wrap; }
.day { width: 40px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .85rem; }
.day.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.code { background: var(--surface-2); padding: 3px 8px; border-radius: 6px; font-family: ui-monospace, Consolas, monospace; }
