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

:root {
  --bg:        #ede5d4;
  --ink:       #181009;
  --ink-mid:   #3d2e1e;
  --ink-faint: #5c4a38;
  --rule:      #b09878;
  --amber:     #572f07;
  --amber-mid: #6e3d0f;
}

html { height: 100%; }

body {
  min-height: 100%;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 55% at 28% 12%, rgba(255,248,220,0.65) 0%, transparent 65%),
    radial-gradient(ellipse 55% 45% at 78% 88%, rgba(155,135,105,0.22) 0%, transparent 55%);
  color: var(--ink);
  /* Palatino: classical, humanist — suits divination literature */
  font-family: Georgia, 'Bitstream Charter', 'URW Bookman L', 'Times New Roman', serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1.5rem;
}

/* Paper grain — SVG turbulence rendered as a repeating background tile */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23g)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.038;
  pointer-events: none;
  z-index: 9999;
}

/* ── Header ─────────────────────────────────────────────────────────── */

header {
  width: 100%;
  max-width: 420px;
  padding: 1.5rem 0 0;
  border-bottom: 1px solid var(--rule);
}

/* ── Main ────────────────────────────────────────────────────────────── */

main {
  display: flex;
  align-items: center;
  padding: 2rem 0;
  width: 100%;
  max-width: 420px;
}

.state     { width: 100%; text-align: center; }
.hidden    { display: none !important; }

/* ── Loading ─────────────────────────────────────────────────────────── */

.loading-text {
  font-size: 1.2rem;
  letter-spacing: 0.32em;
  color: var(--ink-faint);
  font-style: italic;
  animation: breathe 2.6s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 0.9; }
}

/* ── Error ───────────────────────────────────────────────────────────── */

.error-text {
  font-size: 1.2rem;
  letter-spacing: 0.32em;
  color: var(--ink-faint);
  font-style: italic;
}

/* ── Reading ─────────────────────────────────────────────────────────── */

.reading {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 2rem;
}

/* ── Hexagram block ──────────────────────────────────────────────────── */

.hexagram {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* The centrepiece — rendered large enough to command the page */
.glyph {
  font-family: 'Noto Sans Symbols 2', 'Apple Symbols', 'Segoe UI Symbol', 'Noto Sans', serif;
  font-size: clamp(10rem, 42vw, 15rem);
  line-height: 1;
  display: block;
  user-select: none;
}

.present .glyph     { color: var(--ink); }
.transformed .glyph { color: var(--amber); }

/* SVG hexagram — same height as the text glyph, width auto to preserve ratio */
svg.glyph {
  height: clamp(10rem, 42vw, 15rem);
  width: auto;
}

.hex-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.75rem;
}

.hex-number {
  font-size: 1rem;
  letter-spacing: 0.28em;
  font-style: italic;
  color: var(--ink-faint);
  display: block;
}

.transformed .hex-number { color: var(--amber-mid); }

.hex-name {
  font-size: clamp(1.2rem, 3.5vw, 1.5rem);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-weight: normal;
  display: block;
}

.hex-name a {
  color: inherit;
  text-decoration: none;
}

.transformed .hex-name { color: var(--amber); }

/* ── Changing-lines separator ────────────────────────────────────────── */
/* Typographic ornament — thin horizontal rules flanking annotated numerals */

.changing-sep {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  width: 100%;
  padding-bottom: 0;
}

.sep-rule {
  flex: 1;
  height: 1px;
  background: var(--rule);
  display: block;
}

.sep-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.sep-label {
  font-size: 0.9rem;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  font-style: italic;
  color: var(--ink-faint);
}

.sep-circles {
  font-size: 1.4rem;
  letter-spacing: 0.18em;
  color: var(--amber-mid);
}

/* ── Footer ──────────────────────────────────────────────────────────── */

footer {
  width: 100%;
  max-width: 420px;
  padding: 2rem 0;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0.25rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: color 0.5s ease, transform 0.5s ease;
  /* Keep emoji-category glyphs monochrome (matches the yin-yang). */
  font-variant-emoji: text;
}

.icon-btn:hover { color: var(--ink); }

/* U+262F (☯) has visibly smaller glyph metrics than U+1F517 (🔗) in most
   fonts, so size it up so the two icons read as equal weight. */
.cast-btn      { font-size: 3rem; }
.cast-btn:hover { transform: rotate(45deg); }

/* ── Timestamp ───────────────────────────────────────────────────────── */

.timestamp {
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  font-style: italic;
  color: var(--ink-faint);
}

/* ── Print ───────────────────────────────────────────────────────────── */

@media print {
  @page { margin: 1.5in 1.25in; }

  body {
    background: white;
    color: black;
    padding: 0;
  }

  /* Kill the paper-grain overlay and gradients */
  body::before { display: none; }

  header { display: none; }

  main {
    padding: 0;
    justify-content: flex-start;
  }

  /* Freeze animations so content is fully visible */
  .u1, .u2, .u3 { animation: none; opacity: 1; transform: none; }

  .glyph { font-size: 8rem; }

  .present .glyph     { color: black; }
  .transformed .glyph { color: #555; }
  svg.glyph rect      { fill: black; }
  svg.glyph rect.cx   { fill: #888; }

  .hex-number { color: #555; }
  .hex-name   { color: black; }
  .transformed .hex-number,
  .transformed .hex-name { color: #555; }

  .hex-name a { color: inherit; text-decoration: none; }

  .sep-rule    { background: #aaa; }
  .sep-label   { color: #555; }
  .sep-circles { color: #555; }

  footer { border-top-color: #aaa; }
  .timestamp { color: #555; }
  .footer-actions { display: none; }
}

/* ── Reveal animation — staggered, unhurried ─────────────────────────── */

@keyframes unfold {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.u1 { animation: unfold 1s cubic-bezier(0.16, 1, 0.3, 1) both; }
.u2 { animation: unfold 1s cubic-bezier(0.16, 1, 0.3, 1) 0.28s both; }
.u3 { animation: unfold 1s cubic-bezier(0.16, 1, 0.3, 1) 0.56s both; }
