:root {
  --bg: #14161a;
  --card: #1d2026;
  --card2: #262a33;
  --line: #2e333d;
  --text: #eceef2;
  --muted: #8c94a3;
  --accent: #ff7a1a;
  --accent-text: #fff;
  --accent-soft: rgba(255, 122, 26, .16);
  --danger: #ff5f5f;
  --h0: #262a33; --h1: #553722; --h2: #94501d; --h3: #d8691a; --h4: #ffa04a;
  --nav-h: 62px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f3ef;
  --card: #ffffff;
  --card2: #efebe5;
  --line: #e3ded6;
  --text: #1c1c1e;
  --muted: #777169;
  --accent: #e2600a;
  --accent-soft: rgba(226, 96, 10, .12);
  --h0: #ebe6de; --h1: #f8d4b6; --h2: #f2a86d; --h3: #e9792a; --h4: #b94f08;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--accent); }

.page {
  max-width: 620px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 4px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
  min-height: 100dvh;
}

/* нижняя навигация под большой палец */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .inner { display: flex; width: 100%; max-width: 620px; }
.bottom-nav a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: 11px; user-select: none;
}
.bottom-nav a .ic { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.bottom-nav a.on { color: var(--text); }
.bottom-nav a.on .ic { filter: none; opacity: 1; }

/* шапка периода */
.topbar { display: flex; justify-content: flex-end; gap: 4px; padding-top: 6px; min-height: 44px; align-items: center; }
.topbar .spacer { flex: 1; }
.chip {
  border: 0; background: none; color: var(--accent); font-size: 15px; padding: 8px 10px; border-radius: 10px;
}
.icon-btn {
  width: 44px; height: 44px; border: 0; background: none; border-radius: 12px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted); text-decoration: none;
}
.icon-btn:active { background: var(--card2); }

.head { display: flex; align-items: center; gap: 6px; margin: 2px 0 6px; }
.head .title { flex: 1; min-width: 0; text-align: center; border: 0; background: none; padding: 4px; border-radius: 12px; }
.head .title:active { background: var(--card2); }
.head h1 { margin: 0; font-size: 20px; line-height: 1.2; font-weight: 700; }
.head h1 .caret { font-size: 13px; color: var(--muted); vertical-align: middle; margin-left: 4px; }
.head small { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.nav-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-size: 22px; line-height: 1; flex: 0 0 auto;
}
.nav-btn:active { background: var(--card2); }

.rating { display: flex; gap: 8px; margin: 12px 0 4px; }
.rating button {
  flex: 1; height: 52px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--card); font-size: 26px; transition: transform .1s;
}
.rating button span { filter: grayscale(1); opacity: .45; transition: .15s; }
.rating button.on { border-color: var(--accent); background: var(--accent-soft); }
.rating button.on span, .rating button.auto span { filter: none; opacity: 1; }
.rating button.auto { border-style: dashed; border-color: var(--muted); }
.rating button:active { transform: scale(.96); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 2px 0; }


