/* I-Ching Coin Oracle */

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

:root {
  --ink: #1b1f2e;
  --ink-deep: #12141f;
  --parchment: #f3ecdc;
  --bronze: #b98a3e;
  --bronze-bright: #d9a94f;
  --text: #e8e4d8;
  --muted: #9a96a8;
}

body {
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-deep) 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}

main {
  width: 100%;
  max-width: 34rem;
  text-align: center;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  color: var(--bronze-bright);
  letter-spacing: 0.03em;
}

.subtitle {
  color: var(--muted);
  margin-top: 0.25rem;
  margin-bottom: 1.5rem;
}

/* Skill & mantra for the reading — present but understated. */
#guidance {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin: -0.5rem 0 1.25rem;
}

.guidance-item strong {
  color: var(--bronze);
  font-weight: 600;
}

#status {
  min-height: 2.5em;
  margin-bottom: 1rem;
  color: var(--text);
}

/* --- Coins --- */

#coin-area {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.coin-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.coin {
  width: 5.5rem;
  height: 5.5rem;
  perspective: 500px;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.45));
  user-select: none;
}

.coin-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.coin .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.coin .face.back {
  transform: rotateY(180deg);
}

.coin .face svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Both flips decelerate into the landing; heads ends on the front face
   (whole turns), tails a half-turn short so the back face shows. */
.coin-inner.flip-heads {
  animation: flip-heads 1.4s cubic-bezier(0.15, 0.6, 0.25, 1) forwards;
}

.coin-inner.flip-tails {
  animation: flip-tails 1.4s cubic-bezier(0.15, 0.6, 0.25, 1) forwards;
}

@keyframes flip-heads {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(1440deg); }
}

@keyframes flip-tails {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(1260deg); }
}

.coin-caption {
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1.1em;
}

/* --- Hexagram figure --- */

#figure {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0 auto 1.5rem;
  max-width: 22rem;
  min-height: 10.5rem;
}

.line {
  display: grid;
  grid-template-columns: 1.5rem 1fr 1.5rem 7.5rem;
  align-items: center;
  gap: 0.5rem;
  animation: line-in 0.45s ease-out;
}

@keyframes line-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.line .pos {
  color: var(--muted);
  font-size: 0.8rem;
}

.line .bar {
  height: 0.9rem;
}

.line .bar.solid {
  background: var(--text);
  border-radius: 2px;
}

.line .bar.broken {
  display: flex;
  gap: 22%;
}

.line .bar.broken i {
  flex: 1;
  background: var(--text);
  border-radius: 2px;
}

.line .mark {
  color: var(--bronze-bright);
  font-size: 1.1rem;
}

.line .value {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: left;
}

.line.highlight .bar,
.line.highlight .bar.broken i {
  background: var(--bronze-bright);
}

/* Separate the lower trigram (lines 1–3) from the upper (lines 4–6). */
.line[data-pos="4"] {
  margin-bottom: 1rem;
}

/* --- Controls --- */

button {
  font-size: 1.05rem;
  padding: 0.7rem 2rem;
  border-radius: 2rem;
  border: 1px solid var(--bronze);
  background: var(--bronze);
  color: var(--ink-deep);
  cursor: pointer;
  font-weight: 600;
}

button:hover:not(:disabled) {
  background: var(--bronze-bright);
  border-color: var(--bronze-bright);
}

button:disabled {
  opacity: 0.5;
  cursor: wait;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid var(--bronze-bright);
  outline-offset: 3px;
}

/* The toss button is itself a coin: round, bronze body, inscription-dark
   text, inner rim — distinct from the gold "Reveal reading" pill. */
#toss {
  width: 6.5rem;
  height: 6.5rem;
  padding: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #c9a35a, #8a6a30 55%, #5a441e);
  border: 2px solid #3a2b12;
  box-shadow:
    inset 0 0 0 4px rgba(226, 186, 106, 0.45),
    0 5px 10px rgba(0, 0, 0, 0.4);
  color: #3f2e10;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1.15;
}

#toss:hover:not(:disabled) {
  background: radial-gradient(circle at 38% 32%, #d9b46a, #9a7a3a 55%, #6a5426);
  border-color: #3a2b12;
}

#toss:active:not(:disabled) {
  transform: translateY(1px) scale(0.97);
}

/* --- Results --- */

#results {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.hexagram-card {
  background: var(--parchment);
  color: var(--ink-deep);
  border-radius: 0.75rem;
  padding: 1.25rem 2rem;
  width: 100%;
  max-width: 20rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.hexagram-card h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #7a6435;
}

.hexagram-card .glyph {
  font-size: 3.5rem;
  line-height: 1.2;
}

.hexagram-card .name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-weight: 600;
}

.hexagram-card .english {
  color: #4a4436;
  margin-top: 0.25rem;
}

/* Drawn hexagram in the primary card — changing lines shown in bronze. */
.mini-figure {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 8rem;
  margin: 0.75rem auto;
}

.mini-line {
  display: grid;
  grid-template-columns: 1fr 1.1rem;
  align-items: center;
  gap: 0.35rem;
}

.mini-line .bar {
  height: 0.75rem;
}

.mini-line .bar.solid {
  background: var(--ink-deep);
  border-radius: 2px;
}

.mini-line .bar.broken {
  display: flex;
  gap: 22%;
}

.mini-line .bar.broken i {
  flex: 1;
  background: var(--ink-deep);
  border-radius: 2px;
}

.mini-line.changing .bar.solid,
.mini-line.changing .bar.broken i {
  background: var(--bronze);
  box-shadow: 0 0 0 1px rgba(185, 138, 62, 0.45);
}

.mini-line .mark {
  color: var(--bronze);
  font-weight: 700;
  line-height: 1;
}

.mini-line[data-pos="4"] {
  margin-bottom: 0.9rem;
}

/* Transformed hexagram: present but secondary to the primary result. */
.hexagram-card.secondary {
  background: transparent;
  border: 1px solid rgba(243, 236, 220, 0.25);
  color: var(--text);
  max-width: 16rem;
  padding: 0.9rem 1.5rem;
}

.hexagram-card.secondary h3 {
  color: var(--muted);
}

.hexagram-card.secondary .glyph {
  font-size: 2.2rem;
}

.hexagram-card.secondary .name {
  font-size: 1.05rem;
}

.hexagram-card.secondary .english {
  color: var(--muted);
}

.changing-note {
  color: var(--bronze-bright);
}

.ext-link {
  font-size: 0.85rem;
  margin-top: -0.25rem;
}

.ext-link a {
  color: var(--bronze-bright);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.ext-link a:hover {
  color: var(--parchment);
}

/* --- Byline --- */

#byline {
  position: fixed;
  right: 0.75rem;
  bottom: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.65;
}

/* --- Small screens --- */

@media (max-width: 480px) {
  body {
    padding: 1.25rem 0.75rem;
  }

  .coin {
    width: 4.25rem;
    height: 4.25rem;
  }

  .line {
    grid-template-columns: 1.1rem 1fr 1.1rem 5.8rem;
    gap: 0.4rem;
  }

  .line .value {
    font-size: 0.7rem;
  }

  .hexagram-card {
    padding: 1rem 1.25rem;
  }
}

/* --- Reduced motion --- */

@media (prefers-reduced-motion: reduce) {
  .coin-inner.flip-heads,
  .coin-inner.flip-tails,
  .line {
    animation-duration: 0.01s;
  }
}
