/* Тате, разкажи ми… — a book being written.
   Piazzolla sets the book itself (with Bulgarian letterforms, switched on by lang="bg");
   Sofia Sans sets everything that is the tool around it: labels, buttons, counts. */

@font-face {
  font-family: "Piazzolla";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/piazzolla-cyrillic-opsz-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Piazzolla";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/piazzolla-latin-opsz-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Piazzolla";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/piazzolla-cyrillic-opsz-italic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Piazzolla";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/piazzolla-latin-opsz-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Sofia Sans";
  font-style: normal;
  font-weight: 1 1000;
  font-display: swap;
  src: url("fonts/sofia-sans-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Sofia Sans";
  font-style: normal;
  font-weight: 1 1000;
  font-display: swap;
  src: url("fonts/sofia-sans-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- tokens ---------- */

:root {
  --paper: #f4eddf;
  --ink: #2a2019;
  --ink-soft: #55473b;
  --muted: #726251;
  --rule: #d8cbb3;
  --accent: #9c3524; /* madder red: the ribbon and the rubrics */
  --accent-deep: #7c2618;
  --on-accent: #fbf4e6;
  --ok: #4d6a38;
  --grain: url("grain-light.png");

  --serif: "Piazzolla", "Iowan Old Style", Georgia, serif;
  --sans: "Sofia Sans", "Segoe UI", system-ui, sans-serif;
  --gutter: 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1613;
    --ink: #ebe0cd;
    --ink-soft: #cbbda7;
    --muted: #a39480;
    --rule: #3d332a;
    --accent: #e2876b;
    --accent-deep: #c96a4f;
    --on-accent: #1a1613;
    --ok: #a5be8b;
    --grain: url("grain-dark.png");
  }
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper) var(--grain);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
}

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

h1[tabindex="-1"]:focus {
  outline: none;
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

.view {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 var(--gutter) 3.5rem;
}

.page {
  max-width: 38rem;
  margin: 0 auto;
}

.notice {
  max-width: 24rem;
  margin: 0 auto;
  padding: 30vh 0 0;
  text-align: center;
  font-style: italic;
  color: var(--muted);
}
.notice .btn {
  margin-top: 1.5rem;
}

/* ---------- small type: the tool around the book ---------- */

.eyebrow {
  font: 600 0.78rem/1.3 var(--sans);
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--accent);
}

.meta {
  text-wrap: balance;
  font: 500 0.92rem/1.4 var(--sans);
  letter-spacing: 0.02em;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.5rem 1.35rem;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font: 600 0.84rem/1.2 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:hover {
  background: var(--ink);
  color: var(--paper);
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
  color: var(--on-accent);
}
.btn-small {
  min-height: 2.5rem;
  padding: 0.35rem 0.9rem;
  font-size: 0.74rem;
  letter-spacing: 0.1em;
}

.text-link {
  font-style: italic;
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}
.text-link:hover {
  color: var(--accent-deep);
}

/* ---------- cover ---------- */

.cover {
  position: relative;
  display: grid;
  gap: 3rem;
  padding-top: clamp(4.5rem, 13vh, 7.5rem);
}

.ribbon {
  position: absolute;
  top: 0;
  right: 0.75rem;
  width: 1.7rem;
  height: clamp(4.5rem, 13vh, 7.5rem);
  background: linear-gradient(90deg, var(--accent-deep), var(--accent) 30%, var(--accent) 70%, var(--accent-deep));
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 0.8rem), 0 100%);
}

.title {
  margin: 0.9rem 0 1.4rem;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(2.6rem, 13.2vw, 4.75rem);
  font-size: min(15.5cqi, 4.75rem); /* the second line is 6.3em wide with its indent */
  line-height: 0.98;
  letter-spacing: -0.015em;
}
/* Set like the opening of a letter: the salutation, then the line beneath it stepped in. */
.title span {
  display: block;
  white-space: nowrap;
}
.title-b {
  padding-left: 0.75em;
}

