/* Тетрадь в клетку: клетка 24px, поля слева, строки стоят на линиях. */

:root {
  --paper: #FDFDFB;
  --grid: #DCE5F3;
  --grid-strong: #9DB1D6;
  --ink: #1F3A93;
  --text: #1D2433;
  --muted: #5B667C;
  --red: #C93A3A;
  --danger: #B3261E;
  --cell: 24px;
  --margin: 72px;
  --hand: "Bradley Hand", "Segoe Print", "Noteworthy", "Marker Felt", "Segoe Script", cursive;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141A2B;
    --grid: #212B47;
    --grid-strong: #44557F;
    --ink: #A9BBFF;
    --text: #E8ECF7;
    --muted: #9AA6C2;
    --red: #FF8A8A;
    --danger: #FF9A92;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  color: var(--text);
  font: 16px/24px var(--sans);
}

body.locked { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ───────── Страница ───────── */

#app {
  position: relative;
  max-width: 720px;
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 calc(136px + env(safe-area-inset-bottom));
}

/* Красные поля: двойная линия */
#app::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin);
  width: 5px;
  border-left: 1px solid var(--red);
  border-right: 1px solid var(--red);
  opacity: 0.8;
  pointer-events: none;
}

.top { padding: 24px 72px 0 calc(var(--margin) + 18px); }

.profile-btn {
  position: absolute;
  top: calc(28px + env(safe-area-inset-top));
  right: 16px;
  z-index: 2;
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  font: 400 22px/1 var(--hand);
}


h1 {
  margin: 0;
  font: 400 32px/48px var(--hand);
  color: var(--ink);
}

.banner {
  margin: 0 0 0;
  padding: 0 0 0 10px;
  border-left: 3px solid var(--ink);
  color: var(--muted);
  font-size: 14px;
  line-height: 24px;
}

h2.sec {
  margin: 24px 0 0;
  padding: 0 16px 0 calc(var(--margin) + 18px);
  font: 400 24px/24px var(--hand);
  color: var(--ink);
}

h2.sec.late { color: var(--danger); }

/* ───────── Строки ───────── */

.row {
  display: grid;
  grid-template-columns: var(--margin) 1fr;
  min-height: 48px;
}

.margin { display: flex; justify-content: center; align-items: flex-start; }

.time {
  padding-top: 12px;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lesson.now .time { box-shadow: inset 0 -3px 0 var(--ink); height: 36px; }

.row-body {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 16px 12px 18px;
  background: none;
  border: 0;
  text-align: left;
}

button.row-body:active { background: color-mix(in srgb, var(--ink) 8%, transparent); }

.row-title { display: block; overflow-wrap: anywhere; }
.row-title.done { color: var(--muted); text-decoration: line-through; }

.row-meta { display: block; color: var(--muted); font-size: 14px; }
.row-meta .subj { color: var(--ink); font-weight: 600; }
.row-meta .who { color: var(--text); }
.row-meta .subj + .who { margin-left: 8px; }
.row-meta .due { margin-left: 8px; }
.row-meta .due.late { color: var(--danger); font-weight: 600; }

.empty {
  margin: 0;
  padding: 12px 16px 12px calc(var(--margin) + 18px);
  color: var(--muted);
}

.link {
  display: inline;
  padding: 0;
  background: none;
  border: 0;
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

details.done-block summary {
  padding: 12px 16px 12px calc(var(--margin) + 18px);
  color: var(--muted);
  cursor: pointer;
}

/* Галочка стоит на полях, как номер в тетради */
.check {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: 2px;
  padding: 0;
  background: none;
  border: 0;
}

.check .box {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--paper);
}

.check svg { width: 16px; height: 16px; opacity: 0; stroke: var(--paper); }
.check[aria-checked="true"] .box { background: var(--ink); }
.check[aria-checked="true"] svg { opacity: 1; }

/* ───────── Нижняя панель ───────── */

#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 2px solid var(--ink);
}

#tabs button {
  position: relative;
  height: 56px;
  background: none;
  border: 0;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
}

#tabs button[aria-current="page"] { color: var(--ink); }

#tabs button[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: -2px;
  height: 4px;
  background: var(--ink);
}

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(56px + 2px + 16px + env(safe-area-inset-bottom));
  z-index: 6;
  height: 52px;
  padding: 0 22px;
  background: var(--ink);
  border: 0;
  border-radius: 26px;
  color: var(--paper);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(15, 25, 70, 0.35);
}

@media (min-width: 760px) {
  #tabs { left: calc(50% - 360px); right: calc(50% - 360px); border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); }
  .fab { right: calc(50% - 344px); }
}

/* ───────── Окна ───────── */

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 16, 40, 0.5);
}

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 3px solid var(--ink);
  border-radius: 16px 16px 0 0;
  animation: rise 0.18s ease-out;
}

@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

@media (min-width: 760px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 16px; max-height: 85vh; }
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.sheet-title { margin: 0; font: 400 26px/48px var(--hand); color: var(--ink); }

.icon-btn {
  width: 44px;
  height: 44px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
}

label { display: block; margin-top: 16px; color: var(--ink); font-weight: 600; }

input, textarea, select {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 0;
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--grid-strong);
  border-radius: 0;
  color: var(--text);
  font: 16px/24px var(--sans);
}

input:focus, textarea:focus, select:focus { border-bottom-color: var(--ink); }

textarea {
  min-height: 192px;
  padding: 0;
  border-bottom: 0;
  background-image: repeating-linear-gradient(to bottom, transparent 0 23px, var(--grid-strong) 23px 24px);
  background-attachment: local;
  resize: vertical;
}

textarea.short { min-height: 72px; }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.error { margin: 8px 0 0; color: var(--danger); font-weight: 600; min-height: 0; }

.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 24px;
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 8px;
  color: var(--paper);
  font-weight: 600;
}

.btn.ghost { background: transparent; color: var(--ink); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn[disabled] { opacity: 0.6; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.chip {
  min-width: 48px;
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  border: 2px solid var(--grid-strong);
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
}

.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.result { margin-top: 16px; }
.code { margin: 8px 0; padding: 8px 12px; border: 2px dashed var(--grid-strong); border-radius: 8px; font: 600 18px/24px ui-monospace, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
a.btn { display: grid; place-items: center; text-decoration: none; }
.result p { margin: 0; }
.result ul { margin: 8px 0 0; padding-left: 20px; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ───────── Вход и уведомления ───────── */

.login {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}

.login form { width: 100%; max-width: 360px; padding: 8px 16px 24px; background: var(--paper); border-top: 3px solid var(--ink); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(140px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: 90vw;
  padding: 12px 16px;
  background: var(--text);
  border-radius: 8px;
  color: var(--paper);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
