/* ============================================================
   ROSARIUM — 玫瑰經默禱
   Aesthetic: candlelit basilica, deep warm darks, gold leaf
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600;700&family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Noto+Serif+TC:wght@300;400;500;600;700&display=swap');

:root {
  --bg-deep: #0e0a07;
  --bg-warm: #1a1109;
  --bg-mid:  #261810;
  --gold-1:  #f3d685;
  --gold-2:  #d9b25a;
  --gold-3:  #8a6a2c;
  --gold-4:  #5a4218;
  --ink-1:   #f4e7c8;
  --ink-2:   #c9b88a;
  --ink-3:   #8a7a52;
  --rose:    #c87b7b;
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; min-height: 100vh; }
body {
  font-family: 'Noto Serif TC', 'Cormorant Garamond', serif;
  background: var(--bg-deep);
  color: var(--ink-1);
  overflow-x: hidden;
}

.app-root {
  position: relative;
  min-height: 100vh;
  width: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%, #2a1a0e 0%, #150c08 60%, #0a0604 100%);
}
.app-root.bg-basilica {
  background:
    radial-gradient(ellipse 60% 80% at 50% 0%, #3a2818 0%, #1a0e08 50%, #050302 100%),
    linear-gradient(180deg, #2a1810 0%, #0a0604 100%);
}
.app-root.bg-midnight {
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%, #0a1428 0%, #04081a 60%, #02030a 100%);
}

/* ================ AMBIENT LAYER ================ */
.ambient-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  overflow: hidden;
}
.candle {
  position: absolute; width: 380px; height: 380px; border-radius: 50%;
  filter: blur(80px);
  background: radial-gradient(circle, rgba(255, 188, 100, 0.45) 0%, rgba(255,150,60,0.15) 40%, transparent 70%);
  animation: flicker 4s ease-in-out infinite;
  mix-blend-mode: screen;
  will-change: opacity, transform;
}
.candle-1 { top: -8%; left: -8%; animation-delay: 0s; }
.candle-2 { top: -10%; right: -10%; animation-delay: 1.3s; background: radial-gradient(circle, rgba(255, 220, 140, 0.35) 0%, rgba(220,140,80,0.1) 40%, transparent 70%);}
.candle-3 { bottom: -10%; left: 10%; animation-delay: 2.1s; }
.candle-4 { bottom: -15%; right: 5%; animation-delay: 0.7s; }
@keyframes flicker {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  25% { opacity: 0.85; transform: scale(1.04); }
  50% { opacity: 0.55; transform: scale(0.97); }
  75% { opacity: 0.78; transform: scale(1.02); }
}
.incense {
  position: absolute; left: 50%; top: 60%; width: 4px; height: 60vh;
  transform: translateX(-50%);
  background: linear-gradient(0deg, transparent 0%, rgba(255,220,180,0.06) 30%, transparent 90%);
  filter: blur(20px);
  animation: incenseRise 9s ease-in-out infinite;
}
@keyframes incenseRise {
  0%, 100% { transform: translateX(-50%) translateY(0) skewX(0); opacity: 0.4; }
  50% { transform: translateX(calc(-50% + 30px)) translateY(-20px) skewX(4deg); opacity: 0.7; }
}
.vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 90% 90% at 50% 50%, transparent 50%, rgba(0,0,0,0.7) 100%);
  pointer-events: none;
}