.cover-head {
  container-type: inline-size;
}

.lede {
  max-width: 25rem;
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.progress {
  margin: 2rem 0 1.7rem;
  max-width: 25rem;
}
.meter {
  position: relative;
  height: 2px;
  background: var(--rule);
}
.meter i {
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(var(--p, 0));
  transform-origin: left;
}
.progress-line {
  margin-top: 0.7rem;
  font: 500 0.95rem/1.4 var(--sans);
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.read {
  margin-top: 1.4rem;
}

.contents h2 {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.6rem;
}
.contents h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}
.contents ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
.contents a {
  display: grid;
  grid-template-columns: 2.5rem auto minmax(1.25rem, 1fr) auto;
  align-items: baseline;
  column-gap: 0.55rem;
  min-height: 3.1rem;
  padding: 0.65rem 0;
  text-decoration: none;
}
.c-num {
  font-style: italic;
  font-size: 1.05rem;
  color: var(--accent);
}
.c-name {
  font-size: 1.32rem;
  line-height: 1.25;
  transition: color 0.15s ease;
}
.c-lead {
  border-bottom: 1px dotted var(--muted);
  opacity: 0.55;
}
.c-count {
  font: 500 0.86rem/1 var(--sans);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.contents a:hover .c-name {
  color: var(--accent);
}
.is-full .c-count {
  color: var(--accent);
}
/* The ribbon marks the chapter you are in. */
.is-here .c-num {
  position: relative;
}
.is-here .c-num::before {
  content: "";
  position: absolute;
  left: -0.95rem;
  top: 0.2em;
  width: 0.5rem;
  height: 1.05rem;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
}

/* Backup block: only where the diary lives in the browser (the static build). */
.backup {
  max-width: 25rem;
  margin-top: 2.2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
}
.backup-note {
  margin: 0.5rem 0 0.9rem;
  font: 500 0.95rem/1.45 var(--sans);
  color: var(--muted);
}
.backup-note.is-due {
  color: var(--accent);
}
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.3rem;
}
.file-link,
.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: 500 0.92rem/1.4 var(--sans);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  cursor: pointer;
}
.file-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
}
.file-link:hover,
.link-button:hover {
  color: var(--accent);
}
/* The file field itself stays out of sight but in reach of the keyboard. */
.file-link input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip-path: inset(50%);
}
.file-link:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.ios-hint {
  margin-top: 0.9rem;
  font: 500 0.88rem/1.45 var(--sans);
  color: var(--ink-soft);
}
.colophon .link-button {
  font: inherit;
}

.colophon {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem 1.5rem;
  margin-top: 3.5rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font: 500 0.86rem/1.5 var(--sans);
  color: var(--muted);
}
.colophon a {
  color: var(--ink-soft);
  text-underline-offset: 0.2em;
}
.cover .colophon {
  margin-top: 1rem;
}

@media (min-width: 60rem) {
  html {
    font-size: 112.5%;
  }
  :root {
    --gutter: 2.5rem;
  }
  .cover {
    grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
    column-gap: 5.5rem;
    align-items: start;
  }
  .cover-head {
    position: sticky;
    top: 3.5rem;
  }
  .contents {
    padding-top: 0.4rem;
  }
  .cover .colophon {
    grid-column: 1 / -1;
  }
  .ribbon {
    right: 0;
  }
}

