/* ============================================================
   Medieval Solutions — Rules page
   A stack of rule cards you scroll, swipe or tap through; each new
   card slaps down onto the stack (js/rules.js). Palette from theme.css,
   card faces match the game's cards (parchment, gold border).
   ============================================================ */

:root {
  --card-w: 320px;
  --card-h: 450px;
  --card-r: 12px;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-ui);
  background-color: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

/* Seven cards (six rules + finale): enough scroll for each to land. */
.container { height: 280vh; }

/* The page scrolls through the cards, so the way back stays pinned (at the
   same spot as on the title, where the pan lands it). */
.signpost { position: fixed; }

.scroll-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: var(--red); z-index: 100; transition: width 0.3s ease;
}

/* Language: a parchment tab hanging from the top edge (like the hall's "up" tab).
   Tapping it unrolls a strip of language seals underneath. */
.lang-tab { position: fixed; top: 0; left: 50%; translate: -50% 0; z-index: 200; display: flex; flex-direction: column; align-items: center; }
.lang-current {
  display: flex; align-items: center; gap: 8px; margin: 0; padding: 8px 14px 9px;
  font-family: var(--font-pixel); font-size: 1rem; color: var(--red); cursor: pointer;
  background: var(--parch); border: 2px solid var(--parch-brd); border-top: none; border-radius: 0 0 12px 12px;
  box-shadow: 0 3px 0 var(--tan); transition: translate .2s cubic-bezier(.3, 1.6, .5, 1), background .2s;
}
.lang-current:hover { background: var(--parch-2); translate: 0 3px; }
.lang-current .icon { width: 22px; height: 22px; image-rendering: pixelated; }
.lang-current .chev { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--red); transition: rotate .2s; }
.lang-current[aria-expanded="true"] .chev { rotate: 180deg; }
.lang-list {
  display: grid; grid-template-columns: repeat(3, auto); gap: 6px; margin-top: 8px; padding: 10px;
  background: var(--parch); border: 2px solid var(--parch-brd); border-radius: 14px; box-shadow: 0 4px 0 var(--tan);
  animation: lang-unroll .25s cubic-bezier(.3, 1.4, .5, 1) both; transform-origin: top center;
}
.lang-list[hidden] { display: none; }
.lang-list button {
  margin: 0; padding: 6px 12px; font-family: var(--font-ui); font-size: .95rem; color: var(--ink); cursor: pointer;
  background: #fff; border: 2px solid var(--tan); border-radius: 999px; transition: border-color .15s, scale .1s;
}
.lang-list button:hover { border-color: var(--red); }
.lang-list button:active { scale: .94; }
.lang-list button[aria-selected="true"] { border-color: var(--gold); background: var(--parch-2); box-shadow: 0 0 0 2px var(--gold); font-weight: bold; }
@keyframes lang-unroll { from { opacity: 0; transform: scaleY(.4); } }
@media (prefers-reduced-motion: reduce) { .lang-list { animation: none; } }

/* ── Rule cards: the game's card face, scaled up ── */
.rule-card {
  position: fixed; top: 50%; left: 50%;
  width: var(--card-w); height: var(--card-h);
  background: var(--card-bg);
  border: 3px solid var(--card-brd);
  border-radius: var(--card-r);
  box-shadow: 2px 3px 12px rgba(30, 14, 6, 0.28);
  padding: 12px;
  display: flex; flex-direction: column; align-items: center;
  opacity: 0; pointer-events: none; cursor: pointer;
  transition: opacity 0.4s ease, transform 0.4s ease, box-shadow 0.2s ease;
}
.rule-card::before {
  content: ''; position: absolute; inset: 8px;
  border: 1.5px solid color-mix(in srgb, var(--card-brd) 70%, transparent);
  border-radius: 7px; pointer-events: none;
}
.rule-card.active { opacity: 1; pointer-events: auto; }
.rule-card.active:hover { box-shadow: 4px 6px 20px rgba(30, 14, 6, 0.38); }

