/* Now, and More — styles */
/* Light palette is the default. Theme resolution:
   - data-theme="dark"  -> dark palette, regardless of system
   - data-theme="light" -> light palette, regardless of system
   - no data-theme      -> system prefers-color-scheme rules */
:root {
  color-scheme: light;
  --bg: #f5efe2;
  --bg-soft: #efe7d6;
  --ink: #2b2620;
  --ink-soft: #6f6656;
  --accent: #b23a2a; /* vermillion */
  --card-bg: rgba(255, 252, 244, 0.82);
  --card-border: rgba(43, 38, 32, 0.14);
  --serif: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "Noto Sans SC", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --glow-color: rgba(178, 58, 42, 0.16);
}

/* Dark palette (the var assignments are repeated under the media query
   below — a selector list cannot span a media-query boundary). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171512;
  --bg-soft: #1e1b17;
  --ink: #ece5d5;
  --ink-soft: #a29885;
  --accent: #e0684f;
  --card-bg: rgba(34, 30, 25, 0.85);
  --card-border: rgba(236, 229, 213, 0.16);
  --glow-color: rgba(224, 104, 79, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #171512;
    --bg-soft: #1e1b17;
    --ink: #ece5d5;
    --ink-soft: #a29885;
    --accent: #e0684f;
    --card-bg: rgba(34, 30, 25, 0.85);
    --card-border: rgba(236, 229, 213, 0.16);
    --glow-color: rgba(224, 104, 79, 0.14);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
}

/* drifting glow — second-layer randomness */
#glow {
  position: fixed;
  width: 55vmax;
  height: 55vmax;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow-color) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
  transition: transform 1.4s ease, opacity 1.4s ease;
  top: -15vmax;
  left: -15vmax;
}

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px 0;
}

.brand { display: flex; align-items: center; gap: 10px; }

.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--accent);
  color: #fff8ee;
  font-family: var(--serif);
  font-weight: 900;
  font-size: 19px;
  border-radius: 5px;
  transform: rotate(-3deg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; font-weight: 900; letter-spacing: 0.06em; }
.brand-text small { font-size: 11px; color: var(--ink-soft); letter-spacing: 0.08em; }

/* ---------- Settings (one quiet button + panel) ---------- */
.settings { position: relative; }

#settings-btn {
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  opacity: 0.55;
  cursor: pointer;
}
#settings-btn:hover, #settings-btn:focus-visible { opacity: 1; color: var(--ink); }

.settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 10;
  width: 268px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  gap: 15px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 16px 18px 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
  text-align: left;
}

.setting-row { display: flex; flex-direction: column; gap: 7px; }
.setting-label { font-size: 12.5px; color: var(--ink-soft); letter-spacing: 0.16em; }

.lang-segment {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  overflow: hidden;
}
.seg-btn {
  font-family: var(--sans);
  font-size: 13px;
  padding: 5px 15px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.seg-btn.active { color: var(--accent); font-weight: 600; background: var(--bg-soft); }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  width: min(880px, 92vw);
  margin: 0 auto;
  padding: 10px 0 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.tagline { color: var(--ink-soft); font-size: 15px; letter-spacing: 0.12em; margin: 14px 0 4px; }
.date-line { font-size: 16px; letter-spacing: 0.1em; margin: 4px 0 6px; color: var(--ink); }

/* ---------- Clocks (shared) ---------- */
.clock { margin: 6px 0 10px; user-select: none; }

/* paper (default): huge serif numerals */
body[data-clock-style="paper"] .clock-digital {
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(64px, 15vw, 148px);
  letter-spacing: 0.02em;
  line-height: 1.05;
}
body[data-clock-style="paper"] .clock-digital .colon { color: var(--accent); }

/* minimal: ultra-thin sans */
body[data-clock-style="minimal"] .clock-digital {
  font-family: var(--sans);
  font-weight: 100;
  font-size: clamp(64px, 16vw, 160px);
  letter-spacing: 0.04em;
  line-height: 1.05;
}
body[data-clock-style="minimal"] .clock-digital .colon { opacity: 0.35; }

/* analog */
.clock-analog svg { width: min(300px, 62vw); height: auto; display: block; margin: 0 auto; }
.dial-face { fill: var(--card-bg); stroke: var(--card-border); stroke-width: 1.5; }
.dial-tick { stroke: var(--ink-soft); stroke-width: 1.4; }
.dial-tick.hour { stroke: var(--ink); stroke-width: 2.6; }
.hand { stroke-linecap: round; }
.hand-hour { stroke: var(--ink); stroke-width: 6; }
.hand-minute { stroke: var(--ink); stroke-width: 3.6; }
.hand-second { stroke: var(--accent); stroke-width: 1.6; }
.dial-pin { fill: var(--accent); }
.analog-readout {
  font-family: var(--sans);
  font-weight: 300;
  font-size: 22px;
  letter-spacing: 0.22em;
  margin-top: 8px;
  color: var(--ink-soft);
}

/* flip */
.clock-flip { display: flex; align-items: center; gap: 10px; justify-content: center; }
.flip-card {
  position: relative;
  min-width: 92px;
  padding: 14px 10px;
  font-family: var(--sans);
  font-weight: 300;
  font-size: clamp(48px, 11vw, 84px);
  line-height: 1;
  color: var(--ink);
  background: linear-gradient(180deg, var(--card-bg) 0%, var(--card-bg) 49%, rgba(0,0,0,0.07) 50%, var(--card-bg) 100%);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.10);
}
.flip-card::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  border-top: 1px solid var(--card-border);
}
.flip-card.tick { animation: flipTick 0.28s ease; }
@keyframes flipTick {
  0% { transform: rotateX(0deg); }
  45% { transform: rotateX(-38deg); }
  100% { transform: rotateX(0deg); }
}
.flip-sep { font-size: 40px; color: var(--ink-soft); }