/* ---------- inner pages ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.6rem;
  margin-bottom: clamp(2rem, 6vh, 3.75rem);
  border-bottom: 1px solid var(--rule);
  font: 500 0.92rem/1.2 var(--sans);
  letter-spacing: 0.03em;
  color: var(--muted);
}
.back {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.75rem;
  color: var(--ink-soft);
  text-decoration: none;
}
.back::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-left: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: rotate(45deg);
}
.back:hover {
  color: var(--accent);
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 3rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
}
.pager-link {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
  min-height: 2.75rem;
  text-decoration: none;
}
.pager-link.is-next {
  align-items: flex-end;
  text-align: right;
}
.pager-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font: 600 0.78rem/1.3 var(--sans);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.is-prev .pager-label::before,
.is-next .pager-label::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-left: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
}
.is-prev .pager-label::before {
  transform: rotate(45deg);
}
.is-next .pager-label::after {
  transform: rotate(-135deg);
}
.pager-title {
  font-style: italic;
  font-size: 1.1rem;
  line-height: 1.3;
}
.pager-link:hover .pager-label,
.pager-link:hover .pager-title {
  color: var(--accent);
}

/* ---------- chapter ---------- */

.numeral {
  font-style: italic;
  line-height: 1;
  color: var(--accent);
}
.chapter-head .numeral {
  font-size: clamp(3.4rem, 15vw, 5.2rem);
  font-weight: 300;
}
.chapter-head h1 {
  margin: 0.5rem 0 0.6rem;
  font-weight: 500;
  font-size: clamp(2.3rem, 9.5vw, 3.5rem);
  line-height: 1.04;
  letter-spacing: -0.012em;
}

.q-list {
  margin: 2.4rem 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}
.q-list a {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr);
  padding: 1rem 0 1.05rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}
.q-mark {
  width: 0.56rem;
  height: 0.56rem;
  margin-top: 0.62rem;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}
.is-answered .q-mark {
  border-color: var(--accent);
  background: var(--accent);
}
.q-text {
  font-size: 1.18rem;
  line-height: 1.38;
  transition: color 0.15s ease;
}
.q-list a:hover .q-text {
  color: var(--accent);
}
.q-excerpt,
.q-date {
  grid-column: 2;
}
.q-excerpt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-top: 0.35rem;
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
.q-date {
  margin-top: 0.4rem;
  font: 500 0.78rem/1.3 var(--sans);
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* ---------- writing ---------- */

.write .topbar {
  margin-bottom: clamp(1.6rem, 4vh, 3.25rem);
}

.pos {
  white-space: nowrap;
}

.question {
  margin-bottom: 1.9rem;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.8rem, 7vw, 2.75rem);
  line-height: 1.15;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

/* A margin line, as in a notebook; it turns red while you write. */
.sheet-wrap {
  margin-left: calc(var(--gutter) * -0.5);
  padding-left: calc(var(--gutter) * 0.5 - 2px);
  border-left: 2px solid var(--rule);
  transition: border-color 0.2s ease;
}
.sheet-wrap:focus-within {
  border-left-color: var(--accent);
}

.sheet {
  --line: 2.15rem;
  display: block;
  width: 100%;
  min-height: calc(var(--line) * 8);
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px), var(--rule) var(--line));
  color: var(--ink);
  caret-color: var(--accent);
  font: inherit;
  font-size: 1.2rem;
  line-height: var(--line);
  font-optical-sizing: auto;
}
.sheet::placeholder {
  font-style: italic;
  color: var(--muted);
  opacity: 1;
}

.write-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.3rem 1.5rem;
  min-height: 1.4rem;
  margin-top: 0.9rem;
  font: 500 0.86rem/1.4 var(--sans);
  letter-spacing: 0.02em;
  color: var(--muted);
}
.save-state[data-kind="saved"] {
  color: var(--ok);
}
.save-state[data-kind="saved"]::before {
  content: "";
  display: inline-block;
  width: 0.34rem;
  height: 0.62rem;
  margin: 0 0.5rem 0.05rem 0.15rem;
  border-right: 1.5px solid;
  border-bottom: 1.5px solid;
  transform: rotate(40deg);
}
.save-state[data-kind="offline"] {
  color: var(--accent);
}

/* ---------- the book ---------- */

