/* =========================================================================
   Старообрядческий Певческий Календарь — оформление
   Палитра: пергамент, кремовый, тёмно-коричневый, бордо, золото.
   Дух древнерусской книжности при современном удобстве.
   ========================================================================= */

:root {
  --parch:      #f1e6cb;
  --parch-2:    #e8d9b6;
  --cream:      #fbf5e7;
  --cream-2:    #f6edd8;
  --ink:        #3a2a18;
  --ink-soft:   #61492f;
  --ink-faint:  #8a7250;
  --bordo:      #7a2230;
  --bordo-deep: #5d1822;
  --cinnabar:   #a8322a;
  --gold:       #b08322;
  --gold-soft:  #c8a64e;
  --line:       rgba(122, 34, 48, .22);
  --line-gold:  rgba(176, 131, 34, .45);
  --shadow:     0 6px 22px rgba(58, 30, 12, .14);
  --radius:     14px;

  --serif: "PT Serif", "Palatino Linotype", Palatino, "Book Antiqua",
           Georgia, "Times New Roman", serif;
}

/* Масштаб шрифта (адаптация для пожилых) */
html { font-size: 17.5px; -webkit-text-size-adjust: 100%; }
html[data-fontscale="large"]  { font-size: 20.5px; }
html[data-fontscale="xlarge"] { font-size: 23.5px; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background-color: var(--parch);
  background-image:
    radial-gradient(120% 90% at 15% 0%, rgba(255, 250, 235, .55), transparent 55%),
    radial-gradient(120% 90% at 85% 100%, rgba(176, 131, 34, .07), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ——— Каркас ——— */
.app-shell {
  display: flex; flex-direction: column;
  height: 100dvh; max-width: 720px; margin: 0 auto;
  position: relative;
}

.app-header {
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  border-bottom: 2px solid var(--gold);
  box-shadow: 0 2px 0 rgba(176,131,34,.25), 0 4px 14px rgba(58,30,12,.08);
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem 1rem .6rem;
}
.app-title { display: flex; flex-direction: column; line-height: 1.05; }
.app-title-main {
  font-size: 1.18rem; font-weight: 700; color: var(--bordo);
  letter-spacing: .04em;
}
.app-title-sub {
  font-size: .78rem; color: var(--gold); letter-spacing: .22em;
  text-transform: uppercase; margin-top: .15rem;
}
.gear-btn {
  flex: 0 0 auto; width: 44px; height: 44px; border: none;
  background: transparent; color: var(--bordo); cursor: pointer;
  border-radius: 50%; display: grid; place-items: center;
}
.gear-btn svg { width: 26px; height: 26px; }
.gear-btn:active { background: rgba(122,34,48,.08); }

.app-main {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 1rem 1rem 1.4rem;
}

/* ——— Нижняя навигация ——— */
.app-nav {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: linear-gradient(0deg, var(--cream) 0%, var(--cream-2) 100%);
  border-top: 2px solid var(--gold);
  padding-bottom: env(safe-area-inset-bottom);
}
.navbtn {
  border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .5rem 0 .55rem; color: var(--ink-soft);
  font-family: var(--serif); font-size: .74rem; min-height: 56px;
  transition: color .15s;
}
.navbtn svg { width: 25px; height: 25px; }
.navbtn.active { color: var(--bordo); }
.navbtn.active svg { color: var(--bordo); }
.navbtn:active { background: rgba(122,34,48,.06); }

/* ——— Вязь / заголовки ——— */
.vyaz {
  font-family: var(--serif); color: var(--bordo);
  letter-spacing: .045em; font-weight: 700;
}
.section-head { text-align: center; margin: .2rem 0 1.1rem; }
.section-head h2 { font-size: 1.5rem; margin: .1rem 0 .15rem; }
.section-sub { color: var(--ink-faint); font-size: .9rem; margin: 0 0 .4rem; font-style: italic; }

/* Орнаменты */
.ornament-band { display: block; width: 190px; max-width: 70%; height: 16px; margin: .5rem auto; color: var(--gold); }
.cross8 { color: var(--bordo); }
.ornament-corner { position: absolute; width: 24px; height: 24px; color: var(--gold-soft); pointer-events: none; }

/* ——— Карточки ——— */
.card {
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
}
.framed {
  position: relative;
  border: 1.5px solid var(--line-gold);
  outline: 1px solid var(--line-gold);
  outline-offset: 4px;
}
.framed > .ornament-corner:nth-of-type(1) { top: 5px; left: 5px; }
.framed > .ornament-corner:nth-of-type(2) { top: 5px; right: 5px; transform: rotate(90deg); }
.framed > .ornament-corner:nth-of-type(3) { bottom: 5px; right: 5px; transform: rotate(180deg); }
.framed > .ornament-corner:nth-of-type(4) { bottom: 5px; left: 5px; transform: rotate(270deg); }
.card-inner { padding: 1.15rem 1.15rem 1.25rem; }

/* ——— Карточка дня ——— */
.date-line { text-align: center; }
.date-big { font-size: 1.5rem; font-weight: 700; color: var(--ink); letter-spacing: .01em; }
.date-meta { color: var(--ink-soft); font-size: .92rem; margin-top: .15rem; }
.date-meta .dow { color: var(--bordo); }
.date-meta .oldstyle { font-style: italic; }
.date-meta .sep { margin: 0 .4rem; color: var(--gold); }

.pills { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; margin: .2rem 0 .8rem; }
.pill {
  display: inline-block; font-size: .8rem; padding: .22rem .6rem;
  border-radius: 999px; border: 1px solid var(--line-gold);
  background: rgba(255,252,244,.7); color: var(--ink-soft); white-space: nowrap;
}
.pill-glas    { background: rgba(176,131,34,.14); border-color: var(--gold); color: var(--bordo-deep); font-weight: 700; }
.pill-fast    { background: rgba(122,34,48,.1); border-color: var(--bordo); color: var(--bordo); }
.pill-free    { background: rgba(96,140,96,.12); border-color: #6b8b6b; color: #3f6b3f; }
.pill-feast12 { background: rgba(122,34,48,.14); border-color: var(--bordo); color: var(--bordo-deep); font-weight: 700; }
.pill-feast   { background: rgba(176,131,34,.16); border-color: var(--gold); color: var(--bordo); }
.pill-sunday  { background: rgba(122,34,48,.08); border-color: var(--line); color: var(--bordo); }

.church-day {
  font-size: 1.32rem; line-height: 1.32; color: var(--bordo-deep);
  text-align: center; margin: .3rem 0 .55rem; font-weight: 700; letter-spacing: .01em;
}
.bukva {
  color: var(--cinnabar); font-weight: 700; font-size: 1.35em; line-height: 1;
}
.day-desc { color: var(--ink); margin: 0 0 .2rem; text-align: center; font-size: 1.02rem; }

/* Песнопения праздника */
.chants {
  margin-top: 1rem; padding: .85rem 1rem;
  background: rgba(176,131,34,.06);
  border: 1px solid var(--line-gold); border-radius: 10px;
}
.chants .mini-head:first-child { margin-top: 0; }
.chant { margin-bottom: .75rem; }
.chant:last-child { margin-bottom: 0; }
.chant-label { color: var(--gold); font-weight: 700; font-size: .82rem; letter-spacing: .06em; text-transform: uppercase; margin-bottom: .15rem; }
.chant-text { margin: 0; color: var(--ink); font-size: 1.02rem; line-height: 1.55; }
.chant-pending { margin: 0; color: var(--ink-faint); font-style: italic; font-size: .92rem; }
.chants.is-draft { border-style: dashed; }
.chant-draft {
  display: inline-block; vertical-align: middle; margin-left: .4rem;
  font-size: .64rem; letter-spacing: .05em; text-transform: uppercase;
  color: var(--bordo); background: rgba(122,34,48,.1);
  border: 1px solid var(--bordo); border-radius: 999px; padding: .1rem .45rem;
}

/* Память дня (месяцеслов) */
.memory {
  margin-top: 1rem; padding: .85rem 1rem;
  background: rgba(122,34,48,.05);
  border: 1px solid var(--line); border-radius: 10px;
}
.memory .mini-head:first-child { margin-top: 0; }
.mem-list { margin: 0; padding-left: 1.1rem; list-style: none; }
.mem-list li { position: relative; margin-bottom: .35rem; color: var(--ink); }
.mem-list li:last-child { margin-bottom: 0; }
.mem-list li::before {
  content: "·"; position: absolute; left: -.85rem; top: -.1em;
  color: var(--bordo); font-weight: 700;
}
.mem-sign {
  font-size: .72rem; color: var(--gold); letter-spacing: .04em;
  text-transform: uppercase; margin-left: .35rem; white-space: nowrap;
}

/* Блок «На клиросе» */
.kliros {
  margin-top: 1.1rem; padding-top: 1rem;
  border-top: 1px dashed var(--line-gold);
}
.kliros-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .7rem; }
.kliros-head .cross8 { width: 30px; height: 48px; flex: 0 0 auto; }
.kliros-title { font-size: 1.2rem; line-height: 1.1; }
.kliros-glas { color: var(--gold); font-size: .92rem; letter-spacing: .14em; text-transform: uppercase; }
.mini-head {
  font-size: .82rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--gold); margin: .9rem 0 .35rem; font-weight: 700;
}
.bullets { margin: .2rem 0 .3rem; padding-left: 1.1rem; list-style: none; }
.bullets li { position: relative; margin-bottom: .42rem; padding-left: .3rem; }
.bullets li::before {
  content: "✛"; position: absolute; left: -1.05rem; top: 0;
  color: var(--gold); font-size: .85em;
}
.fast-note {
  margin: .7rem 0 0; padding: .55rem .7rem; font-style: italic;
  background: rgba(122,34,48,.06); border-left: 3px solid var(--bordo);
  border-radius: 0 8px 8px 0; color: var(--ink-soft); font-size: .95rem;
}

.back-btn, .today-btn {
  border: 1px solid var(--line-gold); background: var(--cream);
  color: var(--bordo); font-family: var(--serif); font-size: .95rem;
  padding: .55rem 1rem; border-radius: 10px; cursor: pointer; margin-bottom: .9rem;
}
.today-btn { display: block; width: 100%; margin: .4rem 0 .2rem; min-height: 48px; }
.back-btn:active, .today-btn:active { background: var(--cream-2); }

/* ——— Календарь ——— */
.cal-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .7rem;
}
.cal-month { font-size: 1.3rem; }
.nav-arrow {
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid var(--line-gold); background: var(--cream);
  color: var(--bordo); font-size: 1.5rem; cursor: pointer; line-height: 1;
}
.nav-arrow:active { background: var(--cream-2); }