/* vertical */
.clock-vertical { display: flex; justify-content: center; min-height: 240px; }
.vertical-time {
  writing-mode: vertical-rl;
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(34px, 7.5vw, 54px);
  letter-spacing: 0.28em;
  line-height: 1.6;
  max-height: 62vh;
}
.vertical-time .v-sec { color: var(--accent); }
.vertical-stack {
  writing-mode: horizontal-tb;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(44px, 10vw, 72px);
  line-height: 1.25;
  letter-spacing: 0.1em;
}

/* ---------- Minute progress ---------- */
.progress-track {
  width: min(420px, 70vw);
  height: 2px;
  background: var(--card-border);
  border-radius: 2px;
  overflow: hidden;
  margin: 10px 0 26px;
}
#minute-progress { height: 100%; width: 0%; background: var(--accent); }

/* ---------- Random stage card ---------- */
.card {
  width: min(620px, 92vw);
  min-height: 168px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 22px 26px 24px;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
  transition: opacity 0.35s ease, transform 0.35s ease;
  outline: none;
}
.card:focus-visible { border-color: var(--accent); }
.card.leaving { opacity: 0; transform: translateY(8px); }

.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-category {
  font-size: 13px;
  letter-spacing: 0.28em;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.card-meta { font-size: 13px; color: var(--ink-soft); text-align: right; }

.card-body { font-size: 19px; line-height: 1.75; }
.card-body .big { font-size: 30px; font-weight: 900; line-height: 1.4; }
.card-body .poem-title { font-size: 21px; font-weight: 900; }
.card-body .poem-author { color: var(--ink-soft); font-size: 15px; margin-left: 10px; }
.card-body .poem-line { display: block; }
.card-body .sub { color: var(--ink-soft); font-size: 15px; }
.card-body .fact-row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 6px; font-size: 15px; color: var(--ink-soft); }
.card-body .fact-row b { color: var(--ink); font-weight: 600; }
.card-body .swatch {
  display: inline-block;
  width: 54px; height: 54px;
  border-radius: 10px;
  vertical-align: middle;
  margin-right: 14px;
  border: 1px solid var(--card-border);
}
.card-body .moon-glyph { font-size: 44px; margin-right: 12px; vertical-align: middle; }
.card-body a.gossip-link {
  color: inherit;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.5;
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
}
.card-body a.gossip-link:hover { color: var(--accent); }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; gap: 16px; margin-top: 22px; }
#draw-btn {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.14em;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
#draw-btn:hover, #draw-btn:focus-visible { color: var(--accent); }
.encounter { color: var(--ink-soft); font-size: 14px; letter-spacing: 0.1em; }
.hint { color: var(--ink-soft); font-size: 12.5px; margin: 10px 0 0; letter-spacing: 0.08em; }

/* ---------- Clock style chips (inside the settings panel) ---------- */
.style-chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-start; }
.style-chip {
  font-family: var(--sans);
  font-size: 13px;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.style-chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- Sign selector & astrology ---------- */
.sign-select {
  font-family: var(--sans);
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.card-body .astro-stars { color: var(--accent); letter-spacing: 0.12em; }
.card-body .swatch-sm {
  display: inline-block;
  width: 13px; height: 13px;
  border-radius: 50%;
  vertical-align: -1px;
  margin: 0 4px;
  border: 1px solid var(--card-border);
}

/* ---------- Footer ---------- */
.footer {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 22px 16px;
  font-family: var(--sans);
}
.second-random { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; letter-spacing: 0.08em; }
.footer-note { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.08em; }

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  .card { padding: 18px 18px 20px; }
  .card-body { font-size: 17px; }
  .flip-card { min-width: 70px; }
  .brand-text small { display: none; }
  .footer-note { display: none; }
}
