/* Board navigation belongs between the intention panel and the board itself. */
.board > .map-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: calc(100% - 48px);
  max-width: 1100px;
  margin: 0 auto 24px;
  padding: 6px;
  gap: 6px;
  border-radius: 16px;
}
.board > .map-controls button { min-height: 48px; font-size: 14px; text-align: center; }
.board > .map-controls .selected { border-radius: 10px; }
.route-lines > path { marker-end: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; stroke-opacity: .7; }
.game-actions:has(#requestBox:not([hidden])) { margin-bottom: 18px; }
.rules-grid { align-items: stretch; }
.rules-grid > .panel { min-width: 0; }

/* An opacity layer produces a continuous hover, including the return transition. */
.overview-round { isolation: isolate; }
.all-rounds .overview-round::before,
.all-rounds .overview-round + .overview-round::before {
  content: '';
  position: absolute;
  inset: 4%;
  left: 4%;
  top: 4%;
  transform: none;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, transparent 54%, color-mix(in srgb, var(--round-color) 19%, transparent) 63%, transparent 74%);
  opacity: 0;
  transition: opacity 420ms ease;
  pointer-events: none;
  z-index: -1;
}
.all-rounds .overview-round:hover { background: transparent; }
.all-rounds .overview-round.current-round { background: radial-gradient(circle,color-mix(in srgb,var(--round-color) 8%,transparent),transparent 72%); }
.all-rounds .overview-round .journey-ring { filter: drop-shadow(0 0 0 transparent); transition: filter 420ms ease; }
.ring-cell > .sector-shape { filter: drop-shadow(0 0 0 transparent); transition: fill 300ms ease, stroke 300ms ease, filter 420ms ease; }
@media (hover: hover) and (pointer: fine) {
  .all-rounds .overview-round:hover::before { opacity: 1; }
  .all-rounds .overview-round:hover .journey-ring { filter: drop-shadow(0 0 12px color-mix(in srgb,var(--round-color) 22%,transparent)); }
}
.all-rounds .overview-round:focus-within::before { opacity: 1; }

/* The main action keeps one painted surface and one position during hover. */
.game-actions #play,
.game-actions #play:hover,
.game-actions #play:active {
  opacity: 1;
  visibility: visible;
  transform: none;
  background: linear-gradient(110deg, #e4be7f, #efd3a0);
  transition: box-shadow 260ms ease, border-color 260ms ease;
  backface-visibility: hidden;
}
.game-actions #play:not(:disabled):hover { box-shadow: 0 0 0 1px #f7d9a288, 0 0 28px #e9bd7540, inset 0 1px 0 #fff5d499; }