/* Resting places: each card lands a little lower and askew, like a real pile. */
.rule-card:nth-child(1) { transform: translate(-50%, -5%) rotate(-5deg); }
.rule-card:nth-child(2) { transform: translate(-50%, -5%) rotate(-2.5deg); }
.rule-card:nth-child(3) { transform: translate(-50%, -5%) rotate(2.5deg); }
.rule-card:nth-child(4) { transform: translate(-50%, -5%) rotate(5deg); }
.rule-card:nth-child(5) { transform: translate(-50%, -5%) rotate(7deg); }
.rule-card:nth-child(6) { transform: translate(-50%, -5%) rotate(-3deg); }
.rule-card:nth-child(7) { transform: translate(-50%, -5%) rotate(-3deg); }

.rule-card.active:nth-child(1) { transform: translate(-50%, -62%) rotate(-2deg); }
.rule-card.active:nth-child(2) { transform: translate(-50%, -56%) rotate(-1deg); }
.rule-card.active:nth-child(3) { transform: translate(-50%, -47%) rotate(1deg); }
.rule-card.active:nth-child(4) { transform: translate(-50%, -37%) rotate(2deg); }
.rule-card.active:nth-child(5) { transform: translate(-48%, -27%) rotate(-2deg); }
.rule-card.active:nth-child(6) { transform: translate(-48%, -20%) rotate(-4deg); }
.rule-card.active:nth-child(7) { transform: translate(-50%, -50%) rotate(0deg); }

.card-corner {
  position: absolute; font-family: var(--font-ui); font-weight: bold; font-size: 1.7rem;
  color: var(--red); line-height: 1;
}
.card-corner.top-left     { top: 16px; left: 18px; }
.card-corner.bottom-right { bottom: 16px; right: 18px; transform: rotate(180deg); }

.card-title {
  font-family: var(--font-display); font-weight: normal;
  font-size: 1.9rem; color: #000;
  margin: 10px 0 4px; text-align: center;
}

.card-text {
  font-size: 1.02rem; line-height: 1.45;
  margin: 6px 0; padding: 0 18px;
  text-align: left; width: 100%; min-height: 0;
}
.card-text:empty { display: none; }

.important-text { color: var(--red); font-size: 1.15em; font-weight: bold; }

.card-art {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 4px 0;
}

img.art-featured, img.art-small, img.art-corner, img.art-badge { object-fit: contain; }
img.art-featured { width: 112px; height: 112px; image-rendering: pixelated; }
img.art-small    { width: 64px; height: 64px; image-rendering: pixelated; opacity: .9; }
img.art-corner   { width: 56px; height: 56px; image-rendering: pixelated; }
img.art-corner.sm { width: 36px; height: 36px; }
img.art-card     { height: 108px; width: auto; border-radius: 6px; box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.25); }
img.art-card--sm { height: 88px; width: auto; border-radius: 6px; box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.25); }
/* A pixel icon pinned to the art: the Troubler's bolt, the lock-in seal. */
img.art-badge {
  position: absolute; width: 44px; height: 44px; image-rendering: pixelated;
  top: 50%; left: 50%; transform: translate(26px, -54px) rotate(12deg);
}

.card-pair { gap: 0; }
.card-pair > :first-child { transform: rotate(-8deg) translateX(12px); z-index: 1; }
.card-pair > :nth-child(2) { transform: rotate(8deg) translateX(-12px); z-index: 2; }

/* Presenting: the second card keeps turning over. */
.card-pair .flip-card { width: 63px; aspect-ratio: auto; height: 88px; perspective: 600px; }
.flip-card.turning .flip-inner { animation: turnOver 3.2s ease-in-out infinite; }
.mini-face { height: 100%; display: flex; align-items: center; justify-content: center; }
.mini-face img { width: 34px; image-rendering: pixelated; }
@keyframes turnOver {
  0%, 30% { transform: rotateY(0); }
  45%, 85% { transform: rotateY(180deg); }
  100% { transform: rotateY(360deg); }
}

