:root {
  --bg: #f7f4ef;
  --surface: #fffdf9;
  --surface-2: #f0ebe3;
  --text: #1f1c18;
  --muted: #857b6f;
  --line: #e6dfd4;
  --accent: #d47716;
  --accent-ink: #fff;
  --accent-soft: #fbe7cf;
  --focus: #d4771666;
  --shadow: 0 1px 2px rgb(60 40 10 / 0.04), 0 6px 20px rgb(60 40 10 / 0.05);
  /* Тепловая карта: в светлой теме насыщеннее — больше записей */
  --h0: #ebe5db;
  --h1: #f6d9ad;
  --h2: #efb867;
  --h3: #dc8f2c;
  --h4: #a95d15;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "PT Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --cell: clamp(8px, calc((min(100vw, 760px) - 110px) / 53 - 2px), 13px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131313;
    --surface: #1c1c1c;
    --surface-2: #262626;
    --text: #ececea;
    --muted: #9a958d;
    --line: #2e2e2e;
    --accent: #f0a04b;
    --accent-ink: #1b1308;
    --accent-soft: #3a2a17;
    --focus: #f0a04b66;
    --shadow: none;
    /* В тёмной теме: чем светлее квадрат, тем больше записей */
    --h0: #242424;
    --h1: #4b3a22;
    --h2: #82602e;
    --h3: #cf9446;
    --h4: #ffd89a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #131313;
  --surface: #1c1c1c;
  --surface-2: #262626;
  --text: #ececea;
  --muted: #9a958d;
  --line: #2e2e2e;
  --accent: #f0a04b;
  --accent-ink: #1b1308;
  --accent-soft: #3a2a17;
  --focus: #f0a04b66;
  --shadow: none;
  --h0: #242424;
  --h1: #4b3a22;
  --h2: #82602e;
  --h3: #cf9446;
  --h4: #ffd89a;
  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 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* ---------- Верхняя панель ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.tabs {
  display: flex;
  gap: 2px;
  margin: 0 auto;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}

.tabs a {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}

.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.tools { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover, .icon-btn.active { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn svg circle[r="1.3"] { fill: currentColor; }

.menu { position: relative; }

.menu-list {
  position: absolute;
  right: 0;
  top: 42px;
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.15);
}

.menu-list a, .menu-list button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }
.menu-email { padding: 6px 10px 8px; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* ---------- Основа ---------- */

.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 16px 96px;
}

.loading { color: var(--muted); text-align: center; padding: 64px 0; }

.card {
  display: block;
  margin: 14px 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

h1, h2 { font-family: var(--serif); letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; margin: 0 0 10px; }
h2 a { text-decoration: none; }
h2 a:hover { color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:disabled { opacity: 0.6; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Заголовок периода ---------- */

.phead {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 6px;
}

.ptitle { flex: 1; text-align: center; min-width: 0; }
.ptitle h1 { margin: 0; font-size: clamp(1.35rem, 5vw, 1.8rem); line-height: 1.2; }
.psub { color: var(--muted); font-size: 0.9rem; display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }

.pill {
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
}

.arrow {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  font-size: 1.8rem;
  line-height: 1;
  text-decoration: none;
  color: var(--muted);
}

.arrow:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Полоса дней недели ---------- */

.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0; }

.wd {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0 4px;
  border-radius: 12px;
  text-decoration: none;
  border: 1px solid transparent;
}

.wd:hover { background: var(--surface-2); }
.wd-name { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.wd-num { font-weight: 600; }
.wd-mark { height: 20px; font-size: 0.9rem; display: grid; place-items: center; }
.wd.today .wd-num { color: var(--accent); }
.wd.cur { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.wd.future { opacity: 0.45; }

.dots { display: block; height: 6px; border-radius: 3px; background: var(--accent); opacity: 0.8; }
.dots.d1 { width: 6px; }
.dots.d2 { width: 12px; }
.dots.d3 { width: 18px; }

/* ---------- Оценка ---------- */

.moodrow { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 12px; }
.mood-label { color: var(--muted); font-size: 0.95rem; }
.moods { display: flex; gap: 6px; }

.mood {
  width: 44px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.3rem;
  cursor: pointer;
  filter: grayscale(1);
  opacity: 0.55;
  transition: transform 0.1s, opacity 0.15s, filter 0.15s;
}

.mood:hover { opacity: 0.9; filter: none; }
.mood:active { transform: scale(0.94); }
.mood.on { filter: none; opacity: 1; border-color: var(--accent); background: var(--accent-soft); }
.mood.auto { filter: none; opacity: 1; border-style: dashed; border-color: var(--accent); }
.mood-note { width: 100%; font-size: 0.82rem; color: var(--muted); }
.day .mood-note { display: none; }

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

.lines { list-style: none; margin: 0; padding: 0; }
.lines.numbered { counter-reset: line; }

.line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border-bottom: 1px dashed var(--line);
}

.lines.numbered .line::before {
  counter-increment: line;
  content: counter(line);
  width: 1.3em;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
  flex: none;
}

.line-text {
  flex: 1;
  padding: 8px 0;
  font-family: var(--serif);
  font-size: 1.08rem;
  overflow-wrap: anywhere;
  cursor: text;
}

.edit-input, .add-input, .search-input, .login-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
}

.edit-input { flex: 1; font-family: var(--serif); font-size: 1.08rem; margin: 4px 0; }
.edit-input:focus, .add-input:focus, .search-input:focus, .login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

.icon.del {
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  cursor: pointer;
  opacity: 0;
}

.line:hover .icon.del, .icon.del:focus-visible, .line.editing .icon.del { opacity: 1; }
.icon.del:hover { background: var(--surface-2); color: var(--text); }
@media (hover: none) { .icon.del { opacity: 0.5; } }

.adder { position: relative; margin-top: 12px; }
.add-input { font-family: var(--serif); font-size: 1.08rem; }

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

.chip {
  max-width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.92rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:hover, .chip.active { border-color: var(--accent); background: var(--accent-soft); }

.counter { margin-top: 8px; text-align: right; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); margin: 4px 0 0; }
.full-note { margin: 12px 0 0; color: var(--muted); font-style: italic; }

.nudge {
  padding: 14px 20px;
  text-decoration: none;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}

.nudge.subtle { background: none; border: 1px dashed var(--line); box-shadow: none; color: var(--muted); font-weight: 500; }
.nudge.subtle:hover { color: var(--text); }

/* ---------- Кандидаты в итоги ---------- */

.cands-block { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }

.cands-block > summary {
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.cands-block > summary::-webkit-details-marker { display: none; }
.cands-block > summary::before { content: '▸'; color: var(--muted); transition: transform 0.15s; }
.cands-block[open] > summary::before { transform: rotate(90deg); }

.count {
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.cgroup { margin-top: 12px; }
.cgroup-head { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.cgroup-head a { text-decoration: none; }
.cgroup-head a:hover { color: var(--text); text-decoration: underline; }
.cgroup > .small { display: inline-block; margin: 2px 0 0 0; text-decoration: none; }

.cands { list-style: none; margin: 4px 0 0; padding: 0; }
.cand { display: flex; align-items: center; gap: 10px; min-height: 38px; }
.cand span { font-family: var(--serif); overflow-wrap: anywhere; }

.plus {
  width: 30px;
  height: 30px;
  flex: none;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: none;
  color: var(--accent);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.plus:hover { background: var(--accent); color: var(--accent-ink); }
.plus:disabled { opacity: 0.4; }

/* ---------- Год ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.stat {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-value { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; line-height: 1.25; margin-top: 2px; overflow-wrap: anywhere; }
.stat-sub { color: var(--muted); font-size: 0.82rem; }

.hm-scroll { overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }

.hm {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: ". months" "days cells";
  gap: 4px 6px;
  width: max-content;
  margin: 0 auto;
}

.hm-months {
  grid-area: months;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  column-gap: 2px;
  font-size: 0.7rem;
  color: var(--muted);
}

.hm-month { white-space: nowrap; }

.hm-days {
  grid-area: days;
  display: grid;
  grid-template-rows: repeat(7, var(--cell));
  row-gap: 2px;
  font-size: 0.65rem;
  line-height: var(--cell);
  color: var(--muted);
}

.hm-cells {
  grid-area: cells;
  display: grid;
  grid-template-rows: repeat(7, var(--cell));
  grid-auto-columns: var(--cell);
  grid-auto-flow: column;
  gap: 2px;
}

.hc { display: block; width: var(--cell); height: var(--cell); border-radius: 2px; background: var(--h0); }
.hc.out { background: none; }
.hc.l1 { background: var(--h1); }
.hc.l2 { background: var(--h2); }
.hc.l3 { background: var(--h3); }
.hc.l4 { background: var(--h4); }
.hc.future { opacity: 0.4; }
.hc.today { outline: 1.5px solid var(--text); outline-offset: 1px; }
a.hc:hover { outline: 1.5px solid var(--accent); outline-offset: 1px; }

.hm-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

.hm-legend .hc { width: 11px; height: 11px; }

.months {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
  margin: 14px 0;
}

.mcell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-decoration: none;
}

.mcell:hover { border-color: var(--accent); }
.mname { font-size: 0.75rem; color: var(--muted); }
.mmood { height: 22px; color: var(--muted); }

.feed { margin-top: 28px; }
.feed > h2 { margin-bottom: 4px; }

.fday { padding: 14px 0; border-bottom: 1px solid var(--line); }
.fdate { display: flex; align-items: baseline; gap: 8px; text-decoration: none; font-weight: 600; }
.fdate:hover { color: var(--accent); }
.fwd { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.fmood { margin-left: auto; }
.fday ul { margin: 6px 0 0; padding-left: 20px; font-family: var(--serif); font-size: 1.05rem; }
.fday li { margin: 2px 0; overflow-wrap: anywhere; }
.more { display: flex; margin: 18px auto 0; }

/* ---------- Поиск ---------- */

.search-head h1 { margin: 0; flex: 1; text-align: left; }
.search-input { margin: 8px 0 6px; font-size: 1.05rem; }

.results { list-style: none; margin: 8px 0 0; padding: 0; }
.results a { display: block; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; }
.results a:hover .rtext { color: var(--accent); }
.rmeta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.82rem; }
.rtext { display: block; font-family: var(--serif); font-size: 1.08rem; margin-top: 2px; overflow-wrap: anywhere; }
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

.tag { padding: 0 7px; border-radius: 6px; background: var(--surface-2); font-size: 0.75rem; }
.tag.week, .tag.month, .tag.year { background: var(--accent-soft); color: var(--accent); }

/* ---------- Вход ---------- */

.login { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.login h1 { font-size: 2.2rem; margin: 8px 0 4px; }
.lead { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 16px; }
.features { list-style: none; padding: 0; margin: 0 0 24px; color: var(--muted); }
.features li { margin: 4px 0; }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form input { text-align: center; font-size: 1.05rem; padding: 12px; }
.login-form .btn { padding: 12px; }
.sent { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.sent p { margin: 4px 0; }

.verify { max-width: 420px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.verify .btn { min-width: 200px; margin-top: 8px; font-size: 1.05rem; }

/* ---------- Диалог и уведомления ---------- */

dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}

dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dlg { padding: 20px; }
.dlg h2 { margin: 0 0 8px; }
.dlg p { margin: 0 0 18px; overflow-wrap: anywhere; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  gap: 14px;
  align-items: center;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.92rem;
  transform: translate(-50%, 150%);
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
  pointer-events: none;
}

.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast .link { color: var(--accent); font-weight: 600; }

/* ---------- Телефоны ---------- */

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .tabs a { flex: 1; text-align: center; padding: 6px 4px; }
  .tools { margin-left: auto; }
  .card { padding: 16px; }
  .months { grid-template-columns: repeat(6, 1fr); }
  .stats { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.pending { margin: 14px 0 0; }
.pending a { color: var(--muted); }
.pending a:hover { color: var(--accent); }
