/* ── Reset & tokens ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gold:         #b8860b;
  --gold-lt:      #d4a520;
  --gold-dim:     #8a6408;
  --bg:           #fdf8f0;
  --bg-card:      #ffffff;
  --bg-strip:     #f5ecd8;
  --text:         #1a1208;
  --text-dim:     #6b5a3e;
  --border:       #ddd0b0;
  --red:          #8b1a1a;
  --hdr-bg:       #1a0a00;
  --hdr-text:     #d4a520;
  --radius:       8px;
  --radius-sm:    4px;
  --shadow:       0 1px 4px rgba(0,0,0,.1);
  --shadow-md:    0 2px 8px rgba(0,0,0,.15);
  --touch-min:    44px;
  --service-font: 1rem;
}

html { font-size: 16px; }

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

/* ── App header ──────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--hdr-bg);
  color: var(--hdr-text);
  padding: .75rem 1rem;
  padding-top: max(.75rem, env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-logo {
  font-size: 1.25rem;
  font-weight: bold;
  letter-spacing: .05em;
}
.app-logo-by {
  font-size: .8rem;
  font-weight: normal;
  letter-spacing: 0;
  opacity: .55;
  vertical-align: baseline;
}

.settings-toggle {
  background: none;
  border: none;
  color: var(--hdr-text);
  font-size: 1.25rem;
  cursor: pointer;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.settings-toggle:hover { background: rgba(255,255,255,.1); }
.settings-toggle[aria-expanded="true"] { color: var(--gold-lt); }

/* ── Settings panel ──────────────────────────────────────────────────────────── */
.settings-panel {
  background: #2a1000;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: .6rem 1rem;
  flex-wrap: wrap;
}

.setting {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: #c8a87a;
  font-size: .85rem;
  cursor: pointer;
}

.setting-label { white-space: nowrap; }
.setting-val { min-width: 3rem; }

input[type="range"] {
  width: 80px;
  accent-color: var(--gold);
  cursor: pointer;
}

.toggle-setting input[type="checkbox"] {
  accent-color: var(--gold);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.btn-icon {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: #c8a87a;
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  min-height: var(--touch-min);
}
.btn-icon:hover { background: rgba(255,255,255,.15); }

/* ── Day navigation ──────────────────────────────────────────────────────────── */
.day-nav {
  display: flex;
  align-items: center;
  background: var(--hdr-bg);
  border-top: 1px solid rgba(255,255,255,.08);
  padding: .35rem .5rem;
  gap: .25rem;
}

.nav-arrow {
  background: none;
  border: none;
  color: var(--gold-lt);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background .15s;
  flex-shrink: 0;
}
.nav-arrow:hover { background: rgba(255,255,255,.1); }
.nav-arrow:active { background: rgba(255,255,255,.2); }

.day-nav-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-width: 0;
}

.today-btn {
  background: var(--gold);
  border: none;
  color: #fff;
  font-size: .72rem;
  font-family: inherit;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .2rem .7rem;
  border-radius: 20px;
  cursor: pointer;
  min-height: 28px;
  margin-bottom: .1rem;
  transition: background .15s;
}
.today-btn:hover { background: var(--gold-lt); }

/* The native date input is hidden; the styled button triggers it */
.date-hidden-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 1px; height: 1px;
}

.date-display-btn {
  background: none;
  border: none;
  color: var(--hdr-text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .1rem .5rem;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.date-display-btn:hover { background: rgba(255,255,255,.08); }

.date-weekday {
  font-size: .72rem;
  color: #c8a87a;
  text-transform: uppercase;
  letter-spacing: .1em;
}
.date-greg {
  font-size: 1rem;
  font-weight: bold;
  line-height: 1.2;
}
.date-julian {
  font-size: .72rem;
  color: #c8a87a;
}

/* ── Day info strip ──────────────────────────────────────────────────────────── */
.day-strip {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  background: var(--bg-strip);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.day-strip::-webkit-scrollbar { display: none; }

.strip-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .4rem .9rem;
  white-space: nowrap;
  flex: 1;
}
.strip-sep {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
  margin: .3rem 0;
}

.strip-label {
  font-size: .68rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-dim);
}
.strip-val {
  font-size: .88rem;
  color: var(--text);
  font-weight: 500;
}

.strip-fasting .strip-val { color: var(--gold-dim); }
.strip-fasting.fasting-strict .strip-val { color: var(--red); }
.strip-fasting.fasting-suspended .strip-val { color: #2e7d32; font-style: italic; }

#strip-vestment { display: flex; align-items: center; gap: .35rem; }
.vestment-swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid transparent;
  flex-shrink: 0;
  vertical-align: middle;
}

.strip-flags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .25rem .8rem;
  border-top: 1px solid var(--border);
  width: 100%;
}

