/* The free reading, /i-ching-reading/ (tools/pages/cast.py, assets/cast.js). The site's tokens (site.css); the cast
   looks like the app's Start: lines in ink, changing lines in the accent with a glow, the names stamped as seals. */

:root {
  --on-accent: #FFFFFF;
  --glow: rgba(58, 91, 255, 0.45);
  --glow-soft: rgba(58, 91, 255, 0.13);
}
@media (prefers-color-scheme: dark) {
  :root {
    --on-accent: #0B0930;
    --glow: rgba(143, 162, 255, 0.55);
    --glow-soft: rgba(143, 162, 255, 0.16);
  }
}

.cast-page { padding-block: clamp(1rem, 0.6rem + 2vw, 3rem) clamp(2.5rem, 1.5rem + 4vw, 4.5rem); }
.cast-page .wrap { max-width: 40rem; }

/* The question */

.ask h1 { font-size: clamp(2rem, 1.55rem + 2.4vw, 3.25rem); line-height: 1.08; letter-spacing: -0.03em; margin-bottom: 0.3em; }
html[lang^="zh"] .ask h1 { letter-spacing: 0.04em; line-height: 1.25; }
.ask .lede { font-size: 1.125rem; line-height: 1.5; margin-bottom: 1.1rem; }
html[lang^="zh"] .ask .lede { line-height: 1.7; }
.question-label { display: block; margin-bottom: 6px; font-weight: 600; }
.question {
  display: block;
  width: 100%;
  min-height: 3.2em;
  padding: 12px 14px;
  font: inherit;
  font-size: 1.1875rem;
  line-height: 1.45;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  resize: vertical;
}
.question::placeholder { color: var(--muted); opacity: 0.85; }
.question:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
button.button.start {
  display: block;
  width: 100%;
  margin: 12px 0 0;
  padding: 15px 20px;
  font-size: 1.1875rem;
  background: var(--accent);
  color: var(--on-accent);
}
button.button.start:hover { text-decoration: none; filter: brightness(1.06); }
button.button.start:disabled { opacity: 0.5; cursor: not-allowed; }
.cast-error { margin: 0.75rem 0 0; color: var(--danger); }
.examples-label { margin: 0.9rem 0 0.4rem; font-size: 0.9375rem; color: var(--muted); }
.examples { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.example {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  font: inherit;
  font-size: 1.0625rem;
  line-height: 1.35;
  text-align: left;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.example::after { content: "↖"; flex: none; color: var(--accent); }
.example:hover, .example:active { border-color: var(--accent); }
/* The buttons' own pressed look, not the browser's tap highlight (which flashed over the stage as it opened). */
button.button.start, .example, button.button.again { -webkit-tap-highlight-color: transparent; }
button.button.start:active { filter: brightness(0.92); }
.private { margin: 0.9rem 0 0; font-size: 0.875rem; color: var(--muted); }

/* How it works, and "Is it accurate?": below the question and the reading, for anyone who wants to know more. */

.about { margin-top: clamp(2.5rem, 2rem + 3vw, 4rem); padding-top: 1.75rem; border-top: 1px solid var(--line); }
.about h2 { font-size: 1.375rem; letter-spacing: -0.015em; margin-bottom: 0.7em; }
html[lang^="zh"] .about h2 { letter-spacing: 0.02em; }
.about > p { color: var(--muted); }
.about-list { list-style: none; margin: 0 0 1em; padding: 0; display: grid; gap: 18px; }
.about-list h3 { margin-bottom: 4px; }
.about-list p { margin: 0; color: var(--muted); }
.accurate { margin-top: 2.25rem; }
.accurate > p { color: var(--ink); }
.accurate .to-question { font-weight: 600; }
.accurate .to-question::after { content: " ↑"; }
/* On the English page a long Chinese quote wraps like the text around it (short terms stay whole: site.css). */
html[lang="en"] .cast-page span.zh-quote { white-space: normal; }

/* The figure: six lines bottom to top (DOM order 1…6), yang one bar, yin two; changing lines in the accent. --bw is
   the bar's width; everything else follows it. */

.hexfig {
  --bw: min(300px, 72vw, 38vh);
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column-reverse;
  gap: calc(var(--bw) * 0.085);
  width: var(--bw);
}
.hexfig .ln {
  position: relative;
  display: flex;
  justify-content: space-between;
  height: calc(var(--bw) * 0.098);
  color: var(--ink);
}
.hexfig .ln > span { display: block; height: 100%; background: currentColor; border-radius: 3px; }
.hexfig .yang > span { width: 100%; }
.hexfig .yin > span { width: 40%; }
.hexfig .ln.changing { color: var(--accent); }
.hexfig .ln.changing > span { box-shadow: 0 0 calc(var(--bw) * 0.07) var(--glow); }
/* An empty place, before its line lands. */
.hexfig .ln.pending > span { visibility: hidden; }
.hexfig .ln.pending::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: var(--line);
  opacity: 0.55;
}
/* The flare when the hexagram is complete. */
.hexfig::after {
  content: "";
  position: absolute;
  inset: -22% -18%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--glow-soft), transparent);
  opacity: 0;
  pointer-events: none;
}
.hexfig.done::after { opacity: 1; }