/* Six-card fan (card 1) — edge cards sit lower, middle cards higher. */
.card-fan { position: relative; width: 178px; height: 108px; margin: 0 auto; overflow: visible; }
.fan-card {
  position: absolute; left: var(--left); top: var(--top);
  height: 72px; width: auto; border-radius: 4px;
  box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.35);
  transform: rotate(var(--rot)); z-index: var(--z);
}
.fan-label { position: absolute; left: 78px; top: 60px; font-family: var(--font-pixel); font-size: 1.2rem; color: var(--red); }

.card-hint {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  font-size: 0.9rem; color: var(--ink2); text-align: center; white-space: nowrap;
  animation: pulse 3s infinite; opacity: 0.75;
}

/* ── Finale ── */
.rule-card--finale { height: auto; min-height: var(--card-h); padding-bottom: 20px; justify-content: center; }
.rule-card--finale .card-hint { position: relative; bottom: auto; left: auto; transform: none; margin-top: 14px; animation: none; }
.rule-card--finale .finale-backdrop {
  position: fixed; top: -200vh; left: -200vw; width: 400vw; height: 400vh;
  background: var(--paper); z-index: 0; pointer-events: none;
}
.rule-card--finale > * { position: relative; z-index: 1; }
/* ms.gif is 500px native — wider than any phone. */
.finale-mascot { max-width: 100%; height: auto; image-rendering: pixelated; }
.finale-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 240px; margin: 16px 0 0; }
.finale-actions a { text-align: center; }

/* ── Slap: the newly arrived card drops onto the stack from above (rules.js adds
   .slap for one animation), and the cards underneath jolt from the impact.
   Uses the individual scale/translate properties so it composes with each
   card's resting transform instead of replacing it. ── */
.rule-card.slap { animation: slap .42s cubic-bezier(.5, 0, .75, 0) both, slapSettle .25s .42s ease-out both; }
.rule-card.jolt { animation: jolt .3s .38s ease-out; }

@keyframes slap {
  from { scale: 1.45; translate: 0 -40px; opacity: 0; box-shadow: 14px 22px 30px rgba(0, 0, 0, .25); }
  to   { scale: 1;    translate: 0 0;     opacity: 1; box-shadow: 2px 3px 12px rgba(30, 14, 6, .28); }
}
@keyframes slapSettle { 0% { scale: 1; } 40% { scale: 0.985 1.01; } 100% { scale: 1; } }
@keyframes jolt { 0%, 100% { translate: 0 0; } 30% { translate: -3px 4px; } 60% { translate: 2px -1px; } }
@keyframes pulse {
  0%, 100% { opacity: 0.75; transform: translateX(-50%) scale(1); }
  50%      { opacity: 1;    transform: translateX(-50%) scale(1.08); }
}

/* The bold words ripple gently every few seconds rather than wiggling nonstop (js/rules.js sets --d per letter). */
.important-text span { display: inline-block; animation: word-ripple 3.4s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes word-ripple { 0%, 34%, 100% { transform: translateY(0); } 10% { transform: translateY(-4%); } 22% { transform: translateY(2%); } }

@media (prefers-reduced-motion: reduce) {
  .card-hint, .flip-card.turning .flip-inner, .important-text span { animation: none !important; }
  .rule-card, .scroll-bar { transition: none !important; }
  .rule-card.slap, .rule-card.jolt { animation: none !important; }
}

@media (max-width: 430px) and (min-width: 351px) {
  :root { --card-w: 296px; --card-h: 416px; }
}

@media (max-width: 350px), (max-height: 600px) {
  :root { --card-w: 260px; --card-h: 380px; }
  .card-title  { font-size: 1.5rem; }
  .card-text   { font-size: 0.86rem; padding: 0 12px; }
  .card-hint   { font-size: 0.7rem; bottom: 14px; }
  .card-corner { font-size: 1.3rem; }
  img.art-featured { width: 80px; height: 80px; }
  img.art-corner   { width: 40px; height: 40px; }
  img.art-card     { height: 76px; }
  img.art-card--sm { height: 62px; }
  .card-pair .flip-card { width: 44px; height: 62px; }
  .card-fan { transform: scale(0.72); transform-origin: center top; margin-bottom: -30px; }
}