.cal-grid-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; color: var(--ink-faint); font-size: .8rem; padding: .3rem 0; }
.cal-dow.sun { color: var(--bordo); }
.cal-grid { margin-top: 2px; }
.cal-cell {
  position: relative; aspect-ratio: 1 / 1; min-height: 40px;
  border: 1px solid transparent; border-radius: 10px;
  background: rgba(255,252,244,.55); color: var(--ink);
  font-family: var(--serif); font-size: 1.02rem; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.cal-cell.empty { background: transparent; border: none; cursor: default; }
.cal-cell .cal-num { line-height: 1; }
.cal-cell.sunday { color: var(--bordo); font-weight: 700; }
.cal-cell.fasting { background: rgba(122,34,48,.07); }
.cal-cell.feast12 { background: rgba(122,34,48,.14); border-color: var(--bordo); font-weight: 700; }
.cal-cell.feast   { border-color: var(--gold); }
.cal-cell.today {
  outline: 2px solid var(--gold); outline-offset: -2px;
  box-shadow: 0 0 0 2px rgba(176,131,34,.25);
}
.cal-cell:active { background: var(--cream-2); }
.cal-dot { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); width: 5px; height: 5px; border-radius: 50%; }
.cal-dot.dot12 { background: var(--bordo); }
.cal-dot.dotg  { background: var(--gold); }