/* The names as seals (印章): 本卦, then → 之卦, tilted a little as if stamped by hand. */

.seals { display: flex; align-items: flex-start; justify-content: center; gap: 14px; }
.seal { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 64px; opacity: 0; }
.seal.stamped { opacity: 1; }
.seal.first { --tilt: -3deg; }
.seal.second { --tilt: 2deg; }
.seal-face {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 64px;
  padding: 0 14px;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 6px;
  box-shadow: 0 2px 10px var(--glow-soft);
  transform: rotate(var(--tilt));
}
.seal-face::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  opacity: 0.55;
}
.seal-face::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
}
.seal-face .classical.seal-zh {
  margin: 0;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0.02em;
  color: inherit;
  white-space: nowrap;
  word-break: keep-all;
}
.seal-sub { margin: 0; max-width: 9.5rem; font-size: 0.9375rem; line-height: 1.3; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.seal-arrow { display: flex; align-items: center; height: 64px; font-size: 1.5rem; font-weight: 600; color: var(--muted); opacity: 0; }
.seal-arrow.on { opacity: 1; }

/* The stage: the cast played over the page, as in the app. Tap anywhere skips. */

html.stage-open, html.stage-open body { overflow: hidden; }
.stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top)) var(--gutter) max(16px, env(safe-area-inset-bottom));
  background: var(--bg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.stage.leaving { pointer-events: none; }
.stage.leaving > * { opacity: 0; }
.stage-stalks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage-caption { position: relative; margin: 3vh 0 0; font-size: 1.125rem; color: var(--muted); text-align: center; }
.stage-body {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: min(4.5vh, 34px);
  width: 100%;
}
.stalk-room { width: 100%; height: min(110px, 13vh); }
.stage-seals { min-height: 104px; }
.stage-skip {
  position: relative;
  min-height: 44px;
  padding: 10px 22px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.stage.still .stalk-room { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .stage .ln.landed > span { animation: land 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  .stage .ln.landed.changing > span { animation: land 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both, breathe 1.6s ease-in-out 260ms infinite; }
  .stage .hexfig.flare::after { animation: flare 1s ease-out both; }
  .stage .seal.stamped .seal-face { animation: stamp 300ms ease-out both; }
  .stage .seal.stamped .seal-face::before { animation: ripple 600ms ease-out 120ms both; }
  .stage .seal.stamped .seal-sub { animation: appear 300ms ease-out 100ms both; }
  .stage .seal-arrow { transition: opacity 200ms ease; }
  .stage > * { transition: opacity 260ms ease; }
  .reading:not([hidden]) { animation: appear 360ms ease-out both; }
}
@keyframes land {
  from { transform: scale(1.12, 1.7); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes breathe {
  50% { box-shadow: 0 0 calc(var(--bw) * 0.12) var(--glow); }
}
@keyframes flare {
  0% { opacity: 0; transform: scale(0.8); }
  30% { opacity: 1; }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes stamp {
  0% { transform: rotate(var(--tilt)) scale(1.6); opacity: 0; }
  53% { transform: rotate(var(--tilt)) scale(1); opacity: 1; }
  76% { transform: rotate(var(--tilt)) scale(0.95); }
  100% { transform: rotate(var(--tilt)) scale(1); opacity: 1; }
}
@keyframes ripple {
  from { transform: scale(1); opacity: 0.6; }
  to { transform: scale(1.45); opacity: 0; }
}
@keyframes appear {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* The reading. The card (question, hexagram, names) is the finished moment people keep: it stands on its own. */

.cast-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 1.5rem;
  padding: 22px 18px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: center;
}
.cast-card .kicker { margin: 0 0 0.3em; }
.reading-question { max-width: 30rem; margin: 0 0 1.5rem; font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.5rem); font-weight: 600; line-height: 1.35; text-wrap: balance; }
html[lang^="zh"] .reading-question { line-height: 1.6; }
.reading-figure { display: flex; flex-direction: column; align-items: center; gap: 30px; margin: 0 0 18px; padding: 8px 0 0; }
.reading-figure .hexfig { --bw: min(220px, 60vw); }
.card-mark { margin: 0; font-size: 0.75rem; letter-spacing: 0.04em; color: var(--muted); opacity: 0.85; }
/* The rule, and under it the app's own note that it is one way to read a cast. */
.rule { margin: 0 0 1.5rem; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent); }
.rule-line { margin: 0; font-weight: 600; line-height: 1.5; }
.rule-note { margin: 0.3em 0 0; font-size: 0.875rem; color: var(--muted); }
/* A line's label (九五) and a name are never split across lines (Chinese pages). */
.rule-line .kept { white-space: nowrap; }
.reading-passage { border-top: 1px solid var(--line); padding-top: 1.25rem; margin-bottom: 1.25rem; }
.passage-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0 0 0.6em; font-size: 0.9375rem; font-weight: 600; }
.passage-title a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-decoration-thickness: 2px; }
.passage-title a:hover { text-decoration-color: currentColor; }
.passage-title .role { padding: 1px 9px; border: 1px solid currentColor; border-radius: 999px; font-size: 0.8125rem; font-weight: 500; color: var(--accent); }
.reading-passage .classical.prominent { font-size: clamp(1.5rem, 1.25rem + 1.2vw, 1.875rem); }

/* After the passages: a cast is a prompt, not a verdict. */

.reading-prompt { margin: 0; padding-top: 1.25rem; border-top: 1px solid var(--line); font-size: 1.0625rem; line-height: 1.55; }
html[lang^="zh"] .reading-prompt { line-height: 1.75; }

/* The call to the app, and how to read this same cast there (Handoff A): step 1 installs it (the store buttons), and
   the six values follow right under them. */

.cast-cta { margin: 1.75rem 0 1.5rem; padding: 20px; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cast-cta .cta-title { margin: 0 0 0.5em; font-size: 1.25rem; letter-spacing: -0.01em; line-height: 1.3; }
html[lang^="zh"] .cast-cta .cta-title { letter-spacing: 0.02em; }
.cast-cta .actions { margin: 0.6rem 0 0; gap: 10px; }
.cast-cta .button.store { min-height: 48px; padding: 13px 20px; }
.handoff { margin: 1.25rem 0 0; padding: 1.1rem 0 0; border-top: 1px solid var(--line); }
.handoff h3 { margin: 0 0 0.45em; font-size: 1.0625rem; }
.handoff-lead { margin: 0 0 0.75em; color: var(--muted); }
.handoff-steps { margin: 0; padding-left: 1.5em; }
.handoff-steps > li { margin: 0 0 0.6em; padding-left: 0.15em; }
.handoff-steps > li::marker { color: var(--accent); font-weight: 600; }
.handoff-steps > li.install { margin-bottom: 1em; }
.install-step { margin: 0; }
.handoff-steps .cta-under { margin-top: 0.45em; }
/* The app's Enter lines form, filled in: one row per line, line 6 at the top, the four values with this cast's on. */
.line-form { list-style: none; margin: 0.7em 0 0.4em -1.65em; padding: 10px; display: grid; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; container-type: inline-size; }
.line-row-shown { display: flex; align-items: center; gap: 8px; }
.line-form .place { flex: none; width: 3.6em; font-size: 0.8125rem; color: var(--muted); }
.chips { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 3px 2px;
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  line-height: 1.15;
  text-align: center;
}
.chip b { font-family: var(--mono); font-size: 1rem; font-weight: 600; }
.chip small { max-width: 100%; font-size: 0.8125rem; line-height: 1.15; overflow-wrap: break-word; }
/* The English names are two words (young yang): one word a line in every chip, so the four read alike. */
html[lang="en"] .chip small { width: min-content; }
/* Little room (a narrow phone, large text): each row's place above its chips; less still, the chips two by two. The
   numbers stay large, and no label runs into the next chip. */
@container (max-width: 15em) {
  .line-row-shown { flex-direction: column; align-items: stretch; gap: 4px; }
  .line-form .place { width: auto; }
}
@container (max-width: 11em) {
  .chips { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.chip.moving { color: var(--accent); }
.chip.on { background: var(--accent); color: var(--on-accent); }

.again-row { margin: 0; text-align: center; }
button.button.again { min-height: 48px; padding: 13px 28px; font-size: 1.0625rem; background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
button.button.again:hover, button.button.again:active { text-decoration: none; background: var(--bg); }

@media (max-width: 360px) {
  .cast-cta { padding: 18px 16px; }
  .cast-cta .button.store { padding-inline: 18px; }
  .seals { gap: 10px; }
  .seal-face { min-width: 56px; height: 56px; padding: 0 10px; }
  .seal-face .classical.seal-zh { font-size: 29px; }
  .seal-arrow { height: 56px; }
  .cast-card { padding-inline: 12px; }
  .line-form { padding: 8px 6px; }
  .line-form .place { width: 3.2em; }
}
