:root {
  /* 24 рабочие клетки + по клетке поля слева и справа */
  --c: max(24px, min(34px, calc((100vw - 32px) / 26)));
  --paper: #fdfdfb;
  --line: #e1e3e6;
  --ink: #23408e;
  --ink-soft: #7d8db8;
  --red: #c62828;
  --pencil: #555;
  --hand: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

body {
  margin: 0;
  background: #eceef0;
  color: var(--pencil);
  font-family: var(--ui);
}

/* ---------- auth ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 16px;
}
.back-home { font-size: 13px; }
.card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 28px;
  background: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
.card h1 { margin: 0 0 4px; font: 400 28px var(--hand); color: var(--ink); }
.card label { display: grid; gap: 4px; font-size: 14px; }
.card input, .dialog input, .dialog select {
  font: 16px var(--ui);
  padding: 8px 10px;
  border: 1px solid #c9ccd1;
  border-radius: 4px;
  background: #fff;
  min-width: 0;
}
.card button[type=submit], .primary {
  font: 600 15px var(--ui);
  padding: 10px 16px;
  border: 0;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}
.card button[disabled] { opacity: .6; cursor: wait; }
.link { background: none; border: 0; color: var(--ink); cursor: pointer; font: 14px var(--ui); text-decoration: underline; }
.error { color: var(--red); margin: 0; min-height: 1em; font-size: 14px; }
/* Ссылка на Android-приложение внизу (в самом приложении скрыта). */
.app-footer { text-align: center; font-size: 13px; }
.app-footer a { color: var(--ink); }
.auth .app-footer { margin-top: 12px; }
.in-app .android-only-web { display: none; }

/* ---------- planner ---------- */
.app { padding: 16px; display: grid; justify-content: center; gap: 8px; }

.toolbar, .below {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: calc(var(--c) * 26);
  max-width: calc(100vw - 32px);
}
/* На узком экране лист прокручивается вбок, клетки не мельчают. */
.sheet-scroll { max-width: calc(100vw - 32px); overflow-x: auto; overscroll-behavior-x: contain; }
/* Горизонтальный жест листает недели, а не уводит браузер «Назад». */
html, body { overscroll-behavior-x: none; }
.icon-btn { display: grid; place-items: center; padding: 4px 7px !important; }
svg.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toolbar button, .below button, .dialog button:not(.primary) {
  font: 14px var(--ui);
  padding: 4px 10px;
  border: 1px solid #c9ccd1;
  border-radius: 4px;
  background: #fff;
  color: #333;
  cursor: pointer;
}
.toolbar #prev, .toolbar #next { font-size: 18px; line-height: 1; padding: 3px 10px 5px; }
.user { margin-left: 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
.user::before { content: "👤 "; }
.status { flex: 1; text-align: right; font-size: 12px; color: #888; }

/* Лист бумаги: чистое поле в одну клетку, внутри — сетка. */
.page {
  position: relative;
  width: calc(var(--c) * 26 + 1px);
  padding: var(--c);
  background: var(--paper);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
.sheet {
  display: grid;
  grid-template-columns: repeat(24, var(--c));
  grid-auto-rows: var(--c);
  width: calc(var(--c) * 24 + 1px);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: var(--c) var(--c);
  box-shadow: inset -1px -1px 0 var(--line);
  font-family: var(--hand);
  color: var(--ink);
}

.date, .dow {
  display: grid;
  place-items: center;
  line-height: 1;
}
.date { font-size: calc(var(--c) * .5); }
.dow { font-size: calc(var(--c) * .36); color: var(--ink-soft); }
.dow.today-col { color: var(--ink); }
.date.weekend, .dow.weekend { color: var(--red); }
.date.today span {
  display: grid;
  place-items: center;
  width: calc(var(--c) * .86);
  height: calc(var(--c) * .86);
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.month {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: calc(var(--c) * .2);
  font-size: calc(var(--c) * .55);
  letter-spacing: .04em;
  white-space: nowrap;
}
.month small { font-size: 1em; margin-left: .4em; }

.box {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
}
svg.mark { width: 100%; height: 100%; overflow: visible; }
svg.mark * { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
svg.mark .hatch { stroke-width: 1; }
.box.empty svg { opacity: 0; }
.box.empty:hover svg, .box.empty:focus-visible svg { opacity: .25; }
.box:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: -2px; }
.today-col { background: rgba(198, 40, 40, .045); }

/* Значок постоянной задачи — в углу клетки времени. */
.rec-icon {
  z-index: 1;
  align-self: start;
  justify-self: start;
  padding: 2px 0 0 2px;
  color: var(--ink-soft);
  pointer-events: none;
}
.rec-icon svg.icon { width: calc(var(--c) * .32); height: calc(var(--c) * .32); display: block; }

.field {
  min-width: 0;
  height: var(--c);
  padding: 0 calc(var(--c) * .15);
  border: 0;
  background: transparent;
  font: calc(var(--c) * .48) var(--hand);
  color: var(--ink);
  outline: none;
}
.field:focus { background: rgba(0, 0, 0, .035); }
.field.time { text-align: center; padding: 0; }
.field.amount { text-align: right; }
.field.invalid { color: var(--red); text-decoration: wavy underline var(--red); }
/* Закрытая задача: вся строка (время, текст, сумма) становится полупрозрачной. */
.field.done, .field.cancelled { opacity: .4; }
.task.cancelled { text-decoration: line-through; }

/* ---------- закладки недели (правое поле листа) ---------- */
.bookmarks {
  position: absolute;
  top: var(--c);
  right: 0;
  width: var(--c);
  display: grid;
  grid-auto-rows: var(--c);
}
.tab {
  margin: 15%;
  padding: 0;
  border: 1px solid var(--ink-soft);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font: calc(var(--c) * .4) / 1 var(--ui);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.tab svg.icon { width: 70%; height: 70%; }
.tab:hover { background: rgba(0, 0, 0, .05); }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: 1px; }

/* ---------- страница задачи в последней клетке ---------- */
.task-page {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.task-page svg.icon { width: 64%; height: 64%; }
/* «Лист с плюсом» виден, только когда наводят на саму клетку (или переходят на неё клавиатурой). */
.task-page:not(.has) { color: var(--ink-soft); opacity: 0; }
.task-page:not(.has):hover, .task-page:not(.has):focus-visible { opacity: .6; }
.task-page:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: -2px; }

/* ---------- текстовая страница ---------- */
.page-title {
  display: flex;
  align-items: center;
  padding: 0 calc(var(--c) * .2);
  font-size: calc(var(--c) * .55);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: underline;
  text-decoration-color: var(--ink-soft);
  text-underline-offset: 4px;
}
.page-btn {
  margin: 12%;
  padding: 0;
  border: 1px solid #c9ccd1;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.page-btn svg.icon { width: 70%; height: 70%; }
.page-delete:hover { color: var(--red); border-color: var(--red); }
/* Строки текста ложатся ровно на линейки: высота строки = клетка. */
.page-text {
  grid-row: 2 / span 31;
  min-width: 0;
  margin: 0;
  padding: 0 calc(var(--c) * .2);
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--ink);
  font: calc(var(--c) * .48) / var(--c) var(--hand);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- поднять / опустить задачу (в левом поле листа) ---------- */
.row-tools {
  position: absolute;
  left: 0;
  width: var(--c);
  height: var(--c);
  display: grid;
  grid-template-rows: 1fr 1fr;
}
.row-tools button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: calc(var(--c) * .32);
  line-height: 1;
  cursor: pointer;
}
.row-tools button:hover:not(:disabled) { color: var(--ink); }
.row-tools button:disabled { opacity: .25; cursor: default; }

/* ---------- звёздочка: скрыть финансы ---------- */
.star[aria-pressed="true"] { color: #c99a06; border-color: #c99a06 !important; }
.star[aria-pressed="true"] svg.icon { fill: currentColor; }
.money-hidden .field.amount { visibility: hidden; }

/* ---------- будильник: скрыть время ---------- */
.clock-toggle[aria-pressed="true"] { color: #fff; background: var(--ink) !important; border-color: var(--ink) !important; }

/* ---------- просроченная задача: день прошёл, квадрат открыт ---------- */
.box.overdue svg.mark * { stroke: var(--red); stroke-width: 2; }

/* ---------- totals ---------- */
.below-actions { display: flex; gap: 6px; margin-left: auto; }
.below { justify-content: space-between; }
.totals {
  margin: 0;
  line-height: 1.6;
  font: 16px var(--hand);
  color: var(--ink);
}

/* ---------- mark menu ---------- */
.mark-menu {
  position: fixed;
  z-index: 10;
  display: grid;
  min-width: 220px;
  padding: 4px;
  background: #fff;
  border: 1px solid #d5d8dc;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
.mark-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 0;
  border-radius: 4px;
  background: none;
  font: 14px var(--ui);
  color: #333;
  text-align: left;
  cursor: pointer;
}
.mark-menu button:hover, .mark-menu button:focus-visible { background: #eef1f6; outline: none; }
.mark-menu button.current { font-weight: 600; }
.mark-menu svg.mark { width: 26px; height: 26px; flex: none; }
.mark-menu .sep { height: 1px; margin: 4px 6px; background: #e5e7ea; }

/* ---------- dialogs ---------- */
.dialog {
  width: min(380px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
  color: #333;
}
.dialog.wide { width: min(560px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(30, 35, 45, .35); }
.dialog h2 { margin: 0 0 16px; font: 600 20px var(--ui); }
.dialog h3 { margin: 18px 0 8px; font: 600 15px var(--ui); }
.dialog fieldset { border: 0; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.dialog legend { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.dialog label { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.font-print { font-family: var(--ui); font-size: 17px; }
.font-script { font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive; font-size: 17px; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 50%; }
.swatch.blue { background: #23408e; }
.swatch.black { background: #1d1d1f; }
.swatch.gray { background: #7b8088; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.app-version { margin-right: auto; align-self: center; font-size: 12px; color: #999; }
.dlg-note { margin: 0 0 12px; font-size: 13px; color: #666; line-height: 1.4; }
.dlg-note:empty { display: none; }
.stack { display: grid; gap: 10px; }
.dialog .stack label { display: grid; gap: 4px; font-size: 14px; }
.admin .switch { font-size: 15px; }
.admin-create { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.dialog .admin-create label { display: grid; gap: 4px; font-size: 14px; }
.pw-row { display: flex; gap: 4px; }
.pw-row input { flex: 1; font-family: ui-monospace, Consolas, monospace !important; }
#admin-msg.ok { color: #2e7d32; }
.rec-list li .tag { font-size: 12px; color: #b26a00; }
@media (max-width: 520px) { .admin-create { grid-template-columns: 1fr; } }
.rec-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rec-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #f5f6f8;
  border-radius: 4px;
  font-size: 14px;
}
.rec-list li span { flex: 1; }
.rec-list li em { font-style: normal; color: #777; }
.rec-list .empty-note { background: none; color: #888; padding: 0; }
.rec-fields { display: grid; grid-template-columns: 72px 1fr 96px; gap: 6px; }
.rec-type { display: flex; gap: 16px; margin: 10px 0; }
.rec-days { display: flex; flex-wrap: wrap; gap: 6px; }
.rec-days label {
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid #d5d8dc;
  border-radius: 4px;
  font-size: 13px;
}
.rec-date { display: flex; gap: 6px; }
.rec-date input { width: 80px; }

/* ---------- финансы выключены в настройках ---------- */
.no-money #rec-amount { display: none; }
.no-money .rec-fields { grid-template-columns: 72px 1fr; }
.dialog .check { font-size: 15px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- быстрый вход: код ---------- */
.quick { justify-items: center; text-align: center; }
.q-user { margin: 0; font-size: 15px; color: #444; }
.q-dots { display: flex; gap: 12px; height: 16px; }
.q-dots span { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: 50%; }
.q-dots span.on { background: var(--ink); }
.q-pad { display: grid; grid-template-columns: repeat(3, 64px); gap: 10px; }
.q-pad button {
  height: 56px;
  border: 1px solid #c9ccd1;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: 500 22px var(--ui);
  cursor: pointer;
  touch-action: manipulation;
}
.q-pad button:active { background: #eef1f6; }
.q-pad .q-bio { display: grid; place-items: center; }
.q-pad .q-bio svg.icon { width: 28px; height: 28px; }
.quick.busy .q-pad { opacity: .5; pointer-events: none; }
.quick.shake .q-dots { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { .quick.shake .q-dots { animation: none; } }

/* ---------- главная страница ---------- */
.landing { --lw: 1080px; background: var(--paper); color: #2b2f36; min-height: 100vh; }
.landing a { color: var(--ink); }
.l-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: var(--lw);
  margin: 0 auto;
  padding: 12px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.l-logo { font: 400 24px var(--hand); text-decoration: none; margin-right: auto; }
.l-links { display: flex; gap: 20px; font-size: 15px; }
.l-links a { text-decoration: none; color: #444; }
.l-links a:hover { color: var(--ink); }
.l-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 6px;
  font: 600 15px var(--ui);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.l-btn.primary { background: var(--ink); color: #fff !important; border: 1px solid var(--ink); }
.l-btn.ghost { background: transparent; color: var(--ink); border: 1px solid #c9ccd1; }
.l-btn.big { padding: 12px 22px; font-size: 16px; }
.l-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 48px;
  max-width: var(--lw);
  margin: 0 auto;
  padding: 64px 16px 48px;
}
.l-hero h1 { margin: 0 0 16px; font: 400 40px/1.2 var(--hand); color: var(--ink); }
.l-hero p { margin: 0 0 24px; font-size: 18px; line-height: 1.6; max-width: 60ch; }
.l-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.l-hero-visual { display: grid; justify-items: center; }

/* Пример листа — те же классы, что на настоящем листе, со своей клеткой. */
.demo-sheet {
  --c: var(--dc);
  --dc: min(26px, calc((100vw - 48px) / 18));
  display: grid;
  grid-template-columns: repeat(18, var(--dc));
  grid-auto-rows: var(--dc);
  width: calc(var(--dc) * 18 + 1px);
  padding: var(--dc);
  box-sizing: content-box;
  background-color: #fff;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: var(--dc) var(--dc);
  background-position: var(--dc) var(--dc);
  background-clip: content-box;
  box-shadow: 0 8px 30px rgba(20, 30, 60, .12);
  transform: rotate(-1.2deg);
  font-family: var(--hand);
  color: var(--ink);
  pointer-events: none;
}
.demo-sheet .month { font-size: calc(var(--dc) * .5); }
.demo-text {
  display: flex;
  align-items: center;
  padding: 0 4px;
  font-size: calc(var(--dc) * .48);
  white-space: nowrap;
  overflow: hidden;
}
.demo-text.time { justify-content: center; }
.demo-text.amount { justify-content: flex-end; }
.demo-text.done, .demo-text.cancelled { opacity: .4; }
.demo-text.cancelled:not(.time):not(.amount) { text-decoration: line-through; }

.l-section { max-width: var(--lw); margin: 0 auto; padding: 48px 16px; scroll-margin-top: 64px; }
.l-section h2, .l-cta h2 { margin: 0 0 24px; font: 400 30px var(--hand); color: var(--ink); }
.l-features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.l-features article {
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.l-features h3 { margin: 12px 0 6px; font-size: 17px; color: #222; }
.l-features p { margin: 0; font-size: 15px; line-height: 1.55; color: #555; }
.l-ico { display: block; width: 36px; height: 36px; color: var(--ink); }
.l-ico svg { width: 100%; height: 100%; }
.l-ico svg.icon { width: 80%; height: 80%; margin: 10%; }
.l-security ul { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.l-security li { padding: 20px; border-left: 3px solid var(--ink); background: #f4f6fb; font-size: 15px; line-height: 1.55; }
.l-security b { display: block; margin-bottom: 6px; color: #222; }
#faq details { border-bottom: 1px solid var(--line); padding: 14px 0; max-width: 75ch; }
#faq summary { cursor: pointer; font-size: 17px; color: #222; }
#faq details p { margin: 10px 0 0; font-size: 15px; line-height: 1.6; color: #555; }
.l-cta { max-width: var(--lw); margin: 0 auto; padding: 48px 16px 64px; text-align: center; }
.l-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--lw);
  margin: 0 auto;
  padding: 20px 16px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: #777;
}
@media (max-width: 860px) {
  .l-links { display: none; }
  .l-hero { grid-template-columns: 1fr; gap: 32px; padding-top: 32px; }
  .l-hero h1 { font-size: 30px; }
  .l-features, .l-security ul { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .l-nav .l-btn.ghost { display: none; }
}
