:root {
  --ink: #1a1210;
  --cream: #f3e6d2;
  --parchment: #e8d4b4;
  --oxblood: #6e1d28;
  --oxblood-deep: #3a1016;
  --gold: #c9a05a;
  --gold-soft: #e6c98a;
  --teal: #2f5e5a;
  --teal-glow: #7ec8b8;
  --ash: #8a7564;
  --hit: #e35a3a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--cream);
  font-family: "Outfit", "Segoe UI", sans-serif;
  overflow: hidden;
}
#app { min-height: 100%; }
button, input { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 0;
  background: none;
}
img { max-width: 100%; display: block; }

#grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  opacity: 0.08;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='.55'/></svg>");
  mix-blend-mode: overlay;
}

.screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.title-card {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 28px;
  align-items: stretch;
  background:
    radial-gradient(120% 80% at 10% 20%, #4a1c22 0%, transparent 55%),
    linear-gradient(160deg, #241618, #120d0c);
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  box-shadow: 0 30px 80px #000a;
}
.title-copy { padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; }
.kicker {
  letter-spacing: 0.42em;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--gold-soft);
}
h1, h2, .serif {
  font-family: "Noto Serif SC", "Cormorant Garamond", serif;
  font-weight: 700;
}
h1 {
  font-size: clamp(42px, 6vw, 72px);
  margin: 12px 0 8px;
  line-height: 1.05;
}
.subtitle {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 22px;
  color: var(--gold-soft);
  margin-bottom: 18px;
}
.lede { max-width: 36em; color: color-mix(in srgb, var(--cream) 82%, var(--ash)); line-height: 1.7; }
.title-art {
  position: relative;
  overflow: hidden;
  min-height: 420px;
}
.title-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 82%;
  filter: saturate(1.06) contrast(1.05);
}
.title-art .ly-bg,
.title-art .ly-body,
.title-art .ly-shoe {
  position: absolute;
  inset: 0;
}
.title-art .ly-bg { object-position: 50% 72%; filter: none; }
.title-art .ly-body { object-position: 50% 88%; z-index: 1; }
.title-art .ly-shoe { object-position: 50% 88%; z-index: 2; }
.title-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }

.btn {
  min-height: 44px;
  padding: 12px 22px;
  border: 1px solid var(--gold);
  color: var(--cream);
  background: color-mix(in srgb, var(--oxblood) 70%, #000);
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 160ms cubic-bezier(.2,1.4,.3,1), background 160ms ease;
}
.btn:hover { transform: translateY(-2px) scale(1.02); background: var(--oxblood); }
.btn:active { transform: scale(0.97); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn:focus-visible,
.eq-card:focus-visible,
.hotspot:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 3px;
}
.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.4em;
  height: 1.4em;
  padding: 0 4px;
  border: 1px solid color-mix(in srgb, var(--gold) 55%, transparent);
  background: #0006;
  font: 11px ui-monospace, "Cascadia Mono", monospace;
  letter-spacing: 0;
  color: var(--gold-soft);
}