.cal-legend {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: center;
  margin: 1rem 0 .3rem; font-size: .82rem; color: var(--ink-soft);
}
.cal-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.lg { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.lg.dot12 { background: var(--bordo); border-radius: 50%; width: 9px; height: 9px; }
.lg.dotg  { background: var(--gold); border-radius: 50%; width: 9px; height: 9px; }
.lg-fast  { background: rgba(122,34,48,.18); border: 1px solid var(--bordo); }
.lg-today { background: transparent; border: 2px solid var(--gold); }

/* ——— Гласы ——— */
.tones-grid { display: flex; flex-direction: column; gap: 1rem; }
.tone-card {
  display: flex; gap: 1rem; align-items: flex-start;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.tone-num {
  flex: 0 0 auto; width: 64px; text-align: center;
  display: flex; flex-direction: column; align-items: center;
  border-right: 1px solid var(--line-gold); padding-right: .8rem;
}
.tone-ch { font-size: 2.4rem; color: var(--cinnabar); font-weight: 700; line-height: 1; }
.tone-lat { font-size: .76rem; color: var(--gold); letter-spacing: .08em; margin-top: .25rem; text-transform: uppercase; }
.tone-body { flex: 1 1 auto; }
.tone-epithet { color: var(--bordo); font-weight: 700; font-size: 1.05rem; margin-bottom: .3rem; }
.tone-char { margin: 0 0 .5rem; color: var(--ink); }
.tone-kliros { font-size: .95rem; color: var(--ink-soft); }
.tone-kliros .mini-head { display: inline; margin: 0; }

/* ——— Праздники ——— */
.search-wrap { margin-bottom: 1.1rem; }
.search-input {
  width: 100%; font-family: var(--serif); font-size: 1.05rem;
  padding: .7rem .9rem; border: 1.5px solid var(--line-gold); border-radius: 12px;
  background: var(--cream); color: var(--ink); min-height: 48px;
}
.search-input::placeholder { color: var(--ink-faint); font-style: italic; }
.search-input:focus { outline: 2px solid var(--gold); border-color: var(--gold); }

.pascha-banner {
  display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem;
  background: linear-gradient(180deg, #fff8ec 0%, #f6e9cc 100%);
  border: 1.5px solid var(--bordo); border-radius: var(--radius);
  padding: .6rem .8rem; box-shadow: var(--shadow);
}
.pascha-banner .cross8 { width: 30px; height: 48px; flex: 0 0 auto; }
.pascha-item { border: none !important; background: transparent !important; box-shadow: none !important; padding: .3rem 0 !important; }

.feast-section { margin-bottom: 1.4rem; }
.feast-sec-head { font-size: 1.25rem; margin: .2rem 0 .15rem; }
.feast-sec-note { color: var(--ink-faint); font-size: .88rem; font-style: italic; margin: 0 0 .7rem; }
.feast-list { display: flex; flex-direction: column; gap: .55rem; }
.feast-item {
  width: 100%; text-align: left; cursor: pointer;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  border: 1px solid var(--line-gold); border-radius: 12px;
  padding: .75rem .9rem; font-family: var(--serif); color: var(--ink);
}
.feast-item:active { background: var(--cream-2); }
.feast-title { font-weight: 700; color: var(--bordo-deep); font-size: 1.04rem; line-height: 1.25; }
.feast-date { color: var(--gold); font-size: .86rem; margin-top: .25rem; letter-spacing: .02em; }
.feast-desc { margin: .4rem 0 0; color: var(--ink-soft); font-size: .94rem; }
.empty-hint { color: var(--ink-faint); font-style: italic; }

/* ——— Настройки ——— */
.settings-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(40, 22, 10, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.settings-panel {
  width: 100%; max-width: 720px;
  background: linear-gradient(180deg, var(--cream) 0%, var(--parch-2) 100%);
  border-top: 3px solid var(--gold); border-radius: 18px 18px 0 0;
  padding: 1.3rem 1.2rem calc(1.4rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(40,22,10,.3);
}
.settings-panel h2 { text-align: center; font-size: 1.4rem; margin: 0 0 1rem; }
.setting-row { margin-bottom: 1rem; }
.setting-label { color: var(--ink-soft); margin-bottom: .5rem; font-size: .95rem; }
.fs-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.fs-opt {
  border: 1.5px solid var(--line-gold); background: var(--cream);
  color: var(--ink); border-radius: 10px; padding: .7rem .3rem; cursor: pointer;
  font-family: var(--serif); font-size: .92rem; min-height: 52px;
}
.fs-opt.active { background: var(--bordo); color: #fbf2dd; border-color: var(--bordo); }
.settings-hint { color: var(--ink-faint); font-size: .85rem; font-style: italic; text-align: center; margin: .8rem 0 1.1rem; }
.settings-close {
  width: 100%; min-height: 52px; border: none; border-radius: 12px;
  background: var(--gold); color: #fff8e8; font-family: var(--serif);
  font-size: 1.05rem; cursor: pointer; letter-spacing: .03em;
}
.settings-close:active { background: var(--gold-soft); }

/* Прокрутка */
.app-main::-webkit-scrollbar { width: 8px; }
.app-main::-webkit-scrollbar-thumb { background: var(--line-gold); border-radius: 8px; }

@media (min-width: 560px) {
  .tones-grid { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .screen { animation: fade .25s ease; }
  @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