.book-title {
  padding: clamp(0.5rem, 5vh, 3rem) 0 clamp(1rem, 4vh, 2.5rem);
  text-align: center;
}
.book-title .title {
  font-size: clamp(2.6rem, 12.5vw, 4.4rem);
}
.book-title .title-b {
  padding-left: 0;
}
.book-title .lede {
  margin: 0 auto 0.6rem;
}
.book-title .actions {
  justify-content: center;
  margin-top: 2rem;
}

.ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  margin: 1.7rem 0;
  color: var(--accent);
}
/* Drawn with borders, not backgrounds: printers leave backgrounds out by default. */
.ornament::before,
.ornament::after {
  content: "";
  width: 2.6rem;
  border-top: 1px solid currentColor;
}
.ornament i {
  border: 0.21rem solid currentColor;
  transform: rotate(45deg);
}

.book-chapter {
  margin-top: clamp(3rem, 9vh, 5rem);
}
.book-chapter > header {
  margin-bottom: 2.4rem;
  text-align: center;
}
.book-chapter .numeral {
  font-size: 2.5rem;
  font-weight: 300;
}
.book-chapter h2 {
  margin-top: 0.45rem;
  font-weight: 500;
  font-size: clamp(1.9rem, 7.5vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.entry {
  margin-bottom: 2.9rem;
}
.entry h3 {
  margin-bottom: 0.7rem;
  font-style: italic;
  font-weight: 400;
  font-size: 1.28rem;
  line-height: 1.35;
  color: var(--accent);
}
/* Set as in a printed book: paragraphs follow each other, each new one stepped in. */
.answer p {
  text-indent: 1.4em;
  overflow-wrap: break-word;
}
.answer p:first-child {
  text-indent: 0;
}
.book-chapter .entry:first-of-type .answer p:first-child::first-letter {
  float: left;
  padding: 0.07em 0.09em 0 0;
  font-size: 3.55em;
  line-height: 0.8;
  color: var(--accent);
}
.entry-meta {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
  margin-top: 0.8rem;
  font: 500 0.8rem/1.3 var(--sans);
  letter-spacing: 0.05em;
  color: var(--muted);
}
.entry-meta a {
  text-underline-offset: 0.2em;
}
.entry-meta a:hover {
  color: var(--accent);
}

/* ---------- motion: one quiet entrance, on the first paint only ---------- */

@media (prefers-reduced-motion: no-preference) {
  .first-paint .ribbon {
    animation: ribbon 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.15s both;
  }
  .first-paint .cover-head > * {
    animation: rise 0.7s ease both;
  }
  .first-paint .cover-head > :nth-child(2) {
    animation-delay: 0.08s;
  }
  .first-paint .cover-head > :nth-child(3) {
    animation-delay: 0.16s;
  }
  .first-paint .cover-head > :nth-child(n + 4) {
    animation-delay: 0.24s;
  }
  .first-paint .contents li {
    animation: rise 0.6s ease both;
    animation-delay: calc(0.3s + var(--i, 0) * 0.035s);
  }
  @keyframes ribbon {
    from {
      transform: translateY(-100%);
    }
  }
  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(0.6rem);
    }
  }
}

/* ---------- print: the book, on paper ---------- */

@media print {
  @page {
    margin: 24mm 22mm 26mm;
  }
  :root {
    --paper: #fff;
    --ink: #000;
    --ink-soft: #222;
    --muted: #555;
    --rule: #bbb;
    --accent: #7c2618;
    --grain: none;
  }
  body {
    font-size: 11.5pt;
  }
  .no-print {
    display: none !important;
  }
  .view {
    max-width: none;
    padding: 0;
  }
  .page {
    max-width: none;
  }
  .book-title {
    padding-top: 28vh;
    break-after: page;
  }
  .book-chapter {
    margin-top: 0;
    break-before: page;
  }
  .book-chapter:first-of-type {
    break-before: auto;
  }
  .book-chapter > header {
    padding-top: 12vh;
  }
  .entry h3 {
    break-after: avoid;
  }
  .entry-meta {
    break-before: avoid;
  }
}
