:root {
  --bg: #141416;
  --card: #1d1d20;
  --card-2: #232327;
  --line: #2e2e33;
  --text: #f3efe8;
  --muted: #9a979e;
  --faint: #67656c;
  --accent: #b8894a;
  --accent-text: #e7b062;
  --accent-soft: #33291b;
  --on-accent: #1b1408;
  --good: #86c79a;
  --bad: #e08a7c;
  --ok: #cfc9bd;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --radius: 22px;
  --nav-h: 76px;
  --gutter: 16px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f2ec;
  --card: #ffffff;
  --card-2: #efe9e0;
  --line: #e2dbd0;
  --text: #1f1c19;
  --muted: #6e6860;
  --faint: #a49e95;
  --accent: #b07d36;
  --accent-text: #94631f;
  --accent-soft: #f3e6cf;
  --on-accent: #fffaf2;
  --good: #3d8a55;
  --bad: #c0533f;
  --ok: #6e6860;
  --shadow: 0 10px 40px rgba(60, 40, 10, .15);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; opacity: .35; }
input, textarea { font: inherit; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ---------- shell ---------- */
.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px var(--gutter) calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
}
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.nav a {
  flex: 1; text-align: center;
  padding: 14px 0; border-radius: 999px;
  color: var(--muted); font-weight: 500; font-size: 15px;
}
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.brand { display: none; }
body.gated .nav { display: none; }
@media (max-width: 899px) {
  body.typing .nav { display: none; }
  .only-wide { display: none !important; }
}
body.loading::before {
  content: ""; position: fixed; top: 0; left: 0; height: 2px; width: 40%; z-index: 30;
  background: var(--accent-text);
  animation: load 1s ease-in-out infinite;
}
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.loading-screen { padding: 40vh 0; text-align: center; color: var(--faint); }