/* ================ HEADER ================ */
.app-header {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(20px + env(safe-area-inset-top)) 36px 6px;
}
.brand {
  display: flex; align-items: baseline; gap: 14px;
  font-family: 'Cinzel', serif;
}
.brand-mark {
  color: var(--gold-1); font-size: 22px;
  text-shadow: 0 0 18px rgba(255, 200, 100, 0.6);
}
.brand-name {
  font-size: 26px; font-weight: 600; letter-spacing: 0.18em;
  color: var(--ink-1);
  background: linear-gradient(180deg, #fff5d4 0%, #d9b25a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-tag {
  font-family: 'Noto Serif TC', serif; font-size: 13px;
  color: var(--ink-3); letter-spacing: 0.3em;
}
.header-meta {
  display: flex; gap: 28px;
}
.meta-item {
  display: flex; flex-direction: column; align-items: flex-end;
  font-family: 'Cinzel', 'Noto Serif TC', serif;
}
.meta-label {
  font-size: 10px; letter-spacing: 0.3em; color: var(--ink-3);
  text-transform: uppercase;
}
.meta-value {
  font-size: 16px; color: var(--gold-1); font-weight: 500;
  margin-top: 2px;
}

/* ================ MYSTERY PICKER ================ */
.mystery-picker {
  position: relative; z-index: 5;
  display: flex; gap: 12px; justify-content: center;
  padding: 8px 24px 12px;
  flex-wrap: wrap;
}
.mystery-chip {
  position: relative;
  background: linear-gradient(180deg, rgba(40,28,18,0.8) 0%, rgba(20,14,8,0.9) 100%);
  border: 1px solid rgba(217, 178, 90, 0.25);
  border-radius: 2px;
  padding: 10px 22px;
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-2);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: all 0.3s ease;
  letter-spacing: 0.08em;
  min-width: 130px;
  min-height: 44px;
}
.mystery-chip::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, oklch(0.6 0.15 var(--hue) / 0.15) 0%, transparent 70%);
  opacity: 0; transition: opacity 0.4s;
  pointer-events: none;
}
.mystery-chip:hover {
  border-color: rgba(217, 178, 90, 0.6);
  color: var(--gold-1);
  transform: translateY(-1px);
}
.mystery-chip:hover::before { opacity: 1; }
.mystery-chip.is-current {
  border-color: var(--gold-1);
  color: var(--gold-1);
  box-shadow:
    0 0 0 1px rgba(243, 214, 133, 0.3),
    0 0 30px oklch(0.65 0.15 var(--hue) / 0.4),
    inset 0 0 20px oklch(0.4 0.1 var(--hue) / 0.3);
}
.mystery-chip.is-current::before { opacity: 1; }
.chip-name { font-size: 16px; font-weight: 500; }
.chip-days { font-size: 11px; color: var(--ink-3); letter-spacing: 0.2em; }
.chip-suggest {
  position: absolute; top: -8px; right: -8px;
  background: var(--gold-2); color: #1a0e04;
  font-size: 10px; padding: 2px 8px; border-radius: 1px;
  letter-spacing: 0.2em; font-weight: 600;
  font-family: 'Noto Serif TC', serif;
}

/* ================ STAGE ================ */
.stage {
  position: relative; z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 440px);
  gap: 24px;
  align-items: center;
  padding: 6px 28px 16px;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}
.rosary-frame {
  position: relative;
  aspect-ratio: 830 / 1040;
  height: clamp(380px, 64dvh, 600px);
  width: auto;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  display: block;
  min-height: 0;
}
.rosary-svg {
  width: 100%; height: 100%;
  filter: drop-shadow(0 8px 40px oklch(0.32 0.08 var(--hue) / 0.45));
  transform: rotate(28deg) scale(0.9);
  transform-origin: center;
  transform-box: fill-box;
}
.rosary-bead {
  transition: transform 0.35s cubic-bezier(.2,.8,.3,1.2);
}
.rosary-bead.is-active {
  transform: scale(1.32);
  animation: beadPulse 2.8s ease-in-out infinite;
}
.rosary-bead.is-completed {
  transform: scale(1.04);
}
.rosary-bead:hover { transform: scale(1.16); }
.rosary-bead.wood-bead:active { transform: translateY(1px) scale(1.06); }
@keyframes beadPulse {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(255, 243, 212, 0.65)); }
  50% { filter: drop-shadow(0 0 18px rgba(255, 243, 212, 0.95)); }
}

/* ================ PRAYER PANEL ================ */
.prayer-panel {
  position: relative;
  width: 100%;
  background:
    linear-gradient(180deg, rgba(30, 18, 10, 0.78) 0%, rgba(15, 9, 5, 0.7) 100%);
  border: 1px solid rgba(217, 178, 90, 0.25);
  border-radius: 1px;
  padding: 22px 28px 18px;
  backdrop-filter: blur(10px);
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.3),
    0 20px 60px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(243, 214, 133, 0.1);
  animation: prayerFadeIn 0.7s ease;
  align-self: center;
  max-height: 78vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(217, 178, 90, 0.35) transparent;
}
.prayer-panel::-webkit-scrollbar { width: 4px; }
.prayer-panel::-webkit-scrollbar-track { background: transparent; }
.prayer-panel::-webkit-scrollbar-thumb {
  background: rgba(217, 178, 90, 0.35);
  border-radius: 2px;
}
.prayer-panel::before {
  content: "✦";
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--bg-deep);
  color: var(--gold-1);
  padding: 0 12px;
  font-size: 14px;
  text-shadow: 0 0 10px rgba(255,200,100,0.5);
}
@keyframes prayerFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.prayer-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-family: 'Cinzel', 'Noto Serif TC', serif;
  font-size: 11px; letter-spacing: 0.25em;
  color: var(--ink-3);
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(217, 178, 90, 0.15);
  margin-bottom: 14px;
}
.prayer-meta-label { color: var(--gold-2); }

