:root {
  --bg: #f6f6f8; --card: #ffffff; --text: #1c1c22; --muted: #6d6d78;
  --line: #e4e4ea; --accent: #e02424; --accent-soft: #fde7ef; --ok: #1f9d55; --warn: #d93025;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121216; --card: #1c1c22; --text: #ececf1; --muted: #9a9aa6;
  --line: #2c2c35; --accent: #ff5c5c; --accent-soft: #3a1b27; --ok: #4cc27f; --warn: #ff7066;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #121216; --card: #1c1c22; --text: #ececf1; --muted: #9a9aa6;
    --line: #2c2c35; --accent: #ff5c5c; --accent-soft: #3a1b27; --ok: #4cc27f; --warn: #ff7066;
  }
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.4 system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; }
.muted { color: var(--muted); } .small { font-size: 13px; }

#setup { padding: calc(var(--sat) + 28px) 20px 20px; max-width: 480px; margin: 0 auto; }
#setup h1 { margin: 0 0 4px; }
.list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.list button { text-align: left; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.list button.on { border-color: var(--accent); background: var(--accent-soft); }

#app { display: flex; flex-direction: column; height: 100%; max-width: 640px; margin: 0 auto; }
header { display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 10px) 16px 8px; }
.title { font-size: 20px; font-weight: 700; }
.icon { width: 40px; height: 40px; border-radius: 50%; font-size: 22px; color: var(--muted); }
.icon.on { color: var(--accent); background: var(--accent-soft); }
.banner { margin: 0 16px 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
main { flex: 1; overflow-y: auto; padding: 0 16px 96px; -webkit-overflow-scrolling: touch; }

.daybar { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.days { flex: 1; flex-wrap: nowrap; justify-content: space-between; gap: 4px; }
.chip { padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.days .chip { flex: 1; padding: 6px 0; text-align: center; border-radius: 12px; font-size: 13px; line-height: 1.25; position: relative; }
.days .chip b { display: block; font-size: 16px; }
.days .chip.today:not(.on) { border-color: var(--accent); }
.days .chip .dot { position: absolute; top: 4px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.days .chip.on .dot { background: #fff; }

.card, .lesson, .hw { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.lesson { display: flex; gap: 12px; }
.lesson .num { font-size: 22px; font-weight: 700; color: var(--accent); width: 22px; text-align: center; }
.lesson .body { flex: 1; min-width: 0; }
.lesson .subj { font-weight: 600; }
.lesson .meta { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.lesson .hwline { margin-top: 8px; padding: 6px 10px; border-radius: 8px; background: var(--bg); font-size: 14px; }
.lesson .hwline.done { text-decoration: line-through; color: var(--muted); }
.lesson .add { color: var(--accent); font-size: 14px; padding: 6px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; }
.seg button.on { background: var(--accent); color: #fff; }
.grp { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 14px 2px 6px; }
.grp.late { color: var(--warn); }
.hw { display: flex; gap: 12px; align-items: flex-start; }
.hw input[type=checkbox] { width: 22px; height: 22px; flex: none; margin-top: 2px; accent-color: var(--accent); }
.hw .body { flex: 1; min-width: 0; }
.hw .subj { font-weight: 600; }
.hw .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.hw.done .txt, .hw.done .subj { color: var(--muted); text-decoration: line-through; }
.hw .edit { color: var(--muted); padding: 2px 6px; }

.row-title { font-weight: 600; margin-bottom: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.wide { width: 100%; } .card .wide + .wide { margin-top: 8px; }
.primary { background: var(--accent); color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600; }
.ghost { padding: 11px 18px; border-radius: 12px; border: 1px solid var(--line); }
.danger { color: var(--warn); padding: 11px 6px; }
#setupGo { margin-top: 14px; }

.fab { position: fixed; right: 20px; bottom: calc(var(--sab) + 76px); width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 4px 14px rgba(0,0,0,.28); }
nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--sab); max-width: 640px; margin: 0 auto; }
nav button { flex: 1; padding: 14px 4px; color: var(--muted); font-size: 14px; }
nav button.on { color: var(--accent); font-weight: 600; }
.badge { background: var(--accent); color: #fff; font-size: 11px; border-radius: 999px; padding: 1px 6px; margin-left: 2px; }

#sheetWrap { position: fixed; inset: 0; z-index: 10; }
.backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--sab) + 16px); max-height: 92%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.sheet-title { font-size: 18px; font-weight: 700; }
.sheet-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.grow { flex: 1; }
.err { color: var(--warn); font-size: 14px; }

.seg.slim { margin-bottom: 10px; }
.chips.days.one { justify-content: center; }
.grp.daylink { display: block; width: 100%; text-align: left; padding: 0; }
.grp.today { color: var(--accent); }
.noles { font-size: 14px; padding: 0 2px 8px; }
#ioText { font: 13px/1.4 ui-monospace, Menlo, monospace; }
.ok { color: var(--ok); }

.lesson { border-left: 5px solid var(--c, var(--line)); background: var(--card);
  background: color-mix(in srgb, var(--c, transparent) 16%, var(--card)); }
.lesson .num { color: var(--c, var(--accent)); }
.toprow { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.ttag { flex: none; font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 3px 8px; border-radius: 6px;
  background: var(--c); color: #fff; min-width: 34px; text-align: center; }
.ttag.static { display: inline-block; vertical-align: middle; margin-left: 8px; padding: 1px 7px; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.sw { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; }
.sw.on { border-color: var(--text); }
.colrow { display: flex; align-items: center; width: 100%; text-align: left; padding: 11px 0; border-bottom: 1px solid var(--line); }
.dotc { width: 16px; height: 16px; border-radius: 50%; background: var(--c); margin-right: 12px; flex: none; }
.late { color: var(--warn); }

.cardActions { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center; }
.cardActions .add.quiet { color: var(--muted); }

/* заполнение пары по времени: лёгкая штриховка, серый перерыв */
.lesson { position: relative; overflow: hidden; isolation: isolate; }  /* isolate: содержимое не перекрывает нижнюю панель */
.lesson > .num, .lesson > .body { position: relative; z-index: 1; }
.prog { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.prog .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; box-sizing: border-box;
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c, var(--accent)) 26%, transparent) 0 3px, transparent 3px 8px);
  border-right: 2px solid color-mix(in srgb, var(--c, var(--accent)) 70%, transparent);
  transition: width .6s linear; }
.prog .fill.done { border-right: 0; }
.prog .brk { position: absolute; top: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, rgba(150,150,160,.38) 0 3px, rgba(150,150,160,.08) 3px 8px); }
.lbrk { font-size: 12px; opacity: .8; }
.lstat { font-weight: 600; color: var(--c, var(--accent)); }
nav { z-index: 5; }
.fab { z-index: 6; }
#leWrap, #colWrap, #ioWrap { position: fixed; inset: 0; z-index: 10; }

.nextbox { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
.nextbox .nb-main { font-weight: 700; }
.nextbox .nb-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* кнопки в окнах переносятся на новую строку, а не вылезают за экран */
.sheet-actions { flex-wrap: wrap; }
.sheet-actions button { white-space: nowrap; }
.switch-row { gap: 12px; padding: 6px 0; }
.switch-row input { flex: none; }
.lesson .hwline, .hw .txt { overflow-wrap: anywhere; }
.count { text-align: right; margin-top: -6px; }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--sab) + 148px); z-index: 8;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.toast button { color: var(--accent); font-weight: 700; padding: 4px 6px; }
.nextbox, .lstat { font-variant-numeric: tabular-nums; }
.ghost:disabled { opacity: .45; }
/* окно импорта/экспорта: две кнопки в ряд, главная на всю ширину */
#ioWrap .sheet-actions .grow { display: none; }
#ioWrap .sheet-actions button { flex: 1 1 40%; }
#ioWrap .sheet-actions .primary { flex: 1 1 100%; order: 3; }

/* ===== пары в одно время: один блок, один номер, без рамок у каждой пары ===== */
.lesson { padding: 0; gap: 0; align-items: stretch; border-left: 1px solid var(--line); background: var(--card); }
.lesson > .num { flex: none; width: 34px; padding: 12px 0 0; text-align: center; }
.lesson.multi > .num { color: var(--muted); }
.entries { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lentry { position: relative; isolation: isolate; overflow: hidden; display: flex; flex: 1 0 auto;
  padding: 10px 12px 10px 10px; border-left: 4px solid var(--c, var(--line));
  background: color-mix(in srgb, var(--c, transparent) 16%, var(--card)); }
.lentry + .lentry { border-top: 1px solid var(--line); }
.lentry > .body { position: relative; z-index: 1; flex: 1; min-width: 0; align-self: center; }
.fitact { display: none; }
.offline { color: var(--warn); }

/* ===== плашка отмены: компактная, в цветах темы, не закрывает расписание ===== */
.toast { left: 12px; right: auto; max-width: calc(100% - 96px); bottom: calc(var(--sab) + 64px);
  padding: 4px 4px 4px 14px; font-size: 14px; border-radius: 999px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.toast button { padding: 6px 12px; }

/* ===== режим «на экран» ===== */
body.fit main { overflow: hidden; padding-bottom: 0; }
body.fit header { padding-bottom: 2px; }
body.fit .seg.slim, body.fit .daybar { margin-bottom: 6px; }
body.fit .nextbox { padding: 6px 12px; margin-bottom: 6px; }
body.fit .nextbox .nb-sub { display: none; }
body.fit #lessons { overflow-y: auto; display: flex; flex-direction: column; gap: calc(6px * var(--k, 1)); }
body.fit .lesson { flex: 1 0 auto; margin-bottom: 0; }
body.fit .lesson > .num { width: calc(30px * var(--k, 1)); padding-top: calc(8px * var(--k, 1)); font-size: calc(18px * var(--k, 1)); }
body.fit .lentry { padding: calc(6px * var(--k, 1)) calc(10px * var(--k, 1)) calc(6px * var(--k, 1)) calc(8px * var(--k, 1)); }
body.fit .subj { font-size: calc(15px * var(--k, 1)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
body.fit .toprow { align-items: center; gap: calc(6px * var(--k, 1)); }
body.fit .ttag { font-size: calc(10px * var(--k, 1)); padding: 2px 6px; min-width: 0; }
body.fit .meta { font-size: calc(12px * var(--k, 1)); margin-top: 0; gap: 0 calc(10px * var(--k, 1)); }
body.fit .lbrk, body.fit .cardActions { display: none; }
body.fit #lessons.dense .meta + .meta { display: none; }
body.fit .hwline { margin-top: 3px; padding: 2px 8px; font-size: calc(12px * var(--k, 1)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.fit .fitact { display: flex; gap: 2px; flex: none; }
body.fit .fitact button { font-size: calc(17px * var(--k, 1)); line-height: 1; padding: 2px 6px; color: var(--accent); }
body.fit .subj { flex: 1; }
body.fit .tag { font-size: calc(11px * var(--k, 1)); padding: 0 calc(6px * var(--k, 1)); }
body.fit .fab { display: none; }   /* в режиме «на экран» у каждой пары есть своя кнопка «＋» */

/* ===== отклик на нажатия ===== */
button { transition: transform .1s ease, opacity .1s ease, background-color .15s ease, border-color .15s ease, color .15s ease; }
button:active:not(:disabled) { transform: scale(.95); opacity: .75; }
.fab:active:not(:disabled) { transform: scale(.9); }
.hwline:active, .chip:active { opacity: .7; }
button:disabled { opacity: .55; }
@keyframes spin { to { transform: rotate(360deg); } }
button.busy::before { content: ''; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
main > section { animation: fadein .18s ease-out; }
.toast { animation: fadein .18s ease-out; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* вид заполнения «линия внизу пары» */
.lentry.pline .prog .fill { top: auto; bottom: 0; height: 3px; background: var(--c, var(--accent)); border-right: 0; }
.lentry.pline .prog .brk { top: auto; bottom: 0; height: 3px; background: rgba(150,150,160,.7); }