.nav-pawn { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: radial-gradient(circle at 35% 30%,#fbffe6,#dbeaab 50%,#a3bd70); box-shadow: 0 0 9px #d5f5a640; vertical-align: -3px; }
.nav .nav-pawn { color: #435334; margin-left: 5px; }
.nav-pawn i { font: 12px/1 Georgia,serif; font-style: normal; }

/* Six stages have six base colours; the deck still controls its own emblem. */
.ritual-screen[data-stage="0"] { --oracle-deep:#241733; --stage-wash:#6c4499a6; --oracle-reading:#171326f2; }
.ritual-screen[data-stage="1"] { --oracle-deep:#1d2742; --stage-wash:#4b5f9fa6; --oracle-reading:#141d32f2; }
.ritual-screen[data-stage="2"] { --oracle-deep:#361c2d; --stage-wash:#974666a6; --oracle-reading:#291321f2; }
.ritual-screen[data-stage="3"] { --oracle-deep:#102d42; --stage-wash:#327fa4a6; --oracle-reading:#0e2233f2; }
.ritual-screen[data-stage="4"] { --oracle-deep:#113b32; --stage-wash:#36917ca6; --oracle-reading:#102c26f2; }
.ritual-screen[data-stage="5"] { --oracle-deep:#3b2c1c; --stage-wash:#ad7c38a6; --oracle-reading:#2d2117f2; }
.ritual-screen .oracle-card::after {
  background:
    linear-gradient(165deg, var(--stage-wash, var(--oracle-wash)), transparent 72%),
    radial-gradient(ellipse 68% 60% at 50% 57%, var(--oracle-reading, #0a1222ed) 0%, var(--oracle-reading, #0a1222ed) 45%, transparent 85%),
    url('assets/oracle-silk.webp') center / cover no-repeat;
}
.oracle-copy {
  padding: 20px 14px;
  margin: 0 -3px;
  background: radial-gradient(ellipse closest-side at center,var(--oracle-reading,#0c1425f2) 0%,var(--oracle-reading,#0c1425f2) 72%,transparent 100%);
}
.ritual-screen .oracle-copy h2 { text-shadow: none; max-width: 16ch; font-size: 32px; }
.oracle-copy .ritual-message { text-shadow: none; color: #f5f0e7; max-width: 31ch; line-height: 1.85; overflow-wrap: anywhere; }
.oracle-card .oracle-sigil { margin-bottom: 16px; }
.oracle-card .oracle-horizon { margin-top: 16px; }

.journal-entry-tools { display: flex; justify-content: flex-end; border-top: 1px solid #bca47526; margin-top: 18px; padding-top: 8px; }
.journal-entry-tools .entry-delete { color: #d9b7b4; min-height: 44px; }
.journal-entry-tools .entry-delete:hover { color: #ffe0dc; background: #d28c8c0f; }
.journal-undo { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; margin-top: 20px; padding: 18px 22px; border: 1px solid #c3ae7545; border-radius: 14px; background: #172936; color: #e7ddc7; }

/* A shallow, perspective-lit stage behind the die and the deck. */
.roll-prompt, .dice-ritual, .roll-result, .stage-result, .deck-ritual {
  position: relative;
  isolation: isolate;
  perspective: 900px;
}
.roll-prompt, .roll-result, .stage-result { padding: 26px 4px 8px; }
.dice-ritual { min-height: 280px; }
.roll-prompt::before, .dice-ritual::before, .roll-result::before, .stage-result::before, .deck-ritual::before {
  content: '';
  position: absolute;
  width: min(340px,90%);
  height: 260px;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse,#d2b87520,transparent 65%),radial-gradient(ellipse at 25% 45%,#6987c52b,transparent 62%);
  z-index: -1;
  pointer-events: none;
}
.roll-prompt::after, .dice-ritual::after, .roll-result::after, .stage-result::after, .deck-ritual::after {
  content: '';
  position: absolute;
  width: min(285px,82%);
  height: 150px;
  left: 50%;
  top: 75px;
  border: 1px solid #e0c08840;
  border-top-color: #e0c08890;
  border-bottom-color: #83b8c145;
  border-radius: 50%;
  transform: translateX(-50%) rotateX(58deg) rotateZ(-15deg);
  z-index: -1;
  pointer-events: none;
}
.deck-ritual::before { height: 340px; background: radial-gradient(ellipse,color-mix(in srgb,var(--deck-color) 14%,transparent),transparent 67%),radial-gradient(ellipse at 15% 50%,#6987c52b,transparent 60%); }
.deck-ritual::after { top: 145px; }
.roll-result .die-wrap, .stage-result .die-wrap { position: relative; z-index: 1; }

.deck-ritual .deck-stack {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 850px;
  transform-style: preserve-3d;
  border-radius: 16px;
}
.deck-ritual .deck-stack > span { transition: transform 340ms ease, box-shadow 340ms ease; backface-visibility: hidden; }
.deck-stack:focus-visible { outline: 2px solid #efd49d; outline-offset: 14px; }
.deck-stack:disabled { opacity: 1; cursor: wait; }
.deck-ritual .deck-stack.drawing { transform: rotateX(5deg); }
.deck-ritual .deck-stack > .drawn-back {
  display: block;
  overflow: visible;
  background: none;
  border: 0;
  box-shadow: none;
  z-index: 10;
  transform-style: preserve-3d;
  backface-visibility: visible;
  animation: draw-card-3d 1200ms cubic-bezier(.22,.7,.2,1) both;
}
.drawn-back .drawn-face {
  position: absolute;
  inset: 0;
  border: 1px solid #e9cc8b;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  backface-visibility: hidden;
  background: linear-gradient(135deg,#20374b,#231d38);
  box-shadow: 0 14px 32px #0007;
  color: #ebd099;
}
.drawn-face.drawn-reverse { font-size: 48px; }
.drawn-face.drawn-front { transform: rotateY(180deg); background: linear-gradient(140deg,#193947,#2e2446); }
.drawn-front svg { width: 65px; height: 65px; fill: none; stroke: #e9cc8b; stroke-width: 1.4; }
.drawn-front b { font: 400 18px/1.3 Georgia,serif; }

.pawn-trail { position: absolute; inset: 0; z-index: 5; pointer-events: none; overflow: visible; }
.pawn-trail i { position: absolute; width: var(--trail-size,4px); height: var(--trail-size,4px); border-radius: 50%; background: #f1e1b3; box-shadow: 0 0 7px #e8f4a9aa,0 0 15px #e0d1a775; opacity: 0; transform: translate(-50%,-50%); animation: trail-fade 650ms ease-out var(--trail-delay,0ms) both; }

@media (hover:hover) and (pointer:fine) {
  .deck-ritual .deck-stack:not(:disabled):hover > span:first-child { transform: translate3d(0,-10px,20px) rotateZ(-6deg) rotateY(-10deg); box-shadow: 0 22px 45px #0006,0 0 24px color-mix(in srgb,var(--deck-color) 20%,transparent); }
  .deck-ritual .deck-stack:not(:disabled):hover > span:nth-child(2) { transform: rotateZ(7deg) translateZ(-3px); }
  .deck-ritual .deck-stack:not(:disabled):hover > span:nth-child(3) { transform: rotateZ(17deg) translateZ(-6px); }
}
@media (prefers-reduced-motion:no-preference) {
  .roll-prompt::before, .dice-ritual::before, .roll-result::before, .stage-result::before, .deck-ritual::before { animation: cosmic-breathe 4s ease-in-out infinite alternate; }
  .roll-prompt::after, .dice-ritual::after, .roll-result::after, .stage-result::after, .deck-ritual::after { animation: cosmic-orbit 7s ease-in-out infinite alternate; }
}
@keyframes cosmic-breathe { from { opacity:.4; transform:translateX(-50%) scale(.9); } to { opacity:1; transform:translateX(-50%) scale(1.08); } }
@keyframes cosmic-orbit { from { opacity:.3; transform:translateX(-50%) rotateX(58deg) rotateZ(-15deg); } to { opacity:.9; transform:translateX(-50%) rotateX(68deg) rotateZ(18deg); } }
@keyframes trail-fade { 0% {opacity:0;transform:translate(-50%,-50%) scale(.3)} 12% {opacity:.8;transform:translate(-50%,-50%) scale(1)} 100% {opacity:0;transform:translate(-50%,-50%) scale(.1)} }
@keyframes draw-card-3d { 0% {opacity:1;transform:translate3d(0,0,2px) rotateZ(-8deg) rotateY(0)} 35% {opacity:1;transform:translate3d(0,-75px,65px) rotateZ(1deg) rotateY(15deg)} 78% {opacity:1;transform:translate3d(0,-105px,110px) rotateZ(0) rotateY(180deg) scale(1.14)} 100% {opacity:0;transform:translate3d(0,-100px,135px) rotateZ(0) rotateY(180deg) scale(1.2)} }
@media (max-width:760px) {
  .board > .map-controls { width:calc(100% - 24px); max-width:none; margin:0 auto 20px; }
  .board > .map-controls button { font-size:13px; padding:10px 8px; }
  .ritual-screen .oracle-card { padding-left:25px; padding-right:25px; }
  .ritual-screen .oracle-copy h2 { font-size:29px; }
  .oracle-copy { padding:18px 10px; margin:0 -2px; }
  .oracle-copy .ritual-message { font-size:16px; line-height:1.85; }
  .journal-undo { padding:16px; }
}
@media (prefers-reduced-motion:reduce) {
  .pawn-trail { display:none; }
  .deck-ritual .deck-stack:not(:disabled):hover > span:first-child { transform:rotate(-8deg); }
}


@media (max-width:760px) { .ritual-screen .oracle-display { padding-left:2px; padding-right:2px; } }
/* Face geometry is independent of the fanned stack's descendant span rules. */
.deck-ritual .deck-stack .drawn-face { width:100%; height:100%; left:0; top:0; padding:10px; transform:none; z-index:auto; }
.deck-ritual .deck-stack .drawn-face.drawn-front { transform:rotateY(180deg); }

/* Equal-sized final actions, with a single baseline and consistent spacing. */
.result-screen .result-actions:has(> #saveResult) {
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  align-items:stretch;
  gap:12px;
}
.result-screen .result-actions:has(> #saveResult) > button {
  display:flex;
  align-items:center;
  justify-content:center;
  align-self:stretch;
  width:100%;
  min-width:0;
  min-height:68px;
  height:100%;
  margin:0;
  padding:16px 14px;
  border-radius:12px;
  flex:none;
  font-size:15px;
  line-height:1.45;
  text-align:center;
  text-wrap:balance;
}
@media(max-width:600px) {
  .result-screen .result-actions:has(> #saveResult) { grid-template-columns:minmax(0,1fr); gap:10px; }
  .result-screen .result-actions:has(> #saveResult) > button { min-height:60px; }
}
