.chapter-premise { color: var(--muted); max-width: 54ch; }
#game-shell[data-adapter="canvas"] {
  --game-text: #f9e8d1;
  background: #201d1b;
  border-color: #705540;
}
#game-surface { aspect-ratio: 2; background: #946445; }
.ravine-frame { display: grid; gap: .35rem; min-width: 0; width: 100%; }
.ravine-arena { position: relative; min-width: 0; }
.player-hud {
  display: grid;
  grid-template-columns: repeat(3, auto) minmax(0, 1fr);
  align-items: start;
  gap: .2rem .9rem;
  padding: .25rem .65rem;
}
.player-hud .stat { min-width: 0; gap: .15rem; }
.player-hud .stat strong { font-size: clamp(.94rem, 2.4vw, 1.25rem); letter-spacing: .025em; }
.player-hud .stat span { font-size: .66rem; }
#hearts { white-space: nowrap; letter-spacing: .095em; }
#hearts span { font-size: inherit; opacity: 1; }
.heart-fill { color: #ff9e85 !important; }
.heart-empty { color: #9f9286 !important; }
#armor-protection { color: #c2e4b9; font-size: .7rem; white-space: nowrap; }
.tonic-supplies { display: flex; align-items: center; gap: .15rem .65rem; flex-wrap: wrap; }
#use-tonic { color: #ffe0a4; border: 1px solid #a47550; background: #3b2b22; border-radius: 4px; padding: .17em .42em; font: inherit; font-size: .72rem; font-weight: 650; cursor: pointer; }
#use-tonic:disabled { opacity: .68; cursor: default; }
#use-tonic kbd { padding-inline: .23em; border: 1px solid #997554; border-radius: 3px; }
.touch-device #use-tonic { display: none; }
.boss-hud { grid-column: 1 / -1; display: flex; align-items: center; gap: .65rem; color: #f7d6ae; font-size: .78rem; }
.boss-hud progress { flex: 1; min-width: 0; accent-color: #e98c5f; height: .75rem; }
.rematch-clock { min-width: 5.5ch; text-align: right; font-variant-numeric: tabular-nums; }
.ranked-clock { white-space: nowrap; font-variant-numeric: tabular-nums; }
.ranked-play-notice { grid-column: 1 / -1; margin: 0; color: #f7d6ae; font-size: .78rem; }
.rematch-unlock {
  position: absolute;
  inset: .65rem auto auto 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 1.4rem);
  margin: 0;
  color: #ffe0a6;
  font-size: clamp(.72rem, 2vw, .88rem);
  text-align: center;
  pointer-events: none;
}
.rematch-unlock:not(:empty) {
  padding: .38rem .7rem;
  border: 1px solid #d19964;
  border-radius: .4rem;
  background: #241a16;
}
#rematches { background: #241f1c; border-color: #705540; color: #fff2df; }
#rematches h2 { font: 500 1.7rem/1.15 Georgia, serif; }
#rematches > p { color: #e0c7ad; }
#rematch-boss {
  display: block; width: 100%; min-height: 44px; margin-top: .4rem; padding: .6rem .75rem;
  border: 1px solid #8e6b49; border-radius: .5rem; background: #332923; color: #fff2df; font: inherit;
}
#rematch-best { color: #f3cc9f; }
[data-mode="rematch"] .campaign-key { display: none; }
.game-menu { background: linear-gradient(115deg, #171b1ae8, #251713cf); border-radius: 12px; }
.game-menu h2 { font-family: Georgia, serif; font-size: clamp(1.65rem, 4vw, 3.3rem); line-height: .98; }
.game-menu p { max-width: min(44ch, 88vw); text-align: center; }
.game-menu a { color: #ffc392; font-size: .81rem; }
.game-menu[data-failure]:not([data-failure=""]) {
  justify-items: center;
  background: radial-gradient(ellipse at 50% 35%, var(--loss-halo), #151819ee 64%, #101316f7);
  animation: reveal-story .35s ease-out;
}
.game-menu[data-failure="cliff"] { --loss-halo: #714c37d9; --loss-art: url("art/WindGorgeVista.png"); --loss-light: #e9bb87; }
.game-menu[data-failure="water"] { --loss-halo: #255966d9; --loss-art: url("art/ReedwaterVista.png"); --loss-light: #9dd6dc; }
.game-menu[data-failure="combat"] { --loss-halo: #723d36d9; --loss-art: url("art/ScorcherSanctuary.png"); --loss-light: #f2a084; }
.game-menu[data-failure="hazard"] { --loss-halo: #774616d9; --loss-art: url("art/BronzeFoundryVista.png"); --loss-light: #f4c174; }
.game-menu[data-failure]:not([data-failure=""]) h2 { max-width: 90%; font-size: clamp(1.15rem, 4vw, 3.05rem); }
.failure-art {
  position: relative; overflow: hidden; width: clamp(130px, 33vw, 300px); height: clamp(34px, 11vw, 126px);
  background: linear-gradient(0deg, #151820aa, #17141a15 75%, #15182055), var(--loss-art) center 56% / cover;
  border: 1px solid var(--loss-light); border-radius: 5px 5px 38% 38% / 5px 5px 15% 15%;
  box-shadow: 0 9px 28px #0a0c128c, inset 0 0 18px #15151b88; isolation: isolate;
}
.failure-art i { position: absolute; display: block; top: 46%; left: 50%; }
.failure-art i:nth-child(2) { --offset: -.95rem; --delay: .13s; }
.failure-art i:nth-child(3) { --offset: 1.1rem; --delay: .27s; }
[data-failure="cliff"] .failure-art i {
  width: 1rem; height: .82rem; margin-left: var(--offset, 0); background: linear-gradient(145deg, var(--loss-light), #483b35);
  clip-path: polygon(15% 22%, 56% 0, 100% 38%, 85% 78%, 54% 100%, 0 63%); animation: failure-fall .85s ease-in var(--delay, 0s) both;
}
[data-failure="water"] .failure-art i {
  width: 55%; height: 38%; left: 23%; border: 1.5px solid var(--loss-light); border-radius: 50%;
  box-shadow: 0 0 .65rem #9dd6dc9e; animation: failure-ripple 1.3s ease-out var(--delay, 0s) both;
}
[data-failure="combat"] .failure-art i {
  width: 14%; height: 6%; margin-left: var(--offset, 0); background: linear-gradient(90deg, #d3a276, #f9ddab);
  clip-path: polygon(0 38%, 72% 38%, 72% 0, 100% 50%, 72% 100%, 72% 64%, 0 64%);
  animation: failure-arrows .65s ease-out var(--delay, 0s) both;
}
[data-failure="hazard"] .failure-art i {
  width: .29rem; height: .29rem; margin-left: var(--offset, 0); border-radius: 50%; background: #fff6c2;
  box-shadow: 0 0 .9rem .2rem #e8833b; animation: failure-embers 1.25s ease-out var(--delay, 0s) both;
}
@keyframes failure-fall { from { transform: translate(-23px, -80px) rotate(-35deg); } to { opacity: .42; transform: translate(14px, 26px) rotate(140deg); } }
@keyframes failure-ripple { from { opacity: 1; transform: scale(.13); } to { opacity: .42; transform: scale(1.2); } }
@keyframes failure-arrows { from { opacity: 0; transform: translate(-95px, 30px) rotate(-28deg); } to { opacity: .8; transform: translate(-24px, -5px) rotate(-28deg); } }
@keyframes failure-embers { from { opacity: 1; transform: translateY(40px); } to { opacity: .48; transform: translateY(-20px); } }
@media (prefers-reduced-motion: reduce) { .game-menu[data-failure]:not([data-failure=""]), .failure-art i { animation: none !important; } }
.game-menu[data-ending="village"] {
  inset: 0 0 0 auto;
  width: min(48%, 24rem);
  grid-template-columns: minmax(0, 1fr);
  align-content: safe center;
  justify-items: center;
  gap: clamp(4px, 1vw, 12px);
  padding: clamp(7px, 1.6vw, 24px);
  border: 1px solid #b696644d;
  border-radius: 0 12px 12px 0;
  background: linear-gradient(110deg, #252c21f0, #25231af7);
  animation: reveal-story .45s ease-out;
}
.game-menu[data-ending="village"] h2 { font-size: clamp(1.02rem, 3.3vw, 2.75rem); line-height: 1.06; }
.game-menu[data-ending="village"] p { font-size: clamp(.67rem, 1.35vw, .98rem); line-height: 1.3; }
.game-menu[data-ending="village"] button { max-width: 100%; }
.rematch-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.story-card { position: absolute; inset: 0; display: flex; align-items: start; overflow: auto; border-radius: 12px; background: linear-gradient(0deg, #10201ee8 10%, #101a19a0 63%, #15221e1f); }
.story-card:not([hidden]) { animation: reveal-story .18s ease-out; }
.story-card[data-beat="oneSun"] { background: linear-gradient(0deg, #211520f5 8%, #22181d88 36%, transparent 68%); }
@keyframes reveal-story { from { opacity: .3; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .story-card:not([hidden]) { animation: none; } }
.story-copy { margin: auto 0 0; width: min(100%, 650px); padding: clamp(9px, 3vw, 37px); color: #fff2df; text-shadow: 0 1px 3px #111; }
.story-copy h2 { margin: .18em 0; font: 500 clamp(1.17rem, 3.4vw, 2.7rem)/1.1 Georgia, serif; }
.story-copy p { margin: 0 0 .45em; font-size: clamp(.73rem, 1.55vw, 1rem); line-height: 1.34; }
#story-chapter { color: #ffd3a2; font-weight: 700; }
.story-copy button { margin-top: .25em; text-shadow: none; }
.story-card[data-beat="homecoming"] { background: linear-gradient(180deg, #192720e8, #17231eb3 20%, transparent 56%); }
.story-card[data-beat="homecoming"] .story-copy { margin: 0 auto; padding: clamp(9px, 2vw, 24px); }
.story-card[data-passive="true"] { pointer-events: none; bottom: auto; background: none; overflow: visible; padding: 8px; }
.story-card[data-passive="true"] .story-copy { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 9px; margin: 0 auto; width: min(100%, 620px); padding: 7px 11px 8px; background: #172522e8; border-radius: 7px; }
.story-card[data-passive="true"] #story-chapter { grid-column: 1; margin: 0; font-size: clamp(.65rem, 1.3vw, .81rem); }
.story-card[data-passive="true"] h2 { grid-column: 1; margin: .12em 0 .23em; font-size: clamp(.84rem, 1.7vw, 1.22rem); }
.story-card[data-passive="true"] #story-lines { grid-column: 1 / -1; margin: 0; font-size: clamp(.68rem, 1.3vw, .88rem); line-height: 1.31; }
.story-card[data-passive="true"] button { grid-column: 2; grid-row: 1 / 3; align-self: start; pointer-events: auto; min-height: 32px; margin: 0; padding: 3px 9px; font-size: .72rem; }
.opening-visual { display: none; }
.story-card[data-beat="opening"] {
  background: linear-gradient(90deg, transparent 40%, #28201696 68%, #21160de6);
  opacity: var(--opening-opacity, 1);
}
.story-card[data-beat="opening"] .opening-visual {
  display: block;
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  background: #39251a;
  opacity: var(--opening-art-opacity, 1);
}
.opening-visual::before, .opening-visual::after { content: ""; position: absolute; inset: 0; }
.opening-visual::before {
  background: url("art/Playfield.png") center 60% / cover;
  transform-origin: 66% 67%;
  transform: translateX(var(--opening-drift, 3%)) scale(var(--opening-zoom, 1.09));
}
.opening-visual::after {
  background:
    linear-gradient(90deg, transparent 48%, #211810ef),
    linear-gradient(0deg, #211810ad, #2118101a 54%, #4c241825),
    radial-gradient(circle at 24% 25%, #fff4c2 0 .55%, #ffc07185 1.25%, transparent 4%),
    radial-gradient(circle at 30% 13%, #fff4c2 0 .65%, #ffc07185 1.45%, transparent 4%),
    radial-gradient(circle at 36% 29%, #fff4c2 0 .67%, #ffc07185 1.45%, transparent 4%),
    radial-gradient(circle at 42% 18%, #fff4c2 0 .65%, #ffc07185 1.45%, transparent 4%),
    radial-gradient(circle at 48% 30%, #fff4c2 0 1%, #ffc07185 2.5%, transparent 7%),
    radial-gradient(circle at 54% 11%, #fff4c2 0 .7%, #ffc07185 1.4%, transparent 4%),
    radial-gradient(circle at 60% 24%, #fff4c2 0 .75%, #ffc07185 1.7%, transparent 4%),
    radial-gradient(circle at 66% 15%, #fff4c2 0 .6%, #ffc07185 1.4%, transparent 4%),
    radial-gradient(circle at 72% 28%, #fff4c2 0 .65%, #ffc07185 1.5%, transparent 4%),
    radial-gradient(circle at 78% 19%, #fff4c2 0 .58%, #ffc07185 1.4%, transparent 4%);
}
.story-card[data-beat="opening"] .story-copy {
  z-index: 1;
  width: min(55%, 470px);
  margin: auto 0 0 auto;
  padding: clamp(8px, 2.5vw, 32px);
}
.ravine-arena:has(.story-card[data-beat="opening"]:not([hidden])) #game-surface canvas {
  transform-origin: left 75.625%;
  transform: scale(var(--opening-well-zoom, 1));
}
.story-card[data-beat="opening"] #story-continue {
  position: absolute;
  top: clamp(5px, 1.15vw, 14px);
  right: clamp(5px, 1.15vw, 14px);
  margin: 0;
  border: 1px solid #e2bf96;
  background: #281d17e6;
  color: #fff2df;
  padding: .38rem .66rem;
  font-size: .76rem;
}
@media (prefers-reduced-motion: reduce) {
  .opening-visual::before,
  .ravine-arena:has(.story-card[data-beat="opening"]:not([hidden])) #game-surface canvas { transform: none; }
  .story-card[data-beat="opening"][data-shot="well"] .opening-visual { opacity: 0; }
  .story-card[data-beat="opening"] { opacity: 1; }
}
.gear-art.item-art { background-repeat: no-repeat; background-position: center; background-size: contain; }
@media (max-width: 520px) { .story-copy button { min-height: 36px; padding: 5px 12px; } }
#account-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: .5rem 1rem; }
#title-profile-notice:empty { display: none; }
.ravine-footer { display: grid; gap: .38rem; }
.ravine-footer .player-controls { margin-inline: auto; justify-content: center; }
.player-status { flex-wrap: wrap; justify-content: center; gap: .35rem .8rem; font-size: .8rem; color: #f8e6d0; text-align: center; }
#keyboard-guide { flex-basis: 100%; color: #cfbcaa; font-size: .72rem; }
#view-notice:empty { display: none; }
#ravine-menu { width: min(600px, calc(100% - 20px)); padding: clamp(12px, 3vw, 24px); }
#ravine-menu h2, #gear-controls { margin-top: 0; }
#menu-content { max-height: min(57dvh, 520px); overflow-y: auto; padding: .1rem .45rem .15rem .15rem; }
.gear-section { margin: .95rem 0 .35rem; color: #d4b394; font-size: .74rem; letter-spacing: .085em; text-transform: uppercase; }
.gear-section:first-child { margin-top: .1rem; }
.gear-row { --gear-art-size: clamp(42px, 10vw, 66px); display: grid; grid-template-columns: var(--gear-art-size) minmax(0, 1fr) auto; align-items: center; gap: .5rem; border: 1px solid #715846; border-radius: 9px; padding: .4rem; margin-bottom: .4rem; background: #302720; }
.gear-row p { margin: .15rem 0 0; font-size: .8rem; line-height: 1.4; }
.gear-row button { white-space: nowrap; padding-inline: clamp(.35rem, 2vw, .75rem); }
.gear-row:focus-within { border-color: #dbb683; background: #493624; }
.gear-art { width: var(--gear-art-size); height: var(--gear-art-size); border: 1px dashed #755a46; border-radius: 6px; background-color: #201c19; }
.gear-art.has-art { border-style: solid; background-image: url("art/RavineGear.png"); background-size: 300% 300%; background-repeat: no-repeat; }
.gear-row button[aria-disabled="true"] { opacity: .65; cursor: default; }
.touch-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem; width: min(100%, 23rem); }
.touch-actions button { min-height: 44px; padding: .38rem .3rem; touch-action: none; }
.touch-actions [data-touch="charge"] small { display: block; font-size: .67rem; line-height: 1.1; }
.touch-actions [data-touch="charge"][data-aim-up] { outline: 2px solid #ffe3a4; outline-offset: -3px; }
.is-playing #game-shell[data-adapter="canvas"] { grid-template-rows: minmax(0,1fr) auto; gap: .55rem; }
.is-playing.touch-device #game-shell[data-adapter="canvas"] { grid-template-rows: minmax(0,1fr) auto auto; }
.is-playing #game-shell[data-adapter="canvas"] .play-area {
  align-self: stretch;
  justify-self: stretch;
  width: 100%;
  display: grid;
  place-items: center;
  container-type: size;
}
.is-playing .ravine-frame { width: min(100%, max(0px, calc(200cqh - 184px))); }
.is-playing.touch-device #keyboard-guide { display: none; }
@media (max-width: 600px) {
  .player-hud .player-controls { gap: .3rem; }
  .player-hud .player-controls button { padding: .3rem .46rem; font-size: .73rem; }
}
@media (max-height: 460px) {
  .is-playing #game-shell[data-adapter="canvas"] { padding-block: .3rem; gap: .3rem; }
  .player-hud { gap: .2rem .6rem; padding: .12rem .2rem; }
  .player-hud .stat strong { font-size: .82rem; }
  .player-hud .stat span { font-size: .55rem; }
  .is-playing .ravine-frame { width: min(100%, max(0px, calc(200cqh - 154px))); }
  .player-status { font-size: .74rem; }
  .game-menu { gap: .33rem; }
  .game-menu p { font-size: .69rem; }
}
@media (orientation: landscape) and (max-height: 460px) {
  .is-playing .ravine-frame {
    width: 100%; height: 100%;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .is-playing .ravine-viewport { display: grid; place-items: center; container-type: size; }
  .is-playing .ravine-arena { width: min(100cqw, 200cqh); }
  .is-playing .game-menu { align-content: safe center; }
  .is-playing.touch-device #game-shell[data-adapter="canvas"]:not([data-state="running"]) {
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .is-playing.touch-device #game-shell:not([data-state="running"]) .touch-controls { display: none; }
}

@media (orientation: landscape) and (min-width: 500px) and (min-height: 260px) and (max-height: 540px) {
  .is-playing.touch-device #game-shell[data-adapter="canvas"][data-state="running"] {
    grid-template-columns: clamp(78px, 10vw, 100px) minmax(0, 1fr) clamp(110px, 17vw, 148px);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: .3rem;
    padding-block: max(.3rem, env(safe-area-inset-top)) max(.3rem, env(safe-area-inset-bottom));
  }
  .is-playing.touch-device [data-state="running"] .play-area {
    grid-area: 1 / 2;
    min-height: 0;
  }
  .is-playing.touch-device [data-state="running"] .ravine-frame {
    width: 100%; height: 100%;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .is-playing.touch-device [data-state="running"] .ravine-viewport {
    display: grid; place-items: center; container-type: size;
  }
  .is-playing.touch-device [data-state="running"] .ravine-arena { width: min(100cqw, 200cqh); }
  .is-playing.touch-device [data-state="running"] .ravine-footer { grid-area: 2 / 1 / 3 / -1; }
  .is-playing.touch-device [data-state="running"] .touch-controls {
    grid-area: 1 / 1 / 2 / -1;
    display: grid; grid-template-columns: subgrid; column-gap: inherit;
    align-self: end; align-items: end; min-height: 0; padding: 0;
    pointer-events: none;
  }
  .is-playing.touch-device [data-state="running"] .touch-stick {
    grid-column: 1; justify-self: center; pointer-events: auto;
  }
  .is-playing.touch-device [data-state="running"] .touch-actions {
    grid-column: 3;
    grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem;
    width: 100%; pointer-events: auto;
  }
  .is-playing.touch-device #game-shell[data-state="running"] .touch-actions button { min-height: 44px; }
}
