/* Тетрадь в клетку: бумага, чернильно-синий, жёлтый маркер */
:root {
  --bg: #F6F4EE;
  --grid: rgba(31, 63, 209, .07);
  --surface: #FFFFFF;
  --text: #16181D;
  --muted: #5B6070;
  --line: #E3E0D6;
  --line-strong: #D6D2C4;
  --ink: #1F3FD1;
  --ink-hover: #1530A8;
  --on-ink: #FFFFFF;
  --ink-soft: #E8ECFF;
  --hl: #FFE14D;
  --hl-soft: #FFF6C7;
  --exam: #C2410C;
  --row-line: #EEEBE2;
  --danger: #B42318;
  --shadow: 0 1px 0 rgba(22, 24, 29, .04);
}
body.dark {
  --bg: #121417;
  --grid: rgba(143, 166, 255, .06);
  --surface: #1B1E24;
  --text: #EEF0F5;
  --muted: #A3A8B6;
  --line: #2C3039;
  --line-strong: #3A3F4A;
  --ink: #8FA6FF;
  --ink-hover: #B0C0FF;
  --on-ink: #121417;
  --ink-soft: rgba(143, 166, 255, .14);
  --hl-soft: rgba(255, 225, 77, .12);
  --exam: #FF8A5C;
  --row-line: #262A32;
  --danger: #FF7A6E;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--text);
  font: 400 15px/1.4 Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.wrap.with-footer { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }

/* ---------- шапка ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: #1F3FD1; position: relative; overflow: hidden; flex-shrink: 0; display: grid; place-items: center; }
.logo::before { content: ""; position: absolute; left: 4px; right: 4px; top: 17px; height: 9px; background: var(--hl); transform: rotate(-8deg); border-radius: 2px; }
.logo svg { position: relative; }
.brand b { display: block; font: 700 12px/1.2 "JetBrains Mono", monospace; letter-spacing: .02em; }
.brand small { display: block; font-size: 12px; color: var(--muted); }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; }
.btn-ghost:hover { border-color: var(--line-strong); }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; flex-shrink: 0; }
.icon-btn:disabled { opacity: .4; cursor: default; }

.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font: 700 26px/1.15 Unbounded, Manrope, sans-serif; letter-spacing: -.01em; }
.title-row span { font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }

/* ---------- полоска дней ---------- */
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.dchip { min-height: 62px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 0; }
.dchip span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; opacity: .8; }
.dchip b { font: 700 17px/1 "JetBrains Mono", monospace; }
.dchip i { width: 5px; height: 5px; border-radius: 50%; margin-top: 3px; background: transparent; }
.dchip i.dot { background: var(--ink); }
.dchip.today { border-color: var(--ink); }
.dchip.on { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.dchip.on i.dot { background: var(--on-ink); }

/* ---------- карточка пары ---------- */
.card { display: flex; flex-direction: column; gap: 12px; width: 100%; text-align: left; padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.card:hover { border-color: var(--line-strong); }
.card.now { border: 2px solid var(--ink); padding: 15px; }
.card-main { display: flex; gap: 14px; }
.when { width: 52px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; padding-top: 2px; font-family: "JetBrains Mono", monospace; }
.when b { font-size: 26px; line-height: 1; color: var(--ink); }
.when small { font-size: 12px; font-weight: 500; color: var(--muted); }
.when small:first-of-type { margin-top: 6px; }
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; border: 1.5px solid var(--ink); color: var(--ink); }
.chip.prac { background: var(--ink); color: var(--on-ink); }
.chip.exam { background: var(--exam); border-color: var(--exam); color: var(--on-ink); }
.live { font-size: 12px; font-weight: 700; color: var(--ink); }
.subj { font-size: 16px; font-weight: 700; line-height: 1.3; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.now-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: -6px; }

.hw-preview { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 12px; background: var(--hl-soft); }
.hw-line { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 600; line-height: 1.35; }
.hw-line > span:last-child { min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hw-line.done > span:last-child { text-decoration: line-through; opacity: .6; }
.hw-more { font-size: 12px; color: var(--muted); padding-left: 38px; }
.tag { flex-shrink: 0; font: 700 11px/1 "JetBrains Mono", monospace; padding: 4px 6px; border-radius: 6px; background: var(--hl); color: #16181D; }
.add-hint { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: 12px; border: 1.5px dashed var(--line-strong); font-size: 14px; font-weight: 600; color: var(--ink); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 56px 16px; }
.empty b { font: 700 20px/1.2 Unbounded, sans-serif; }
.empty span { color: var(--muted); }
.orphan-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 0 -4px; }

/* ---------- экран пары ---------- */
.back { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; border: 0; background: none; padding: 0; font-weight: 600; color: var(--ink); }
.lesson-head { display: flex; flex-direction: column; gap: 12px; }
.lesson-head h1 { font-size: 23px; line-height: 1.2; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.fact { padding: 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fact small { font-size: 12px; color: var(--muted); }
.fact b { font-size: 15px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.section-title h2, label.section-label { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.section-title span { font-size: 13px; font-weight: 600; color: var(--muted); }
.hw { padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.hw-head { display: flex; align-items: center; gap: 10px; }
.ava { width: 32px; height: 32px; border-radius: 50%; background: var(--ink-soft); color: var(--ink); display: inline-grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.who b { font-size: 14px; }
.who small { font-size: 12px; color: var(--muted); }
.hw p { margin: 0; font-size: 15px; line-height: 1.45; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; }
.hw p.done { text-decoration: line-through; color: var(--muted); }
.photos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ph { padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; height: 120px; background: var(--bg); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.done-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px 0 10px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; font-weight: 700; }
.done-btn .box { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line-strong); display: inline-grid; place-items: center; color: transparent; }
.done-btn.on { background: var(--hl); border-color: #F0CF2C; color: #16181D; }
.done-btn.on .box { background: #16181D; border-color: #16181D; color: var(--hl); }
.icon-btn.danger { color: var(--danger); }

.form { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
textarea { width: 100%; min-height: 96px; resize: vertical; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 16px; line-height: 1.4; }
textarea::placeholder { color: var(--muted); opacity: .8; }
.attach { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1.5px dashed var(--line-strong); background: transparent; font-size: 14px; font-weight: 600; color: var(--ink); }
.attach.off { opacity: .5; pointer-events: none; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.pv { position: relative; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.pv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(22, 24, 29, .75); color: #fff; display: grid; place-items: center; padding: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.footer { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.footer > div { max-width: 560px; margin: 0 auto; }
.btn-primary { width: 100%; height: 52px; border-radius: 14px; border: 0; background: var(--ink); color: var(--on-ink); font-size: 16px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary:hover { background: var(--ink-hover); }
.btn-primary:disabled { opacity: .6; cursor: default; }

/* ---------- неделя ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.week-nav div { display: flex; flex-direction: column; align-items: center; text-align: center; }
.week-nav h1 { font-size: 20px; }
.week-nav span { font-size: 13px; color: var(--muted); }
.wday { border-radius: 18px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.wday.today { border: 2px solid var(--ink); }
.wday-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 14px 8px; }
.wday-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.wday-head span { font-size: 12px; font-weight: 600; color: var(--muted); }
.wday-head span.pill { font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--ink); color: var(--on-ink); }
.wrow { display: grid; grid-template-columns: 22px 44px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; border: 0; border-top: 1px solid var(--row-line); background: none; text-align: left; min-height: 52px; }
.wrow b { font: 700 15px/1 "JetBrains Mono", monospace; color: var(--ink); }
.wrow .t { font: 500 12px/1 "JetBrains Mono", monospace; color: var(--muted); }
.wrow .s { display: flex; flex-direction: column; min-width: 0; }
.wrow .s span:first-child { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wrow .s span:last-child { font-size: 12px; color: var(--muted); }
.wrow .tag.off { visibility: hidden; }
.wempty { padding: 4px 14px 12px; font-size: 13px; color: var(--muted); }

/* ---------- загрузка, ошибки, просмотр фото, тосты ---------- */
.skeleton { height: 120px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.error { padding: 20px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.viewer { position: fixed; inset: 0; z-index: 20; background: rgba(10, 11, 14, .94); display: grid; place-items: center; padding: 16px; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.viewer-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14); color: #fff; display: grid; place-items: center; }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: #16181D; color: #fff; font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast[hidden] { display: none; }
body.dark .toast { background: #EEF0F5; color: #16181D; }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