.stage {
  height: 100%;
  display: grid;
  grid-template-columns: 1.25fr 0.85fr;
  grid-template-rows: 1fr auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.map-wrap {
  position: relative;
  overflow: hidden;
  background: #cbb48e;
  transform: translate3d(var(--shake-x, 0), var(--shake-y, 0), 0);
}
.map-wrap img.map {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
.hotspot {
  position: absolute;
  width: 86px;
  height: 86px;
  margin: -43px 0 0 -43px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--gold) 80%, white);
  background: radial-gradient(circle at 50% 40%, #fff6, transparent 55%), color-mix(in srgb, var(--oxblood) 55%, transparent);
  box-shadow: 0 0 0 6px #0002, 0 8px 18px #0005;
  color: var(--cream);
  display: grid;
  place-items: center;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-align: center;
  padding: 8px;
  line-height: 1.2;
}
.hotspot:hover { transform: scale(1.06); }
.hotspot.here {
  background: var(--oxblood);
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--gold) 50%, transparent);
}
.hotspot.cleared::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal-glow);
  position: absolute;
  top: 8px;
  right: 8px;
}
.hotspot:disabled { opacity: 0.35; }
.map-hero {
  position: absolute;
  width: 72px;
  height: 72px;
  margin: -92px 0 0 -36px;
  pointer-events: none;
  z-index: 4;
  filter: drop-shadow(0 8px 10px #0008);
  transition: left 280ms cubic-bezier(.2,1.1,.3,1), top 280ms cubic-bezier(.2,1.1,.3,1);
  image-rendering: auto;
}
.map-hero img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.portrait-col {
  display: grid;
  grid-template-rows: 1fr auto;
  background: #0c0a0a;
  border-left: 1px solid color-mix(in srgb, var(--gold) 28%, transparent);
  position: relative;
}
.portrait {
  position: relative;
  overflow: hidden;
  min-height: 200px;
  transform: translate3d(var(--shake-x, 0), var(--shake-y, 0), 0);
}
.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 88%;
  transition: filter 280ms ease, transform 420ms cubic-bezier(.16,1,.3,1);
}
.portrait .ly-bg,
.portrait .ly-body,
.portrait .ly-shoe {
  position: absolute;
  inset: 0;
}
.portrait .ly-bg {
  object-position: 50% 70%;
  z-index: 0;
}
.portrait .ly-body {
  object-position: 50% 88%;
  z-index: 1;
  filter: drop-shadow(0 18px 22px #0006);
}
.portrait .ly-shoe {
  object-position: 50% 88%;
  z-index: 2;
  filter: none;
}
.portrait .ly-body.volcano { filter: drop-shadow(0 18px 22px #0006) sepia(.18) saturate(1.12) hue-rotate(-8deg); }
.portrait .ly-body.ice { filter: drop-shadow(0 18px 22px #0006) saturate(.78) hue-rotate(12deg) brightness(1.04); }
.portrait .ly-body.snow { filter: drop-shadow(0 18px 22px #0006) saturate(.72) brightness(1.1); }
.portrait.dress .ly-body,
.portrait.dress .ly-shoe { transform: scale(1.04); }
.ly-wounds {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.ly-wounds .scar,
.ly-wounds .scar-fresh { display: none; }
.portrait.wounds-1 .s1,
.portrait.wounds-2 .s1,
.portrait.wounds-2 .s2,
.portrait.wounds-3 .s1,
.portrait.wounds-3 .s2,
.portrait.wounds-3 .s3,
.portrait.wounds-4 .s1,
.portrait.wounds-4 .s2,
.portrait.wounds-4 .s3,
.portrait.wounds-4 .s4 { display: inline; }
.portrait.hurt .scar-fresh {
  display: inline;
  animation: wound-bloom 520ms ease-out forwards;
}
@keyframes wound-bloom {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
.cap {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 4;
  letter-spacing: 0.14em;
  color: var(--gold-soft);
  text-shadow: 0 2px 12px #000;
}
.hud {
  padding: 14px 16px 16px;
  background: linear-gradient(180deg, #1a1214, #120e0e);
  display: grid;
  gap: 10px;
}
.bars { display: grid; gap: 6px; }
.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--gold-soft);
}
.bar {
  height: 10px;
  background: #2a1c1c;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--gold);
  width: var(--w);
  transition: width 240ms ease, background 240ms ease;
}
.bar.warn > span { background: #d4a017; }
.bar.danger > span { background: var(--hit); }
.bar.danger { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hit) 50%, transparent); }
.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: color-mix(in srgb, var(--cream) 80%, var(--ash));
}
.chip {
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  padding: 4px 8px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.dock {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1.25fr 0.85fr;
  background: #140f10;
  border-top: 1px solid color-mix(in srgb, var(--gold) 22%, transparent);
  min-height: 148px;
}
.log {
  margin: 0;
  padding: 14px 18px;
  list-style: none;
  font-size: 13px;
  line-height: 1.55;
  color: color-mix(in srgb, var(--cream) 78%, var(--ash));
  overflow: auto;
  max-height: 148px;
}
.log li:first-child { color: var(--cream); }
.panel {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 1px solid #ffffff10;
}
.panel h2 { margin: 0; font-size: 18px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #0c0909e6;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.sheet {
  width: min(920px, 100%);
  max-height: min(92vh, 960px);
  overflow: auto;
  background: #171111;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  padding: 0 22px 22px;
}
.sheet-narrow { width: min(560px, 100%); }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 12px;
  margin-bottom: 8px;
  background: #171111;
  border-bottom: 1px solid #ffffff12;
}
.sheet-head h2 { margin: 0; }
.grid-eq {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.grid-eq > div {
  max-height: min(68vh, 720px);
  overflow-y: auto;
  padding-right: 6px;
}
.eq-card {
  text-align: left;
  width: 100%;
  min-height: 44px;
  padding: 12px;
  border: 1px solid #ffffff14;
  background: #22181a;
  margin-bottom: 8px;
}
.eq-card.on { border-color: var(--gold); background: #3a2226; }
.eq-card small { display: block; color: var(--ash); margin-top: 4px; }

.combat {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 20px;
  align-items: center;
}
.foe-art {
  background: var(--parchment);
  min-height: 120px;
  display: grid;
  place-items: center;
}
.foe-art img { width: min(220px, 100%); height: auto; }
.pops {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.pop {
  position: absolute;
  font-family: "Cormorant Garamond", serif;
  font-size: 28px;
  color: var(--cream);
  animation: pop 700ms cubic-bezier(.16,1,.3,1) forwards;
  text-shadow: 0 2px 0 #000, 0 0 12px #000;
}
.pop.crit { font-size: 42px; color: var(--gold-soft); }
.pop.ward { font-size: 22px; color: var(--ash); }
.pop.hit { color: var(--hit); }
@keyframes pop {
  from { transform: translate(-50%, 8px) scale(0.7); opacity: 0; }
  30% { opacity: 1; }
  to { transform: translate(-50%, -48px) scale(1.1); opacity: 0; }
}

.route {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 5;
  display: flex;
  gap: 0;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  background: #0c0909d0;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.route li {
  padding: 4px 10px;
  color: var(--ash);
  border-right: 1px solid #ffffff14;
}
.route li:last-child { border-right: 0; }
.route li.here { color: var(--cream); }
.route li.done { color: var(--teal-glow); }
.objective {
  position: absolute;
  top: 52px;
  left: 14px;
  z-index: 5;
  max-width: min(420px, 70%);
  padding: 8px 12px;
  background: #0c0909d0;
  border: 1px solid color-mix(in srgb, var(--gold) 28%, transparent);
  color: var(--gold-soft);
  font-size: 13px;
  text-shadow: 0 1px 8px #000;
}
.hint {
  margin: 0;
  font-size: 12px;
  color: var(--ash);
  line-height: 1.4;
}
.combat-acts { margin-top: 2px; }
.bar.foe > span { background: var(--teal-glow); }
.bar.foe.warn > span { background: #d4a017; }
.bar.foe.danger > span { background: var(--hit); }

.end {
  text-align: center;
  max-width: 520px;
}
.end h1 { margin-bottom: 12px; }

#dev {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 50;
  font: 12px ui-monospace, monospace;
  color: #8f8;
}

@media (max-width: 900px) {
  html, body {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #app { min-height: 100dvh; }
  .screen {
    height: auto;
    min-height: 100dvh;
    display: block;
    padding: max(12px, env(safe-area-inset-top)) 12px max(24px, env(safe-area-inset-bottom));
  }
  .title-card, .stage, .dock, .combat, .grid-eq {
    grid-template-columns: 1fr;
  }
  .title-card { width: 100%; }
  .title-copy { padding: 28px 20px 16px; }
  h1 { font-size: clamp(32px, 11vw, 52px); }
  .title-art {
    min-height: 0;
    aspect-ratio: 2 / 3;
    max-height: 70dvh;
  }
  .stage {
    height: auto;
    display: flex;
    flex-direction: column;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .map-wrap {
    height: 46dvh;
    min-height: 220px;
    flex: none;
  }
  .portrait-col {
    border-left: 0;
    border-top: 1px solid color-mix(in srgb, var(--gold) 28%, transparent);
    grid-template-rows: auto auto;
  }
  .portrait {
    height: auto;
    min-height: 320px;
    aspect-ratio: 2 / 3;
  }
  .dock {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .log { max-height: none; }
  .hotspot { width: 64px; height: 64px; margin: -32px 0 0 -32px; font-size: 10px; }
  .route {
    font-size: 11px;
    padding: 4px 6px;
    flex-wrap: wrap;
    max-width: calc(100% - 24px);
  }
  .objective { top: 52px; max-width: calc(100% - 28px); font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .hotspot, .map-hero, .portrait img, .bar > span { transition: none; }
  .btn:hover, .btn:active, .hotspot:hover { transform: none; }
  .pop { animation: none; opacity: 1; }
  .map-wrap, .portrait { transform: none !important; }
  .portrait.hurt .scar-fresh { animation: none; opacity: 0; }
}