.special-flag-chip {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: #1a5c2a;
  background: #e8f5e9;
  border: 1px solid #66bb6a;
  border-radius: 12px;
  padding: 2px 8px;
  cursor: help;
  white-space: nowrap;
}

/* ── Period color coding (G6) ────────────────────────────────────────────── */
.day-strip[data-period="BRIGHT_WEEK"]    { border-bottom: 3px solid #b89a00; background: #fffde8; }
.day-strip[data-period="PENTECOSTARION"] { border-bottom: 3px solid #2e7d32; background: #f1f8f1; }
.day-strip[data-period="TRIODION_LENTEN"]{ border-bottom: 3px solid #6a1b9a; background: #f3eef7; }
.day-strip[data-period="TRIODION_PRE"]   { border-bottom: 3px solid #8c5a9e; background: #f8f2fb; }
.day-strip[data-period="HOLY_WEEK"]      { border-bottom: 3px solid #8b1a1a; background: #fdf0f0; }

.day-strip[data-period="BRIGHT_WEEK"]     .strip-val { color: #7a6000; }
.day-strip[data-period="PENTECOSTARION"]  .strip-val { color: #1b5e20; }
.day-strip[data-period="TRIODION_LENTEN"] .strip-val { color: #4a148c; }
.day-strip[data-period="TRIODION_PRE"]    .strip-val { color: #6a1b9a; }
.day-strip[data-period="HOLY_WEEK"]       .strip-val { color: #8b1a1a; }

/* ── Main content area ───────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  padding: .75rem .75rem 2rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ── Language chips + load button ───────────────────────────────────────────── */
.lang-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}

.lang-chips {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  flex: 1;
}

.lang-chip {
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: .3rem .6rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: .88rem;
  background: var(--bg-card);
  transition: background .15s, border-color .15s;
  min-height: var(--touch-min);
  user-select: none;
}
.lang-chip:hover { background: #f0e8d4; border-color: var(--gold); }
.lang-chip input { display: none; }
.lang-chip:has(input:checked) {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
  font-weight: bold;
}

.lang-chip-new { position: relative; }
.lang-new-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #c0392b;
  color: #fff;
  font-size: .55rem;
  font-weight: bold;
  line-height: 1;
  padding: 1px 3px;
  border-radius: 3px;
  letter-spacing: .02em;
  pointer-events: none;
}

.btn-primary {
  background: var(--gold);
  color: #fff;
  border: none;
  padding: .5rem 1.25rem;
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  min-height: var(--touch-min);
  transition: background .15s;
}
.btn-primary:hover { background: var(--gold-lt); }
.btn-primary:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* ── Loading / error ─────────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
  font-style: italic;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.4} 50%{opacity:1} }

.error-box {
  background: #fff0f0;
  border: 1px solid #ffb3b3;
  border-radius: var(--radius);
  padding: .9rem 1rem;
  color: #8b0000;
  margin-bottom: .75rem;
}

/* ── Feast banner ────────────────────────────────────────────────────────────── */
.feast-banner {
  background: linear-gradient(135deg, #3d1a00, #6b3300);
  color: var(--gold-lt);
  text-align: center;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: bold;
  margin-bottom: .75rem;
}

/* ── Audit / fallback diagnostic banner ──────────────────────────────────────── */
.audit-banner {
  background: #2d0000;
  border: 1.5px solid #c00;
  color: #ff6b6b;
  border-radius: var(--radius);
  padding: .6rem 1rem;
  margin-bottom: .75rem;
  font-size: .82rem;
  line-height: 1.55;
}
.audit-banner summary {
  cursor: pointer;
  font-weight: bold;
  color: #ff4444;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.audit-banner summary::-webkit-details-marker { display: none; }
.audit-banner ul {
  margin: .4rem 0 0 1rem;
  padding: 0;
}
.audit-banner li { margin: .15rem 0; }
.audit-banner .ab-warn { color: #ff6b6b; }
.audit-banner .ab-ok   { color: #6bff8a; }

/* ── Service tabs ────────────────────────────────────────────────────────────── */
.service-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gold);
  margin-bottom: .9rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.service-tabs::-webkit-scrollbar { display: none; }

.tab {
  background: transparent;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: .55rem 1rem;
  font-family: inherit;
  font-size: .9rem;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text-dim);
  white-space: nowrap;
  transition: background .15s, color .15s;
  min-height: var(--touch-min);
  flex-shrink: 0;
}
.tab:hover { background: #f5ecd6; color: var(--text); }
.tab.active {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
  font-weight: bold;
}

/* ── Panels ──────────────────────────────────────────────────────────────────── */
.panel { display: none; }
.panel-active { display: block; }

/* ── Lang columns (service text) ─────────────────────────────────────────────── */
.lang-columns {
  display: grid;
  gap: .9rem;
  grid-template-columns: 1fr;
}

.lang-column {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.lang-column.lang-missing {
  opacity: .5;
  border-style: dashed;
}

.lang-column-header {
  font-size: .72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--gold);
  border-bottom: 1px solid var(--border);
  padding-bottom: .4rem;
  margin-bottom: .75rem;
}

/* ── Service texts ───────────────────────────────────────────────────────────── */
.rubric {
  color: var(--red);
  font-style: italic;
  font-size: .85rem;
  margin: .5rem 0 .15rem;
}
.rubric.hidden-rubric { display: none; }

.troparion-text,
.kontakion-text {
  font-size: var(--service-font);
  margin: .25rem 0 .9rem;
}

.tone-label {
  display: inline-block;
  background: var(--bg-strip);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 .35rem;
  font-size: .75rem;
  color: var(--text-dim);
  margin-left: .4rem;
  vertical-align: middle;
}

/* ── Stichera ─────────────────────────────────────────────────────────────── */
.sticheron {
  margin: .3rem 0 .9rem;
}

.sticheron-label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: .2rem;
}

.sticheron-text {
  font-size: var(--service-font);
  margin: 0;
}

.sticheron-text.theotokion {
  font-style: italic;
}

/* ── Canon ────────────────────────────────────────────────────────────────── */
.canon-ode-header {
  font-size: .82rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 1rem 0 .3rem;
}

.canon-irmos {
  font-size: var(--service-font);
  font-style: italic;
  color: var(--text-dim);
  margin: 0 0 .4rem;
}

.canon-troparion {
  font-size: var(--service-font);
  margin: .2rem 0 .4rem;
}

.canon-troparion.theotokion {
  font-style: italic;
}

.no-text {
  color: var(--text-dim);
  font-style: italic;
  font-size: .9rem;
}

/* ── Saints panel ────────────────────────────────────────────────────────────── */
#saints-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.saint-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.saint-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: .85rem 1rem .7rem;
  cursor: pointer;
  gap: .5rem;
  user-select: none;
}
.saint-card-header:hover { background: #fdf3e2; }

.saint-name {
  font-weight: bold;
  font-size: 1rem;
  color: var(--text);
  flex: 1;
}
.saint-rank-badge {
  font-size: .72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--gold-dim);
  white-space: nowrap;
}
.saint-expand-icon {
  font-size: .8rem;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: transform .2s;
}
.saint-card.expanded .saint-expand-icon {
  transform: rotate(180deg);
}

.saint-card-body {
  display: none;
  padding: 0 1rem .9rem;
  border-top: 1px solid var(--border);
}
.saint-card.expanded .saint-card-body { display: block; }

.saint-lang-names {
  font-size: .82rem;
  color: var(--text-dim);
  margin: .5rem 0 .2rem;
}

.saint-life {
  font-size: .88rem;
  color: var(--text-dim);
  margin-top: .4rem;
  max-height: 160px;
  overflow: hidden;
  position: relative;
}
.saint-life::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--bg-card));
  pointer-events: none;
}

.missing-text-note {
  font-size: .85rem;
  color: var(--text-dim);
  font-style: italic;
  margin: .4rem 0;
}
.missing-text-note a {
  color: var(--accent);
  text-decoration: underline;
}

.prokeimenon-text {
  font-style: italic;
  font-size: var(--service-font);
  margin: .2rem 0 .6rem;
  padding-left: .5rem;
  border-left: 2px solid var(--gold-dim);
}

.stichera-lang-note {
  font-size: .75rem;
  color: var(--text-dim);
  font-style: italic;
  margin: 0 0 .3rem;
}

.rubric-row {
  display: flex;
  align-items: baseline;
  gap: .4rem;
}

.fallback-lang-badge {
  font-size: .68rem;
  font-weight: bold;
  letter-spacing: .05em;
  color: var(--gold-dim);
  background: #fdf3e2;
  border: 1px solid #d4a843;
  border-radius: 3px;
  padding: 1px 4px;
  white-space: nowrap;
  cursor: help;
}

/* ── E6: Missing text filter toolbar ────────────────────────────────────────── */
.svc-text-toolbar {
  padding: .35rem .8rem .25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.svc-filter-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.svc-filter-label input[type="checkbox"] { accent-color: var(--gold); }

#panel-service-text.filter-missing .lang-column > * { display: none !important; }

#panel-service-text.filter-missing .lang-column > .lang-column-header,
#panel-service-text.filter-missing .lang-column > .vespers-type-header,
#panel-service-text.filter-missing .lang-column > .service-text-placeholder,
#panel-service-text.filter-missing .lang-column > .missing { display: block !important; }

#panel-service-text.filter-missing .lang-column > .rubric:has(+ .service-text-placeholder),
#panel-service-text.filter-missing .lang-column > .rubric:has(+ .missing) { display: block !important; }

.vespers-type-header {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .2rem .6rem;
  margin: .3rem 0 .9rem;
}

.lang-col-fallback-badge {
  display: inline-block;
  margin-left: .45rem;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: #7a5500;
  background: #fff4cc;
  border: 1px solid #c8960a;
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
  cursor: help;
  vertical-align: middle;
}

/* ── E3: Semantic status classes for service text elements ───────────────────── */
/* .ok     — text present from corpus or fixed repertoire  */
/* .missing — text absent from corpus (placeholder shown)  */
/* .blocked — element suppressed by rubrics                */
/* .combined — text assembled from multiple sources        */
/* .transferred — text taken from a different language/day */

.ok { /* no special decoration — normal reading state */ }

.missing {
  font-style: italic;
  opacity: .65;
}

.blocked {
  text-decoration: line-through;
  opacity: .4;
  font-style: italic;
}

.transferred {
  border-left: 2px solid #b8860b;
  padding-left: .4rem;
  opacity: .85;
}

.combined {
  border-left: 2px solid var(--gold);
  padding-left: .4rem;
}

.stichera-lang-note.transferred {
  font-size: .72rem;
  color: #c44;
  margin-bottom: .15rem;
  border: 1px solid #6b1a1a;
  border-radius: 3px;
  padding: .15rem .4rem;
  background: #200;
  opacity: 1;
}

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 1rem;
  font-size: .78rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.app-footer a { color: var(--gold); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }
.footer-links { margin-top: .2rem; }

/* ── Desktop enhancements ────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .app-logo { font-size: 1.4rem; }
  .date-greg { font-size: 1.1rem; }

  .lang-columns {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

@media (min-width: 768px) {
  .app-main { padding: 1rem 1.5rem 3rem; }
  .app-header { padding: .9rem 1.5rem; }
  .day-nav { padding: .5rem 1rem; }
  .day-strip .strip-item { padding: .5rem 1.25rem; }
}

/* ── Readings panel ──────────────────────────────────────────────────────────── */
.reading-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .85rem 1rem;
  margin-bottom: .75rem;
}

.reading-row {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.reading-row:last-child { border-bottom: none; }

.reading-type {
  font-size: .72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--red);
  flex-shrink: 0;
  min-width: 80px;
}

.reading-ref {
  font-size: 1rem;
  font-weight: bold;
  color: var(--text);
}

.reading-pericope {
  font-size: .75rem;
  color: var(--gold-dim);
  background: var(--bg-strip);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 .35rem;
  white-space: nowrap;
}

.reading-ref-en {
  font-size: .78rem;
  color: var(--text-dim);
  font-style: italic;
  margin-left: auto;
}

/* ── External links ───────────────────────────────────────────────────────────── */
.ext-links {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-top: .75rem;
}

.ext-links-hdr {
  font-size: .72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-dim);
  margin-bottom: .5rem;
}

.ext-link {
  display: flex;
  align-items: center;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--gold);
  text-decoration: none;
  font-size: .9rem;
  transition: color .15s;
}
.ext-link:last-child { border-bottom: none; }
.ext-link:hover { color: var(--gold-lt); text-decoration: underline; }
.ext-link::after {
  content: ' ↗';
  font-size: .75rem;
  color: var(--text-dim);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Calendar button ─────────────────────────────────────────────────────────── */
.day-nav-top-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .1rem;
}

.calendar-btn {
  background: none;
  border: none;
  color: var(--gold-lt);
  font-size: 1.1rem;
  cursor: pointer;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  padding: 0 .2rem;
  transition: background .15s;
  line-height: 1;
}
.calendar-btn:hover { background: rgba(255,255,255,.1); }

/* ── Calendar modal overlay ──────────────────────────────────────────────────── */
.cal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.cal-modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

.cal-header {
  display: flex;
  align-items: center;
  background: var(--hdr-bg);
  padding: .6rem .75rem;
  gap: .4rem;
}

.cal-nav-btn {
  background: none;
  border: none;
  color: var(--gold-lt);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background .15s;
  flex-shrink: 0;
}
.cal-nav-btn:hover { background: rgba(255,255,255,.1); }

.cal-month-label {
  flex: 1;
  text-align: center;
  color: var(--hdr-text);
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: .05em;
}

.cal-close-btn {
  background: none;
  border: none;
  color: #c8a87a;
  font-size: .95rem;
  cursor: pointer;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background .15s;
  flex-shrink: 0;
}
.cal-close-btn:hover { background: rgba(255,255,255,.1); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f5ecd8;
  border-bottom: 1px solid var(--border);
}
.cal-weekdays span {
  text-align: center;
  padding: .3rem 0;
  font-size: .7rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}
.cal-weekdays span:first-child { color: #8b1a1a; }
.cal-weekdays span:last-child  { color: var(--gold-dim); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}

/* Day cell */
.cal-day {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: .25rem .3rem;
  min-height: 60px;
  cursor: pointer;
  background: var(--bg-card);
  transition: background .1s;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  overflow: hidden;
}
.cal-day:hover { background: #fdf3e2; }
.cal-day.cal-day-empty {
  background: #f9f5ee;
  cursor: default;
  pointer-events: none;
}
.cal-day.cal-day-today {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}
.cal-day.cal-day-selected {
  background: #fff8e8;
}

/* Day number */
.cal-day-num {
  font-size: .85rem;
  font-weight: bold;
  line-height: 1;
  color: var(--text);
}
.cal-day.cal-sunday .cal-day-num { color: #8b1a1a; }
.cal-day.cal-saturday .cal-day-num { color: var(--gold-dim); }

/* Julian sub-label */
.cal-day-julian {
  font-size: .6rem;
  color: var(--text-dim);
  line-height: 1;
}

/* Feast name */
.cal-day-feast {
  font-size: .6rem;
  line-height: 1.2;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

/* Rank color bar at top of cell */
.cal-day::before {
  content: '';
  display: block;
  height: 3px;
  position: absolute;
  top: 0; left: 0; right: 0;
}
.cal-day.rank-great::before  { background: #b8860b; }
.cal-day.rank-vigil::before  { background: #e0952a; }
.cal-day.rank-poly::before   { background: #8b1a1a; }
.cal-day.rank-doxo::before   { background: #2d7a2d; }
.cal-day.rank-lent::before   { background: #6b3580; }

/* Text colors matching rank */
.cal-day.rank-great  .cal-day-feast { color: #7a5500; font-weight: bold; }
.cal-day.rank-vigil  .cal-day-feast { color: #8b4500; }
.cal-day.rank-poly   .cal-day-feast { color: #8b1a1a; }
.cal-day.rank-doxo   .cal-day-feast { color: #1a5c1a; }
.cal-day.rank-lent   .cal-day-feast { color: #6b3580; }

/* Fasting dot */
.cal-day-fast {
  position: absolute;
  bottom: .2rem;
  right: .3rem;
  font-size: .55rem;
  color: var(--text-dim);
  line-height: 1;
}

/* Calendar legend */
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .9rem;
  padding: .6rem .75rem;
  border-top: 1px solid var(--border);
  background: #fdf8f0;
}
.cal-legend-item {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .7rem;
  color: var(--text-dim);
}
.cal-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cal-dot.rank-great { background: #b8860b; }
.cal-dot.rank-vigil { background: #e0952a; }
.cal-dot.rank-poly  { background: #8b1a1a; }
.cal-dot.rank-doxo  { background: #2d7a2d; }
.cal-dot.rank-lent  { background: #6b3580; }

/* Loading state in calendar */
.cal-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Service text assembly ───────────────────────────────────────────────────── */
.service-text-fixed {
  white-space: pre-line;
  font-size: var(--service-font);
  line-height: 1.8;
  color: var(--text);
  margin: .25rem 0 .75rem;
  font-style: italic;
}

.litany-petition {
  font-size: var(--service-font);
  line-height: 1.7;
  color: var(--text);
  margin: .2rem 0 0 .5rem;
}

.litany-response {
  font-size: var(--service-font);
  line-height: 1.6;
  color: var(--gold-dim);
  font-style: italic;
  margin: .05rem 0 .4rem 1.75rem;
}

.service-text-placeholder {
  font-size: calc(var(--service-font) * .9);
  color: var(--text-dim);
  font-style: italic;
  margin: .1rem 0 .5rem;
}

.service-text-reading-ref {
  font-size: var(--service-font);
  color: var(--text);
  margin: .25rem 0 .25rem .5rem;
  padding-left: .75rem;
  border-left: 2px solid var(--border);
}

/* ── Scene gallery ───────────────────────────────────────────────────────────── */

.scene-gallery-header { padding: 1rem 1rem .25rem; }
.scene-gallery-title { font-size: 1.15rem; color: var(--gold-dim); margin-bottom: .3rem; }
.scene-gallery-subtitle { font-size: .85rem; color: var(--text-dim); line-height: 1.5; }

.scene-filter-row {
  display: flex;
  gap: .4rem;
  padding: .5rem 1rem .75rem;
  flex-wrap: wrap;
}
.scene-filter-btn {
  font-family: inherit;
  font-size: .8rem;
  padding: .25rem .75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.scene-filter-btn.active,
.scene-filter-btn:hover {
  background: var(--gold-dim);
  color: #fff;
  border-color: var(--gold-dim);
}

.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  padding: 0 1rem 1.5rem;
}

.scene-card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .18s, transform .18s;
  outline: none;
}
.scene-card:hover,
.scene-card:focus {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--gold);
}

.scene-card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #f0ead8;
}
.scene-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scene-actor-badge {
  position: absolute;
  bottom: .3rem;
  right: .4rem;
  background: rgba(26,10,0,.55);
  color: #f5c842;
  font-size: .75rem;
  padding: .1rem .35rem;
  border-radius: var(--radius-sm);
  letter-spacing: .05em;
}

.scene-card-label {
  padding: .45rem .65rem;
  font-size: .9rem;
  font-weight: bold;
  color: var(--text);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

/* ── Scene modal ─────────────────────────────────────────────────────────────── */

.scene-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(10,5,0,.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .5rem;
  overflow-y: auto;
}
.scene-modal.hidden { display: none; }

.scene-modal-inner {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 860px;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.scene-modal-stage {
  position: relative;
  width: 100%;
  background: #f0ead8;
}
.scene-modal-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.scene-modal-counter {
  position: absolute;
  bottom: .5rem;
  left: .6rem;
  background: rgba(26,10,0,.55);
  color: #d4a520;
  font-size: .78rem;
  padding: .1rem .45rem;
  border-radius: var(--radius-sm);
}

.scene-modal-close {
  position: absolute;
  top: .6rem;
  right: .6rem;
  z-index: 10;
  background: rgba(26,10,0,.6);
  color: #d4a520;
  border: none;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.scene-modal-close:hover { background: rgba(26,10,0,.9); }

.scene-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(26,10,0,.55);
  color: #d4a520;
  border: none;
  border-radius: var(--radius-sm);
  width: 2.2rem;
  height: 3.5rem;
  font-size: 1.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background .15s;
}
.scene-modal-nav:hover { background: rgba(26,10,0,.88); }
.scene-modal-prev { left: .5rem; }
.scene-modal-next { right: .5rem; }

.scene-modal-info {
  padding: .8rem 1rem 1rem;
}
.scene-info-title {
  font-size: 1.05rem;
  color: var(--gold-dim);
  margin-bottom: .3rem;
}
.scene-info-desc {
  font-size: .88rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: .5rem;
}
.scene-info-section {
  font-size: .78rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gold-dim);
  margin: .5rem 0 .2rem;
}
.scene-info-list {
  list-style: none;
  margin: 0 0 .4rem .5rem;
}
.scene-info-list li {
  font-size: .83rem;
  color: var(--text);
  line-height: 1.6;
}
.scene-info-list li::before {
  content: '· ';
  color: var(--gold-dim);
}

.scene-json-btn {
  font-family: monospace;
  font-size: .72rem;
  padding: .2rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
  margin-top: .5rem;
}
.scene-json-btn:hover { border-color: var(--gold-dim); color: var(--gold-dim); }
.scene-json-pre {
  font-family: monospace;
  font-size: .72rem;
  background: #f5f0e8;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .7rem;
  margin-top: .4rem;
  overflow: auto;
  max-height: 200px;
  white-space: pre;
}

@media (max-width: 480px) {
  .scene-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; padding: 0 .5rem 1rem; }
  .scene-modal-nav { width: 1.8rem; height: 2.8rem; font-size: 1.2rem; }
}

/* ── Print ───────────────────────────────────────────────────────────────────── */
/* ── E8: Print button ────────────────────────────────────────────────────────── */
.svc-btn-group {
  margin-left: auto;
  display: flex;
  gap: .5rem;
}
.svc-print-btn {
  padding: .25rem .7rem;
  font-size: .78rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.svc-print-btn:hover { background: var(--gold); color: #fff; border-color: var(--gold); }

/* ── Position diagrams ───────────────────────────────────────────────────────── */
.position-diagram {
  margin: .75rem 0 .5rem;
  padding: .6rem .8rem .5rem;
  background: #fdf8ef;
  border: 1px solid #d4b870;
  border-radius: 6px;
  max-width: 320px;
}
.position-diagram svg {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto .4rem;
}
.position-diagram-caption {
  font-size: .74rem;
  color: #5a4020;
  line-height: 1.45;
  margin: 0 0 .3rem;
  font-style: italic;
}
.position-diagram-legend {
  display: flex;
  gap: .75rem;
  font-size: .72rem;
  color: #7a5a30;
  align-items: center;
}
.position-diagram-legend span {
  display: flex;
  align-items: center;
  gap: .2rem;
}
.position-diagram-legend svg {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  max-width: 14px;
  margin: 0;
}

/* ── E10: Toast notification ─────────────────────────────────────────────────── */
.toast-notification {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--hdr-bg, #1a0a00);
  color: var(--hdr-text, #d4a520);
  padding: .45rem 1.25rem;
  border-radius: .5rem;
  font-size: .85rem;
  z-index: 9999;
  pointer-events: none;
  animation: toast-fadeinout 2.5s ease forwards;
}
@keyframes toast-fadeinout {
  0%   { opacity: 0; transform: translateX(-50%) translateY(.6rem); }
  12%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  78%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── E8: Print media ─────────────────────────────────────────────────────────── */
@media print {
  .app-header .settings-toggle,
  .settings-panel,
  .day-nav,
  .lang-row,
  .service-tabs,
  .feat-banner,
  .app-footer,
  .svc-text-toolbar,
  .svc-print-btn { display: none !important; }

  .app-header {
    background: none;
    color: #000;
    padding: .4rem 0;
    box-shadow: none;
    border-bottom: 1px solid #ccc;
  }
  .app-logo { color: #000; font-size: 1.1rem; }
  .app-main { padding: 0; }

  body { font-size: 11pt; background: #fff; }
  .rubric { color: #8b0000; font-style: italic; }
  .troparion-text, .kontakion-text, .service-text-fixed { font-size: 11pt; }
  .sticheron-text { font-size: 11pt; }
  .litany-petition, .litany-response { font-size: 10.5pt; }
  .service-text-placeholder { display: none !important; }

  /* When printing via the Print button, show only service text panel */
  body.print-service-text .panel { display: none !important; }
  body.print-service-text #panel-service-text { display: block !important; }
  body.print-service-text .day-strip { display: flex !important; }

  /* Default (browser Ctrl+P): show all visible panels */
  body:not(.print-service-text) .panel { display: block !important; }

  .lang-columns { display: block !important; }
  .lang-column { border: 1px solid #ccc; page-break-inside: avoid; margin-bottom: 1rem; }
  .lang-col-fallback-badge, .stichera-lang-note { display: none !important; }
  .saint-card-body { display: block !important; }
  .vespers-type-header { border: none; font-size: 10pt; }
  .position-diagram { display: none !important; }
}