.announce-block {
  text-align: center;
  padding: 8px 0 4px;
}
.announce-decade {
  font-family: 'Cinzel', serif;
  font-size: 11px; letter-spacing: 0.4em;
  color: var(--gold-2); margin-bottom: 6px;
}
.announce-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 26px; font-weight: 500; margin: 0;
  color: var(--ink-1);
  background: linear-gradient(180deg, #fff5d4 0%, var(--gold-2) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: 0.15em;
  animation: titleGlow 4s ease-in-out infinite;
}
@keyframes titleGlow {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(217, 178, 90, 0.4)); }
  50% { filter: drop-shadow(0 0 18px rgba(243, 214, 133, 0.7)); }
}
.announce-sub {
  font-size: 14px; color: var(--ink-2);
  margin-top: 8px; letter-spacing: 0.1em;
}
.announce-scripture {
  font-style: italic;
  font-family: 'Cormorant Garamond', 'Noto Serif TC', serif;
  font-size: 15px; color: var(--ink-2);
  margin-top: 14px;
  padding: 10px 12px;
  border-top: 1px solid rgba(217, 178, 90, 0.15);
  border-bottom: 1px solid rgba(217, 178, 90, 0.15);
  line-height: 1.5;
}
.announce-fruit {
  font-size: 12px; color: var(--ink-3);
  margin-top: 12px; letter-spacing: 0.2em;
}
.announce-fruit span {
  color: var(--gold-1); font-size: 14px; padding: 0 4px;
}

