/* Post-battle presentation only. A real footer row keeps actions reachable;
   unusually short windows scroll the results, never the continuation controls. */
body:has(> #app > .result-scene) {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}
body:has(> #app > .result-scene) > #app {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
body > #app > .result-scene {
  --result-ink: #25382f;
  --result-gold: #a77c28;
  --result-max-size: clamp(132px, 25svh, 196px);
  height: 100%;
  min-height: 0;
  padding: clamp(12px, 2.5svh, 28px) max(16px, env(safe-area-inset-right)) clamp(12px, 2.5svh, 28px) max(16px, env(safe-area-inset-left));
  display: grid;
  place-items: center;
  color: var(--result-ink);
  background: linear-gradient(90deg, #f6efd9f5, #f6efd9eb 65%, #f6efd9c4), url('./assets/storybook/results-library.webp') center / cover no-repeat;
}
.result-card {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  width: min(100%, 1120px);
  max-height: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid #b89a59;
  border-radius: 12px;
  text-align: center;
  background: linear-gradient(130deg, #fffbef, #f8efd7);
  box-shadow: 0 4px 0 #9e783329, 0 12px 35px #55441e12;
}
.result-content {
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-color: #bba674 #f8efd7;
  padding: clamp(16px, 2.6svh, 28px) clamp(18px, 3vw, 38px) 16px;
}
.result-content:focus-visible { outline: 2px solid #52745a; outline-offset: -5px; }
.result-corner { position: absolute; width: 25px; height: 34px; color: #b18b3b; pointer-events: none; }
.result-corner .result-sprig { width: 100%; height: 100%; }
.result-corner-tl { top: 9px; left: 9px; transform: rotate(12deg); }
.result-corner-tr { top: 9px; right: 9px; transform: scaleX(-1) rotate(12deg); }
.result-corner-bl, .result-corner-br { display: none; }
.result-eyebrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 12px 12px;
  font: 700 11px/1.5 Arial, sans-serif;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #71684e;
}
.result-eyebrow > span[aria-hidden] { color: var(--result-gold); font: 23px/1 Georgia, serif; }
.result-eyebrow > span:last-child { transform: scaleX(-1); }
.result-hero {
  display: grid;
  grid-template-columns: var(--result-max-size) minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: clamp(14px, 3vw, 40px);
  max-width: 780px;
  margin: 0 auto 16px;
}
.result-max { grid-area: 1 / 1 / 3 / 2; align-self: center; position: relative; }
.result-max::after {
  content: '';
  position: absolute;
  bottom: 2%;
  left: 17%;
  width: 66%;
  height: 7%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #76501f25, transparent 70%);
}
.result-max-glow { position: absolute; inset: 10% -5% 0; background: radial-gradient(ellipse, #ecd8974d, transparent 70%); pointer-events: none; }
.result-max-sprite {
  position: relative;
  z-index: 1;
  width: var(--result-max-size);
  height: var(--result-max-size);
  background-image: url('./assets/max-instructions.webp');
  background-repeat: no-repeat;
  background-size: calc(var(--result-max-size) * 4) calc(var(--result-max-size) * 6);
  background-position: 0 calc(var(--result-max-size) * var(--result-max-row) * -1);
  animation: result-max-frames 1.8s steps(4) infinite;
}
@keyframes result-max-frames { to { background-position-x: calc(var(--result-max-size) * -4); } }
.result-intro { grid-area: 1 / 2; min-width: 0; }
.result-title, .result-retry .result-title {
  margin: 0;
  font: 700 clamp(42px, 8svh, 72px)/1.05 Georgia, 'Times New Roman', serif;
  letter-spacing: -2px;
  color: var(--result-ink);
}
/* The heading receives screen-reader focus on entry, without a giant box. */
.result-title:focus { outline: none; }
.result-subtitle { margin: 8px 0 5px; font: 700 clamp(19px, 2.5svh, 25px)/1.25 Georgia, serif; text-wrap: balance; }
.result-message { margin: 0 auto; max-width: 440px; color: #71684f; font: 14px/1.5 Arial, sans-serif; text-wrap: balance; }
.result-awards {
  grid-area: 2 / 2;
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}
.result-stars { display: flex; justify-content: center; align-items: center; gap: 7px; position: relative; z-index: 1; }
.result-star { display: block; width: clamp(40px, 7svh, 57px); aspect-ratio: 1; }
.result-star:nth-child(2) { width: clamp(48px, 8svh, 66px); }
.result-star svg { display: block; width: 100%; height: 100%; }
.result-star.is-earned { filter: drop-shadow(0 3px 2px #97671d20); animation: result-star-arrive .65s cubic-bezier(.2,.8,.3,1.3) both; animation-delay: calc(var(--star-order) * .13s + .1s); }
.result-star.is-empty { opacity: .72; }
@keyframes result-star-arrive { from { opacity: 0; transform: translateY(8px) scale(.75); } to { opacity: 1; transform: none; } }
.result-laurel { color: #84915a; width: 25px; height: 44px; flex: 0 1 25px; }
.result-laurel-left { transform: scaleX(-1) rotate(-18deg); }
.result-laurel-right { transform: rotate(-18deg); }
.result-spark { position: absolute; color: #b18530; pointer-events: none; font-size: 14px; animation: result-sparkle 2.6s ease-in-out 3; }
.result-spark-one { left: 20%; top: 3px; }
.result-spark-two { right: 14%; top: 28px; font-size: 11px; animation-delay: .4s; }
.result-spark-three { right: 29%; top: 0; font-size: 13px; animation-delay: .8s; }
@keyframes result-sparkle { 0%,100% { opacity: .45; } 50% { opacity: 1; } }
.result-unlock { margin: 0 0 14px; padding: 10px 14px; border: 1px solid #a3b07c; border-radius: 6px; background: #edf0db; color: #38523b; font-size: 13px; line-height: 1.5; }
.result-unlock strong { display: block; font: 700 18px/1.4 Georgia, serif; }
.result-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0; }
.result-metric {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 76px;
  padding: 12px;
  border: 1px solid #d3bc85;
  border-radius: 7px;
  background: #fff9e9;
  box-shadow: 0 3px 0 #9e783315;
}
.result-metric > dl { margin: 0; display: flex; flex-direction: column-reverse; min-width: 0; }
.result-metric-icon { flex: 0 0 38px; display: grid; place-items: center; width: 38px; height: 38px; color: #92702c; }
.result-metric-icon svg { width: 100%; height: 100%; }
.result-metric dd { margin: 0; font: 700 clamp(27px, 4svh, 36px)/1.1 Georgia, serif; font-variant-numeric: tabular-nums; white-space: nowrap; }
.result-metric dt { margin-top: 5px; font: 10px/1.4 Arial, sans-serif; letter-spacing: .8px; text-transform: uppercase; color: #756c55; }
.result-rule { display: none; }
.result-summary { margin: 14px 0 0; color: #756c55; font: 13px/1.5 Arial, sans-serif; text-wrap: balance; }
.result-actions {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 16px clamp(18px, 3vw, 38px) max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid #d6c39c;
  background: #f3ead2;
}
.result-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 46px;
  padding: 11px 18px;
  border: 1px solid #48604c;
  border-radius: 24px;
  cursor: pointer;
  font: 700 14px/1.3 Arial, sans-serif;
  color: var(--result-ink);
  background: #fff9e9;
  transition: background .15s, transform .15s;
}
.result-actions button:hover { background: #e8dfc3; }
.result-actions button:active { transform: translateY(1px); }
.result-actions button:focus-visible { outline: 3px solid #368271; outline-offset: 3px; }
.result-actions .result-next { color: #fff9e9; background: #25382f; border-color: #25382f; font-size: 16px; }
.result-actions .result-next:hover { background: #385743; }
.result-next > span { color: #ebbe56; }
.result-next > span:first-child:not(:last-child) { display: none; }
.result-shop svg { flex: 0 0 22px; width: 22px; height: 22px; }
.result-actions .result-levels { background: transparent; border-color: #b5a57e; }

/* Later sandbox CSS shares these classes. Keep both post-battle variants
   compact, including long achievement lists, without changing their data. */
.result-scene.sandbox-result .result-hero { grid-template-columns: var(--result-max-size) minmax(0, 1fr); grid-template-rows: auto; margin-bottom: 16px; }
.result-scene.sandbox-result .result-max { grid-area: 1 / 1; margin: 0; }
.result-scene.sandbox-result .result-intro { grid-area: 1 / 2; }
.result-scene.sandbox-result .result-title { font-size: clamp(35px, 6.5svh, 58px); letter-spacing: -1.5px; }
.result-scene.sandbox-result .sandbox-result-record { margin-top: 8px; }
.result-scene.sandbox-result .result-metric { min-height: 70px; }
.result-scene.sandbox-result .result-metric dd { font-size: clamp(25px, 3.5svh, 32px); }
.result-scene.sandbox-result .result-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.result-scene.sandbox-result .sandbox-new-achievements { margin: 14px 0 0; }

@media (max-width: 640px) {
  body > #app > .result-scene { --result-max-size: clamp(100px, 26vw, 148px); padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left)); }
  .result-card { border-radius: 9px; }
  .result-content { padding: 16px 14px 14px; scrollbar-gutter: auto; }
  .result-corner { width: 18px; height: 25px; }
  .result-eyebrow { margin: 0 8px 10px; font-size: 9px; letter-spacing: 1.3px; }
  .result-eyebrow > span[aria-hidden] { display: none; }
  .result-hero { grid-template-columns: var(--result-max-size) minmax(0, 1fr); gap: 0 10px; margin-bottom: 12px; }
  .result-intro { grid-area: 1 / 1 / 2 / 3; }
  .result-title, .result-retry .result-title { font-size: clamp(38px, 10vw, 52px); letter-spacing: -1.5px; }
  .result-subtitle { margin-top: 6px; font-size: 19px; }
  .result-message { font-size: 12px; max-width: 320px; }
  .result-max { grid-area: 2 / 1; margin-top: 5px; }
  .result-awards { grid-area: 2 / 2; margin: 0; gap: 4px; }
  .result-laurel, .result-spark { display: none; }
  .result-stars { gap: 3px; }
  .result-star { width: clamp(31px, 8vw, 48px); }
  .result-star:nth-child(2) { width: clamp(38px, 9.5vw, 57px); }
  .result-metrics { gap: 6px; }
  .result-metric { min-height: 66px; padding: 9px 4px; }
  .result-metric-icon { display: none; }
  .result-metric dd { font-size: 27px; }
  .result-metric dt { font-size: 9px; letter-spacing: .3px; }
  .result-summary { margin-top: 10px; font-size: 12px; }
  .result-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px 14px max(12px, env(safe-area-inset-bottom)); }
  .result-actions .result-next { grid-column: 1 / -1; }
  .result-actions button { min-height: 44px; padding: 9px 8px; font-size: 12px; }
  .result-actions .result-next { font-size: 15px; }
  .result-shop svg { display: none; }
  .result-scene.sandbox-result .result-hero { column-gap: 8px; }
  .result-scene.sandbox-result .result-title { font-size: clamp(28px, 7vw, 42px); }
  .result-scene.sandbox-result .result-subtitle { font-size: 17px; }
  .result-scene.sandbox-result .result-message { font-size: 12px; }
  .result-scene.sandbox-result .sandbox-result-label { font-size: 9px; margin-bottom: 5px; }
  .result-scene.sandbox-result .sandbox-result-record { font-size: 10px; padding: 4px 8px; }
  .result-scene.sandbox-result .result-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-scene.sandbox-result .result-next { grid-column: auto; }
}
/* Small landscape windows and high browser zoom must still leave room for
   the action row. Secondary actions remain reachable by horizontal scroll
   or keyboard, rather than being removed or covered. */
@media screen and (max-height: 520px) {
  body:has(> #app > .result-scene) > footer { display: none; }
}
@media screen and (max-height: 360px) {
  body:has(> #app > .result-scene) > .topbar {
    zoom: 1;
    height: 54px;
    min-height: 54px;
    padding: 4px 12px;
    flex-wrap: nowrap;
    gap: 8px;
  }
  body:has(> #app > .result-scene) > .topbar .brand { width: 138px; height: 46px; }
  body:has(> #app > .result-scene) > .topbar nav { display: none; }
  body:has(> #app > .result-scene) > .topbar .wallet { margin-left: auto; }
  body > #app > .result-scene { padding-block: 6px; }
  .result-scene .result-actions, .result-scene.sandbox-result .result-actions {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    overflow-x: auto;
  }
  .result-scene .result-actions button { flex: 0 0 auto; min-height: 44px; padding: 9px 14px; }
  .result-scene .result-actions .result-next { min-width: 140px; }
}
@media (prefers-reduced-motion: reduce) {
  .result-max-sprite, .result-star.is-earned, .result-spark { animation: none; }
  .result-victory .result-max-sprite { background-position-x: calc(var(--result-max-size) * -2); }
  .result-actions button { transition: none; }
  .result-actions button:hover, .result-actions button:active { transform: none; }
}
@media (forced-colors: active) {
  body > #app > .result-scene, .result-card, .result-actions { background: Canvas; color: CanvasText; }
  .result-card, .result-metric, .result-actions button { box-shadow: none; border-color: ButtonText; }
  .result-corner, .result-max-glow, .result-spark, .result-laurel { display: none; }
  .result-title, .result-message, .result-eyebrow, .result-metric dt, .result-summary { color: CanvasText; }
  .result-actions button, .result-actions .result-next { color: ButtonText; background: ButtonFace; }
  .result-max-sprite, .result-star, .result-metric-icon svg { forced-color-adjust: none; }
}
@media print {
  body:has(> #app > .result-scene) { display: block; height: auto; overflow: visible; }
  body:has(> #app > .result-scene) > #app, .result-content { overflow: visible; }
  body > #app > .result-scene { height: auto; background: white; padding: 10px; }
  .result-card { display: block; max-height: none; box-shadow: none; break-inside: avoid; }
  .result-max-sprite, .result-star.is-earned, .result-spark { animation: none; }
  .result-actions { display: none; }
}