.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 4px 6px; margin: 12px 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 8px 8px; min-height: 50px; }
.list li + li { border-top: 1px solid var(--line); }
.list .num { color: var(--muted); font-size: 13px; width: 16px; text-align: right; flex: 0 0 auto; }
.list .txt { flex: 1; min-width: 0; word-break: break-word; }
.list button.txt { text-align: left; border: 0; background: none; padding: 6px 0; }
.list li.pending .txt { opacity: .6; }
.list li.pending .txt::after { content: " ⏳"; }
.list li.editing { flex-wrap: wrap; }
.list li.editing input {
  flex: 1 1 100%; height: 44px; background: var(--card2); border: 1px solid var(--accent); border-radius: 12px;
  padding: 0 12px; outline: none; font-size: 16px;
}
.edit-actions { display: flex; gap: 6px; width: 100%; padding-top: 6px; }
.edit-actions button {
  height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); padding: 0 14px; font-size: 15px;
}
.edit-actions .grow { flex: 1; }
.edit-actions .del { color: var(--danger); }
.edit-actions .save { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.empty { color: var(--muted); padding: 14px 10px; font-size: 15px; }

.add { display: flex; gap: 8px; margin: 10px 0 0; position: relative; }
.add input {
  flex: 1; min-width: 0; height: 52px; padding: 0 16px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--card); outline: none; font-size: 16px;
}
.add input:focus { border-color: var(--accent); }
.btn {
  height: 52px; min-width: 52px; padding: 0 18px; border-radius: 16px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 16px;
}
.btn:disabled { opacity: .4; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn.block { width: 100%; }
.counter { color: var(--muted); font-size: 13px; text-align: right; margin: 6px 4px 0; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.suggest button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 14px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

h2 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 26px 4px 8px; font-weight: 600; }
.group-h { font-size: 13px; margin: 10px 8px 0; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.group-h a { color: inherit; text-decoration: none; }
.plus {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2);
  color: var(--accent); font-size: 20px; flex: 0 0 auto; line-height: 1;
}
.plus.done { color: var(--muted); border-color: transparent; background: none; cursor: default; font-size: 16px; }
.list li.promoted .txt { color: var(--muted); }

/* модалка календаря — снизу, как шторка */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); border-radius: 22px 22px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  width: 100%; max-width: 480px; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; } }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; font-size: 17px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .dow { font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-grid button { position: relative; height: 46px; border: 0; background: none; border-radius: 12px; font-size: 16px; }
.cal-grid button:active { background: var(--card2); }
.cal-grid button.other { opacity: .3; }
.cal-grid button.today { color: var(--accent); font-weight: 700; }
.cal-grid button.sel { background: var(--accent); color: var(--accent-text); }
.cal-grid button i { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-grid button.sel i { background: var(--accent-text); }
.sheet .btn { margin-top: 10px; }

/* обзор года: 12 мини-месяцев */
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 12px; margin: 12px 0; }
@media (min-width: 560px) { .months { grid-template-columns: repeat(4, 1fr); } }
.mini h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.mini h4 a { color: inherit; text-decoration: none; }
.mini .g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini .g a, .mini .g span { aspect-ratio: 1; border-radius: 3px; background: var(--h0); display: block; }
.mini .g span { background: none; }
.mini .g a.l1 { background: var(--h1); } .mini .g a.l2 { background: var(--h2); }
.mini .g a.l3 { background: var(--h3); } .mini .g a.l4 { background: var(--h4); }
.mini .g a.today { outline: 1.5px solid var(--text); outline-offset: -1px; }
.legend { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); justify-content: flex-end; }
.legend .lg0 { background: var(--h0); } .legend .lg1 { background: var(--h1); } .legend .lg2 { background: var(--h2); }
.legend .lg3 { background: var(--h3); } .legend .lg4 { background: var(--h4); }
.hint.found { margin-top: 10px; }
.legend span { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.day-h { font-size: 13px; color: var(--muted); margin: 14px 6px 2px; }
.day-h a { color: inherit; text-decoration: none; }
.top .n { color: var(--muted); font-size: 13px; }

/* поиск */
.search-input {
  width: 100%; height: 52px; padding: 0 16px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--card); outline: none; font-size: 16px; margin-top: 10px;
}
.search-input:focus { border-color: var(--accent); }
mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 1px; }
.when { color: var(--muted); font-size: 13px; white-space: nowrap; text-decoration: none; }

/* вход */
.login { min-height: 90dvh; display: flex; flex-direction: column; justify-content: center; gap: 12px; max-width: 400px; margin: 0 auto; }
.login h1 { font-size: 34px; margin: 0; }
.login p { color: var(--muted); margin: 0 0 8px; }
.login input {
  height: 52px; padding: 0 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--card);
  outline: none; font-size: 16px;
}
.login input:focus { border-color: var(--accent); }
.login .err { color: var(--danger); min-height: 1.4em; }

.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 8px; min-height: 56px; }
.settings .row + .row { border-top: 1px solid var(--line); }
.settings .row a { text-decoration: none; }
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 11px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.offline { text-align: center; font-size: 13px; color: var(--muted); padding: 6px; }