.prayer-block { padding: 4px 0; }
.prayer-title {
  font-family: 'Cinzel', 'Noto Serif TC', serif;
  font-size: 12px; letter-spacing: 0.4em;
  color: var(--gold-2);
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(217, 178, 90, 0.15);
}
.prayer-body {
  font-family: 'Noto Serif TC', serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink-1);
  text-align: center;
  letter-spacing: 0.06em;
}
.prayer-line {
  opacity: 0;
  animation: lineRise 0.6s ease forwards;
}
@keyframes lineRise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================ WELCOME / FINISH OVERLAY ================ */
.welcome-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(10,6,3,0.6) 0%, rgba(0,0,0,0.85) 100%);
  backdrop-filter: blur(4px);
  cursor: pointer;
  animation: overlayFade 0.8s ease;
}
@keyframes overlayFade {
  from { opacity: 0; } to { opacity: 1; }
}
.welcome-inner {
  text-align: center;
  padding: 50px 70px;
  border: 1px solid rgba(217, 178, 90, 0.3);
  background: linear-gradient(180deg, rgba(30,18,10,0.6), rgba(10,6,3,0.6));
  position: relative;
}
.welcome-inner::before, .welcome-inner::after {
  content: ""; position: absolute; width: 30px; height: 30px;
  border: 1px solid var(--gold-2);
}
.welcome-inner::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.welcome-inner::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }
.welcome-mark {
  font-size: 48px; color: var(--gold-1);
  text-shadow: 0 0 30px rgba(243, 214, 133, 0.7);
  animation: markBreathe 4s ease-in-out infinite;
}
@keyframes markBreathe {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.05); opacity: 1; }
}
.welcome-title {
  font-family: 'Cinzel', 'Noto Serif TC', serif;
  font-size: 42px; letter-spacing: 0.5em;
  color: var(--gold-1);
  margin: 18px 0 8px;
  background: linear-gradient(180deg, #fff5d4 0%, var(--gold-2) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-sub {
  font-size: 16px; letter-spacing: 0.25em; color: var(--ink-2);
  margin-bottom: 20px;
}
.welcome-cta {
  font-size: 14px; color: var(--gold-1); letter-spacing: 0.2em;
  padding: 10px 20px;
  border: 1px solid rgba(217, 178, 90, 0.3);
  display: inline-block;
  margin-bottom: 14px;
}
.welcome-hint {
  font-size: 11px; letter-spacing: 0.3em; color: var(--ink-3);
}

/* ================ FOOTER CTRLS ================ */
.app-footer {
  position: relative; z-index: 5;
  display: flex; justify-content: center; gap: 12px;
  padding: 12px 24px calc(22px + env(safe-area-inset-bottom));
}
.ctrl {
  background: linear-gradient(180deg, rgba(40,28,18,0.8) 0%, rgba(15,9,5,0.9) 100%);
  border: 1px solid rgba(217, 178, 90, 0.25);
  color: var(--ink-2);
  padding: 10px 18px;
  font-family: 'Noto Serif TC', serif;
  font-size: 14px; letter-spacing: 0.15em;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 1px;
  min-width: 50px;
  min-height: 44px;
}
.ctrl:hover {
  border-color: var(--gold-2);
  color: var(--gold-1);
  box-shadow: 0 0 16px rgba(217, 178, 90, 0.3);
}
.ctrl:focus-visible,
.mystery-chip:focus-visible {
  outline: 2px solid var(--gold-1);
  outline-offset: 2px;
}
.ctrl.primary {
  background: linear-gradient(180deg, #4a3418 0%, #2a1c0c 100%);
  border-color: var(--gold-2);
  color: var(--gold-1);
  padding: 10px 28px;
}
.ctrl.primary:hover {
  background: linear-gradient(180deg, #5a4222 0%, #3a2614 100%);
  box-shadow: 0 0 24px rgba(243, 214, 133, 0.4);
}

/* Tweaks panel font override so it matches */
.tweaks-panel { font-family: 'Noto Serif TC', serif !important; }

@media (max-width: 900px) {
  .app-root {
    grid-template-rows: auto auto auto auto;
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
    align-content: start;
    padding: 0 14px 8px;
    overflow: visible;
  }
  .rosary-frame {
    width: 100%;
    height: clamp(160px, 24dvh, 200px);
    aspect-ratio: auto;
    max-width: 100%;
    max-height: none;
    margin: 0 auto;
    overflow: visible;
  }
  .rosary-svg { transform: rotate(30deg) scale(0.65); }
  .prayer-panel {
    max-height: none;
    overflow-y: visible;
    padding: 14px 18px 70px;
  }
}
@media (max-width: 768px) {
  .app-header {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: calc(8px + env(safe-area-inset-top)) 14px 4px;
  }
  .brand { gap: 8px; }
  .header-meta { gap: 12px; }
  .meta-value { font-size: 13px; }
  .meta-label { font-size: 10px; }
  .mystery-picker { gap: 6px; padding: 4px 10px 6px; }
  .mystery-chip { padding: 6px 14px; min-height: 44px; }
  .chip-name { font-size: 14px; }
  .chip-days { font-size: 11px; }
  /* On mobile, only display today's mystery for a calmer focus. */
  .mystery-chip:not(.is-suggested) { display: none; }
  .announce-title { font-size: 18px; letter-spacing: 0.1em; }
  .announce-decade { font-size: 10px; }
  .announce-sub { font-size: 13px; margin-top: 4px; }
  .announce-scripture { font-size: 13px; padding: 6px 6px; margin-top: 8px; line-height: 1.45; }
  .announce-fruit { font-size: 11px; margin-top: 8px; }
  .prayer-meta { font-size: 10px; padding-bottom: 6px; margin-bottom: 8px; }
  .prayer-title { font-size: 11px; margin-bottom: 8px; padding-bottom: 6px; }
  .prayer-body { font-size: 15px; line-height: 1.65; }
  .welcome-inner { padding: 32px 38px; }
  .welcome-title { font-size: 32px; letter-spacing: 0.4em; }
  .welcome-sub { font-size: 14px; }
  .ctrl { padding: 8px 14px; font-size: 13px; min-width: 44px; min-height: 44px; }
  .ctrl.primary { padding: 8px 20px; }
  .app-footer {
    gap: 8px;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 6;
    background: linear-gradient(180deg, transparent 0%, rgba(14,10,7,0.92) 40%);
    backdrop-filter: blur(6px);
  }
}
@media (max-width: 480px) {
  .brand-name { font-size: 20px; letter-spacing: 0.14em; }
  .brand-tag { display: none; }
  .header-meta { gap: 10px; }
  .rosary-frame { height: clamp(160px, 26dvh, 220px); }
}

/* ================ REDUCED MOTION ================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .candle,
  .incense,
  .rosary-bead.is-active,
  .announce-title,
  .welcome-mark { animation: none !important; }
  .prayer-line { opacity: 1 !important; transform: none !important; }
}