/* ---------- header ---------- */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 28px; }
.head-text { min-width: 0; position: relative; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.title-btn { display: inline-flex; align-items: center; gap: 8px; text-align: left; }
.title-btn h1, .head h1 { font: 600 34px/1.15 var(--serif); letter-spacing: -.01em; }
.title-btn svg { color: var(--muted); flex: none; margin-top: 6px; }
.date-pick { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.subtitle { margin-top: 6px; color: var(--muted); }
.head-nav { display: flex; gap: 8px; flex: none; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 16px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); background: var(--card);
  color: var(--text);
}
.icon-btn.disabled { opacity: .35; pointer-events: none; }
.icon-btn.ghost { background: transparent; }

/* ---------- blocks ---------- */
.block { margin-bottom: 32px; }
.label { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.label-row .label { margin: 0; }
.block > .label { margin-bottom: 14px; }
.counter { font-size: 15px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.card { background: var(--card); border-radius: var(--radius); }
.note { color: var(--muted); font-size: 15px; }
.hint { margin-top: 12px; color: var(--faint); font-size: 14px; }
.empty { color: var(--faint); padding: 4px 0; }

/* ---------- moods ---------- */
.moods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mood {
  display: grid; justify-items: center; gap: 6px;
  padding: 16px 8px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--muted);
  transition: border-color .15s, background .15s, color .15s;
}
.mood .emoji { font-size: 30px; line-height: 1; filter: grayscale(1); opacity: .75; transition: filter .15s, opacity .15s; }
.mood.on { background: var(--card); }
.mood.on .emoji { filter: none; opacity: 1; }
.mood.on.good { border-color: var(--good); color: var(--good); }
.mood.on.bad { border-color: var(--bad); color: var(--bad); }
.mood.on.ok { border-color: var(--ok); color: var(--text); }
.mi { display: inline-block; width: 1.2em; text-align: center; }
.mi.none { filter: grayscale(1); opacity: .45; }

.mood-card { padding: 22px 24px; margin-bottom: 32px; }
.mood-card .label { display: block; margin-bottom: 14px; }
.mood-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mood-emoji { font-size: 32px; line-height: 1; }
.mood-emoji.none { filter: grayscale(1); opacity: .45; }
.mood-name { font-size: 26px; font-weight: 600; letter-spacing: .02em; }
.mood-name.good { color: var(--good); }
.mood-name.bad { color: var(--bad); }
.mood-name.ok { color: var(--text); }
.mood-name.muted { color: var(--muted); font-size: 20px; font-weight: 500; letter-spacing: 0; }
.badge { padding: 5px 12px; border-radius: 999px; background: var(--card-2); font-size: 14px; color: var(--muted); }
button.badge { color: var(--accent-text); }
.mood-adjust { margin-left: auto; display: flex; gap: 8px; }

/* ---------- entries ---------- */
.entries { display: grid; gap: 8px; margin-bottom: 12px; }
.entries:empty { display: none; }
.entry {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 10px 12px 14px;
  background: var(--card); border-radius: 18px;
}
.entry.removing { opacity: .4; }
.entry-text { flex: 1; min-width: 0; padding: 3px 0; white-space: pre-wrap; overflow-wrap: anywhere; cursor: text; }
.entry .bullet { flex: none; width: 22px; padding-top: 3px; color: var(--accent-text); font-weight: 600; font-variant-numeric: tabular-nums; }
.star, .del { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; color: var(--faint); }
.star[aria-pressed="true"] { color: var(--accent-text); }
.del:hover, .star:hover { background: var(--card-2); }
.edit-input {
  width: 100%; resize: none; border: 0; outline: 0; padding: 0; margin: 0;
  background: transparent; line-height: 1.45; display: block;
}

.add { display: flex; gap: 12px; align-items: flex-end; }
.add textarea {
  flex: 1; min-width: 0; resize: none;
  min-height: 56px; max-height: 200px;
  padding: 15px 22px; border-radius: 28px;
  background: var(--card); border: 1px solid var(--line); outline: 0;
  line-height: 1.45;
}
.add textarea:focus { border-color: var(--accent); }
.add textarea::placeholder { color: var(--faint); }
.add-btn {
  flex: none; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
}

/* ---------- candidates ---------- */
.cands { display: grid; gap: 8px; }
.cand {
  width: 100%; display: flex; align-items: flex-start; gap: 12px; text-align: left;
  padding: 13px 16px; border-radius: 18px;
  border: 1px dashed var(--line);
}
.cand:hover:not(:disabled) { border-color: var(--accent); }
.cand .plus { color: var(--accent-text); flex: none; padding-top: 2px; }
.cand-text { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.cand-meta { flex: none; display: flex; align-items: center; gap: 4px; color: var(--faint); font-size: 14px; padding-top: 2px; }
.cand-meta svg { color: var(--accent-text); }
.cands-more { display: none; }
.cands.open .cands-more { display: block; }
.link-btn { color: var(--accent-text); font-weight: 500; padding: 10px 0; }

/* ---------- children (days of a week, weeks of a month, months of a year) ---------- */
.children { display: grid; gap: 10px; }
.child { display: block; padding: 18px 20px; }
.child.is-today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.child.is-future { opacity: .45; }
.child-head { display: flex; align-items: baseline; gap: 10px; }
.child-head .mi { align-self: center; }
.child-title { font-weight: 600; font-size: 18px; }
.child-sub { color: var(--muted); font-size: 15px; }
.child-head .chev { margin-left: auto; color: var(--faint); align-self: center; }
.child-list { margin: 8px 0 0 32px; display: grid; gap: 4px; }
.child-list li { position: relative; overflow-wrap: anywhere; }
.child-list li::before { content: "•"; position: absolute; left: -14px; color: var(--accent-text); }
.child-list li.starred::before { content: "★"; font-size: 12px; left: -16px; top: 2px; }
.child-empty, .child-more { margin: 6px 0 0 32px; color: var(--faint); font-size: 15px; }

/* ---------- post of the day ---------- */
.post { padding: 22px 24px; margin-bottom: 32px; }
.post .label { display: block; margin-bottom: 12px; }
.post-text { font: 500 18px/1.55 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.post-text.clamped { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.post-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.post-src { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.post-src:hover { color: var(--accent-text); }

/* ---------- overview ---------- */
.head-actions { display: flex; gap: 8px; flex: none; }
.search { position: relative; margin-bottom: 28px; }
.search svg { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 56px; padding: 0 20px 0 52px;
  border-radius: 28px; border: 1px solid var(--line); background: transparent; outline: 0;
}
.search input:focus { border-color: var(--accent); }
.search input::placeholder { color: var(--faint); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 32px; }
.stat { padding: 20px 24px; }
.stat b { display: block; font: 600 36px/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); }

.heat-card { padding: 20px 20px 18px; margin-bottom: 32px; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--card-2); }
.seg button { padding: 6px 14px; border-radius: 999px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.heat { --cell: 13px; --gap: 4px; display: flex; gap: 8px; }
.heat-days { display: grid; grid-template-rows: repeat(7, var(--cell)); gap: var(--gap); padding-top: 22px; font-size: 12px; color: var(--muted); line-height: var(--cell); }
.heat-scroll { overflow-x: auto; scrollbar-width: none; flex: 1; }
.heat-scroll::-webkit-scrollbar { display: none; }
.heat-months { position: relative; height: 22px; font-size: 12px; color: var(--muted); }
.heat-months span { position: absolute; top: 0; white-space: nowrap; }
.heat-grid { display: flex; gap: var(--gap); width: max-content; }
.hcol { display: grid; grid-template-rows: repeat(7, var(--cell)); gap: var(--gap); }
.hc { width: var(--cell); height: var(--cell); border-radius: 3px; background: var(--card-2); display: block; }
.hc.future { background: transparent; }
.hc.today { box-shadow: 0 0 0 1.5px var(--accent-text); }
.hc.l1 { background: color-mix(in srgb, var(--accent) 35%, var(--card-2)); }
.hc.l2 { background: color-mix(in srgb, var(--accent) 60%, var(--card-2)); }
.hc.l3 { background: color-mix(in srgb, var(--accent) 82%, var(--card-2)); }
.hc.l4 { background: var(--accent-text); }
.hc.m0 { background: var(--bad); }
.hc.m1 { background: color-mix(in srgb, var(--ok) 45%, var(--card-2)); }
.hc.m2 { background: var(--good); }
.hc.m-none { background: color-mix(in srgb, var(--muted) 25%, var(--card-2)); }
.heat-legend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 12px; font-size: 12px; color: var(--muted); }
.heat-legend .hc { width: 11px; height: 11px; }

.facts { padding: 6px 22px; margin-bottom: 32px; }
.fact { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 0; }
.fact + .fact { border-top: 1px solid var(--line); }
.fact span { color: var(--muted); }
.fact b { font-weight: 600; text-align: right; }
.fact small { color: var(--muted); font-weight: 400; margin-left: 4px; }

.journal { display: grid; gap: 10px; }
.jday { display: block; padding: 20px 22px; }
.jday-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.jday-title { font: 600 20px/1.3 var(--serif); }
.jday-rel { color: var(--muted); font-size: 15px; flex: none; }
.jday-mood { margin-top: 8px; color: var(--muted); }
.jday .child-list { margin-left: 18px; }

.results { display: grid; gap: 8px; }
.result { display: block; padding: 14px 18px; }
.result-meta { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.result mark { background: var(--accent-soft); color: var(--accent-text); border-radius: 4px; padding: 0 2px; }
.footer { text-align: center; color: var(--faint); font-size: 14px; padding: 24px 0 8px; }

/* ---------- gate, toast, sheet ---------- */
.gate { min-height: 80vh; display: grid; place-content: center; justify-items: center; text-align: center; gap: 12px; padding: 0 24px; }
.gate-mark { font-size: 56px; }
.gate h1 { font: 600 28px/1.2 var(--serif); }
.gate p { color: var(--muted); max-width: 360px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 16px;
  width: max-content; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 16px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: var(--accent); font-weight: 600; white-space: nowrap; }

.sheet { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; justify-items: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.sheet-body {
  position: relative; width: 100%; max-width: 520px;
  padding: 28px 24px calc(24px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0; background: var(--card); box-shadow: var(--shadow);
}
.sheet-body h2 { font: 600 24px/1.2 var(--serif); margin-bottom: 10px; }
.sheet-body p { color: var(--muted); margin-bottom: 16px; }
.invite-link { padding: 14px 16px; border-radius: 14px; background: var(--card-2); font-size: 14px; overflow-wrap: anywhere; user-select: all; margin-bottom: 16px; }
.sheet-actions { display: grid; gap: 10px; }
.btn { height: 52px; border-radius: 26px; border: 1px solid var(--line); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- wide screens: Telegram Desktop, browser ---------- */
@media (min-width: 900px) {
  :root { --nav-h: 0px; }
  .app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
  .nav {
    position: sticky; top: 0; height: 100vh;
    flex-direction: column; gap: 4px;
    padding: 32px 16px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav a { flex: none; text-align: left; padding: 11px 18px; }
  .brand { display: block; font: 600 22px/1.2 var(--serif); padding: 0 18px 28px; }
  .view { max-width: 1120px; margin: 0; padding: 40px 48px 56px; }
  .layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 40px; align-items: start; }
  .layout-day { grid-template-areas: "main side"; }
  .layout-day .col-main { grid-area: main; }
  .layout-day .col-side { grid-area: side; position: sticky; top: 40px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .toast { bottom: 32px; }
  .sheet { align-items: center; }
  .sheet-body { border-radius: 28px; }
  .heat { --cell: 14px; }
}
@media (max-width: 380px) {
  .title-btn h1, .head h1 { font-size: 28px; }
  .icon-btn { width: 42px; height: 42px; border-radius: 14px; }
  .mood-card, .post { padding: 18px; }
}
