/* ---------- Fonts (self-hosted, OFL) ---------- */
@font-face { font-family: "Literata"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(fonts/literata-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Literata"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(fonts/literata-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }
@font-face { font-family: "Literata"; font-weight: 400; font-style: italic; font-display: swap;
  src: url(fonts/literata-cyrillic-400-italic.woff2) format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Literata"; font-weight: 400; font-style: italic; font-display: swap;
  src: url(fonts/literata-latin-400-italic.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }
@font-face { font-family: "Literata"; font-weight: 600; font-style: normal; font-display: swap;
  src: url(fonts/literata-cyrillic-600-normal.woff2) format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Literata"; font-weight: 600; font-style: normal; font-display: swap;
  src: url(fonts/literata-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }
@font-face { font-family: "Golos"; font-weight: 400; font-display: swap;
  src: url(fonts/golos-text-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Golos"; font-weight: 400; font-display: swap;
  src: url(fonts/golos-text-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }
@font-face { font-family: "Golos"; font-weight: 500; font-display: swap;
  src: url(fonts/golos-text-cyrillic-500-normal.woff2) format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Golos"; font-weight: 500; font-display: swap;
  src: url(fonts/golos-text-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }
@font-face { font-family: "Golos"; font-weight: 600; font-display: swap;
  src: url(fonts/golos-text-cyrillic-600-normal.woff2) format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Golos"; font-weight: 600; font-display: swap;
  src: url(fonts/golos-text-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }

/* ---------- Tokens ---------- */
:root {
  --night: #151a36;     /* page */
  --dusk: #1f2549;      /* raised surfaces */
  --dusk-2: #2a3160;    /* pressed / my chat bubble */
  --mist: #ebe7f6;      /* main text */
  --haze: #a6a3c6;      /* secondary text */
  --faint: #6c6a96;     /* tertiary, empty nights */
  --line: rgba(235, 231, 246, 0.09);
  --dawn: #f4b886;      /* accent: the moment of waking */
  --lucid: #9de2d4;     /* lucid dreams only */

  --serif: "Literata", Georgia, serif;
  --sans: "Golos", -apple-system, "Segoe UI", Roboto, sans-serif;

  --pad: 20px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(120% 60% at 50% -10%, #232a57 0%, rgba(35, 42, 87, 0) 60%),
    var(--night);
  background-attachment: fixed;
  color: var(--mist);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--dawn); outline-offset: 2px; border-radius: 6px; }

#view {
  padding: 18px var(--pad) calc(var(--tabbar-h) + var(--safe-b) + 28px);
  max-width: 640px;
  margin: 0 auto;
}
body.no-tabs #view { padding-bottom: calc(var(--safe-b) + 32px); }

/* ---------- Type ---------- */
.page-title {
  font: 600 30px/1.15 var(--serif);
  letter-spacing: -0.01em;
  margin: 6px 0 4px;
}
.page-sub { color: var(--haze); margin: 0 0 18px; }
.h2 {
  font: 600 19px/1.3 var(--serif);
  margin: 34px 0 12px;
}
.muted { color: var(--haze); }
.small { font-size: 13px; }

/* ---------- Night sky (last 30 nights) ---------- */
.sky { margin: 4px 0 22px; }
.sky-row {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  align-items: center;
  height: 18px;
}
.star {
  justify-self: center;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--faint);
  opacity: 0.55;
}
.star.on { width: 7px; height: 7px; background: var(--dawn); opacity: 1;
  box-shadow: 0 0 8px rgba(244, 184, 134, 0.55); }
.star.lucid { background: var(--lucid); box-shadow: 0 0 9px rgba(157, 226, 212, 0.7); }
.sky-caption { display: flex; justify-content: space-between; margin-top: 6px;
  font-size: 13px; color: var(--haze); }
.sky-caption b { color: var(--mist); font-weight: 500; }

/* ---------- Search + filters ---------- */
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--dusk);
  border-radius: 14px;
  padding: 0 14px;
  height: 46px;
}
.search svg { width: 18px; height: 18px; flex: none; stroke: var(--haze); fill: none; stroke-width: 2; }
.search input {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: 0;
  color: var(--mist); font: 400 16px var(--sans);
}
.search input::placeholder { color: var(--faint); }
.chips {
  display: flex; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  margin: 12px calc(var(--pad) * -1) 0;
  padding: 0 var(--pad);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: none;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 14px;
  color: var(--haze);
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--mist); color: var(--night); border-color: var(--mist); }
.chip.lucid-chip { color: var(--lucid); border-color: rgba(157, 226, 212, 0.35); }
.chip.lucid-chip[aria-pressed="true"] { background: var(--lucid); color: var(--night); }

/* ---------- Dream list ---------- */
.month {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 30px 0 4px;
  color: var(--haze); font-size: 14px;
}
.month strong { font: 600 15px var(--sans); color: var(--mist); }
.dream-row {
  display: block;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.dream-row:last-child { border-bottom: 0; }
.night { font-size: 13px; color: var(--dawn); display: flex; gap: 10px; align-items: center; }
.lucid-mark { color: var(--lucid); }
.dream-row .title { font: 600 19px/1.3 var(--serif); margin: 4px 0 6px; }
.dream-row .excerpt {
  margin: 0; color: var(--haze); font-size: 14.5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tags { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 13px; color: var(--faint); }
.tags span::before { content: "#"; opacity: 0.6; }

/* ---------- Dream page ---------- */
.back {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--mist); font-size: 15px; margin: 0 0 14px -4px;
  background: var(--dusk); border: 0; border-radius: 999px;
  padding: 7px 14px 7px 10px; cursor: pointer;
}
.dream-head .night { font-size: 14px; }
.dream-head .page-title { margin-top: 8px; }
.feel { font: italic 400 16px var(--serif); color: var(--haze); margin: 6px 0 0; }
.dream-head .tags { margin-top: 12px; }
.meta-line { margin-top: 10px; font-size: 13px; color: var(--faint); }
.lucid-banner {
  margin-top: 14px;
  display: inline-block;
  color: var(--lucid);
  border: 1px solid rgba(157, 226, 212, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
}

.seg {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--dusk);
  border-radius: 12px; padding: 4px;
  margin: 26px 0 18px;
}
.seg button {
  border: 0; background: none; border-radius: 9px;
  padding: 9px 0; font-size: 14px; color: var(--haze); cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--dusk-2); color: var(--mist); font-weight: 500; }

.prose { font: 400 17px/1.7 var(--serif); }
.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { font-weight: 600; color: var(--mist); }
.prose ul, .prose ol { padding-left: 1.2em; margin: 0 0 1em; }
.prose li { margin-bottom: 0.45em; }
.prose h2 { font: 600 19px/1.3 var(--serif); margin: 30px 0 10px; }
.prose.compact { font-size: 16px; line-height: 1.6; }

.section { margin-top: 34px; }
.section > .h2 { margin-top: 0; }
.panel {
  background: var(--dusk);
  border-radius: 16px;
  padding: 18px;
}
.panel.dawn-edge { border-left: 3px solid var(--dawn); border-radius: 4px 16px 16px 4px; }

.btn {
  display: flex; justify-content: center; align-items: center; gap: 8px;
  width: 100%;
  margin-top: 14px;
  border: 0; border-radius: 12px;
  background: var(--dawn); color: #2a1b10;
  font: 600 15px var(--sans);
  padding: 13px 16px;
  cursor: pointer;
}
.btn.ghost { background: var(--dusk-2); color: var(--mist); font-weight: 500; }

.pager { display: grid; gap: 10px; margin-top: 40px; }
.pager a { display: block; padding: 14px 16px; border-radius: 14px; background: var(--dusk); }
.pager .small { color: var(--haze); }
.pager .t { font: 600 16px var(--serif); margin-top: 2px; }

/* ---------- Discussion ---------- */
.chat { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.msg { max-width: 88%; font-size: 15.5px; line-height: 1.55; }
.msg p { margin: 0 0 0.6em; } .msg p:last-child { margin: 0; }
.msg.me { align-self: flex-end; background: var(--dusk-2); padding: 11px 14px; border-radius: 16px 16px 4px 16px; }
.msg.ai { align-self: flex-start; padding: 2px 0 2px 14px; border-left: 2px solid var(--dawn); color: var(--mist); }
.msg .who { display: block; font-size: 12px; color: var(--haze); margin-bottom: 3px; }
.linkback { display: block; padding: 14px 16px; border-radius: 14px; background: var(--dusk); margin-top: 6px; }
.linkback .t { font: 600 16px var(--serif); }

/* ---------- Signs ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 8px 0 0; }
.stat { background: var(--dusk); border-radius: 14px; padding: 14px 12px; }
.stat .n { font: 600 28px/1 var(--serif); }
.stat .l { margin-top: 6px; font-size: 13px; color: var(--haze); line-height: 1.3; }
.stat.lucid .n { color: var(--lucid); }

.sign { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sign:last-child { border-bottom: 0; }
.sign-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.sign-name { font: 600 17px var(--serif); }
.sign-count { font-size: 14px; color: var(--mist); }
.bar { height: 4px; border-radius: 4px; background: var(--line); margin: 8px 0 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--dawn); }
.sign .small { color: var(--faint); }

.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 120px; }
.mcol { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.mcol .col { width: 100%; max-width: 18px; border-radius: 5px 5px 2px 2px; background: var(--dusk-2); min-height: 3px; }
.mcol .col.has { background: var(--dawn); }
.mcol .n { font-size: 11px; color: var(--haze); }
.mcol .lbl { font-size: 11px; color: var(--faint); }

.emo { display: flex; flex-wrap: wrap; gap: 8px; }
.emo span { background: var(--dusk); border-radius: 10px; padding: 7px 12px; font-size: 14px; }
.emo b { font-weight: 500; color: var(--haze); margin-left: 6px; }

/* ---------- Reports ---------- */
.report-row { display: block; padding: 16px; border-radius: 16px; background: var(--dusk); margin-bottom: 10px; }
.report-row.pinned { background: linear-gradient(160deg, #2b2f63 0%, #23285a 100%); box-shadow: inset 0 0 0 1px rgba(244, 184, 134, 0.25); }
.report-row .t { font: 600 18px/1.3 var(--serif); }
.report-row .small { color: var(--haze); margin-top: 4px; }
.report-row .period { color: var(--dawn); font-size: 13px; margin-bottom: 4px; }

/* ---------- States ---------- */
.state { text-align: center; padding: 70px 10px; color: var(--haze); }
.state .t { font: 600 20px/1.35 var(--serif); color: var(--mist); margin-bottom: 8px; }
.state .btn { max-width: 260px; margin: 18px auto 0; }
.loading { padding: 80px 0; text-align: center; color: var(--faint); }

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(21, 26, 54, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
body.no-tabs #tabbar { display: none; }
#tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--faint); }
#tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
#tabbar a.active { color: var(--mist); }
#tabbar a.active svg { stroke: var(--dawn); }

@media (prefers-reduced-motion: no-preference) {
  .seg button { transition: background-color 0.18s, color 0.18s; }
  .prose.swap { animation: fadein 0.22s ease-out; }
  @keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
}

/* ---------- Mode switch + calendar ---------- */
.mode-switch { margin: 14px 0 18px; }
.cal-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; margin-bottom: 10px; }
.cal-nav { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--dusk); color: var(--mist); font-size: 22px; cursor: pointer; }
.cal-title { justify-self: center; background: none; border: 0; font: 600 20px var(--serif); color: var(--mist); cursor: pointer; padding: 6px 10px; border-radius: 10px; }
.cal-title:not(.static)::after { content: " ▾"; font: 400 13px var(--sans); color: var(--haze); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid.weekdays span { text-align: center; font-size: 12px; color: var(--faint); padding: 4px 0; }
.day {
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; font-size: 15px; color: var(--faint); border: 0; background: none;
}
.day.empty { visibility: hidden; }
.day.has { background: var(--dusk); color: var(--mist); font-weight: 500; cursor: pointer; }
.day.today { box-shadow: inset 0 0 0 1px rgba(235, 231, 246, 0.35); }
.day.lucid { box-shadow: inset 0 0 0 1.5px var(--lucid); }
.day.selected { background: var(--dawn); color: #2a1b10; }
.day .dots { position: absolute; bottom: 6px; left: 0; right: 0; display: flex; justify-content: center; gap: 3px; }
.day .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--dawn); }
.day.lucid .dots i { background: var(--lucid); }
.day.selected .dots i { background: #2a1b10; }
.cal-caption { margin: 18px 0 2px; color: var(--haze); font-size: 14px; display: flex; gap: 10px; align-items: baseline; }
.link { background: none; border: 0; color: var(--dawn); font: inherit; padding: 0; cursor: pointer; }

.year-row { margin-bottom: 18px; }
.year-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.year-label b { font: 600 18px var(--serif); }
.year-label span { font-size: 13px; color: var(--haze); }
.year-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.ym { border: 0; border-radius: 10px; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; color: var(--faint); background: rgba(31, 37, 73, 0.6); }
.ym .mn { font-size: 12px; }
.ym .mc { font: 600 15px var(--serif); min-height: 18px; color: var(--mist); }
.ym.l1 { background: #2b2f55; } .ym.l2 { background: #4a3f5e; } .ym.l3 { background: #8a6a63; } .ym.l4 { background: var(--dawn); }
.ym.l4 .mc, .ym.l4 .mn { color: #2a1b10; }
.ym.l3 .mn, .ym.l2 .mn { color: var(--mist); }

/* ---------- Pre-lucid + clickable tags ---------- */
.stat.prelucid { display: block; }
.stat.prelucid .n { color: #c9b8f2; }
.chip.prelucid-chip { color: #c9b8f2; border-color: rgba(201, 184, 242, 0.35); }
.chip.prelucid-chip[aria-pressed="true"] { background: #c9b8f2; color: var(--night); }
.tag-link { background: none; border: 0; padding: 0; font: inherit; color: var(--haze); cursor: pointer; }
.tag-link::before { content: "#"; opacity: 0.6; }
