:root {
  --bg: #111312;
  --panel: #15161a;
  --panel2: #1c1d17;
  --bone: #c8bea0;
  --ember: #b06932;
  --lantern: #ecb362;
  --core: #fcd17e;
  --curse: #9cc45a;
  --muted: #8c8a82;
  --fail: #8a4a42;
  --line: rgba(200, 190, 160, 0.45);
  --fs: 1rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #111312;
  color: var(--bone);
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  font-size: 18px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #020201;
}
#vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(2,2,1,0.55) 100%);
}
body[data-screen="explore"] #vignette,
body[data-screen="dialogue"] #vignette { opacity: 0.32; }
body[data-screen="title"] #vignette {
  background:
    radial-gradient(ellipse at 30% 40%, rgba(176,105,50,0.12), transparent 42%),
    radial-gradient(ellipse at center, transparent 40%, rgba(2,2,1,0.72) 100%);
}

button {
  min-width: 48px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #1c1d17;
  color: var(--bone);
  border-radius: 2px;
  font: 600 1rem/1.1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.02em;
  cursor: pointer;
}
button:hover { border-color: var(--lantern); color: var(--core); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.38; cursor: default; transform: none; color: var(--muted); }
button:focus-visible, [tabindex]:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--lantern);
  outline-offset: 2px;
}
button:focus:not(:focus-visible) { outline: none; }
button.primary { border-color: var(--ember); color: var(--lantern); }
button.is-on { border-color: var(--lantern); background: #23252b; color: var(--core); }
button.icon-btn { min-width: 48px; width: 48px; padding: 0; }
button.menu-btn {
  width: auto;
  min-width: 48px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.menu-ico {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
  flex: 0 0 auto;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.screen[hidden] { display: none !important; }

#screen-title {
  align-items: stretch;
  justify-content: flex-end;
  background: linear-gradient(90deg, rgba(8,8,6,0.2) 0%, rgba(8,8,6,0.55) 55%, rgba(8,8,6,0.78) 100%);
}
.title-inner {
  width: min(420px, 46vw);
  margin: auto 4vw auto auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  text-align: left;
}
.kicker {
  margin: 0;
  color: var(--ember);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.7rem;
}
#game-title {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 4.4vw, 3.1rem);
  line-height: 1.05;
  letter-spacing: 0.06em;
  color: #c8bea0;
  text-shadow:
    0 1px 0 #fcd17e,
    0 2px 0 #3e352a,
    0 3px 0 #171109,
    0 0 22px rgba(176, 105, 50, 0.55);
}
.tag {
  margin: 0 0 8px;
  color: var(--muted);
  font-style: italic;
  font-family: Georgia, serif;
}
.title-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.title-actions .primary { grid-column: 1 / -1; }
.ai-note {
  margin: 10px 0 0;
  font-size: max(14px, 0.8rem);
  line-height: 1.35;
  color: #9b8365;
  max-width: 42em;
}

.sheet-screen { background: rgba(2, 2, 1, 0.62); }
.sheet {
  width: min(520px, 96vw);
  max-height: 96vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.55);
}
.sheet.wide { width: min(720px, 96vw); }
.sheet h2 {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-weight: 600;
  color: var(--lantern);
  letter-spacing: 0.04em;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { flex: 1; }
.muted { color: var(--muted); }
.error { color: #c07a72; margin: 0; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.field input {
  min-height: 48px;
  background: #111312;
  border: 1px solid var(--line);
  color: var(--bone);
  padding: 0 12px;
  font: 600 1rem/1 Georgia, serif;
}
.looks { display: flex; gap: 8px; }
.look {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  min-height: 96px;
}
.look canvas {
  width: 48px; height: 48px;
  image-rendering: pixelated;
  background: #020201;
}
.look span { font-size: 0.75rem; color: var(--muted); }

.attr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.attr {
  display: grid;
  grid-template-columns: 1fr 48px 2rem 48px;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(200,190,160,0.2);
  padding: 4px 6px;
}
.attr b { text-align: center; }
.derived {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px 10px;
  margin: 0;
}
.derived div { display: flex; justify-content: space-between; gap: 6px; border-bottom: 1px solid rgba(200,190,160,0.15); padding-bottom: 2px; }
.derived dt { color: var(--muted); font-size: 0.8rem; }
.derived dd { margin: 0; color: var(--core); }
.skill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.skill-row button { min-height: 48px; font-size: 0.85rem; }
.row-actions { display: flex; gap: 8px; }
.row-actions button { flex: 1; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1; min-width: 72px; }
.vol { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.vol input { flex: 1; height: 28px; }

.slot {
  display: grid;
  grid-template-columns: 1fr 88px 88px;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(200,190,160,0.2);
  padding: 8px;
}
.slot p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.slot.autosave { grid-template-columns: 1fr 88px; }
.code-panel textarea {
  width: 100%;
  min-height: 72px;
  background: #111312;
  color: var(--bone);
  border: 1px solid var(--line);
  font: 12px/1.3 ui-monospace, monospace;
  padding: 8px;
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(200,190,160,0.15); min-height: 44px; align-items: center; }
.party-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.party-card { border: 1px solid rgba(200,190,160,0.25); padding: 10px; }
.party-card h3 { margin: 0 0 4px; font-family: Georgia, serif; }
.party-card ul { margin: 8px 0 0; padding: 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }

#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: linear-gradient(to bottom, rgba(8,8,6,0.82), rgba(8,8,6,0));
  pointer-events: none;
}
#hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-width: 0;
}
#hud-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
#hud[hidden],
#interact-btn[hidden],
#dialogue-panel[hidden],
#export-panel[hidden],
#import-panel[hidden] { display: none !important; }
body:not([data-screen="explore"]):not([data-screen="dialogue"]) #hud { display: none !important; }
body[data-screen="battle"] #dialogue-panel,
body[data-screen="battle"] #tip-card,
body[data-screen="title"] #tip-card,
body[data-screen="charcreate"] #tip-card,
body[data-screen="credits"] #tip-card { display: none !important; }
#hud > * { pointer-events: auto; }
#hud-gold {
  font-family: Georgia, serif;
  color: var(--lantern);
  min-width: 72px;
  padding: 0 6px;
  flex: 0 0 auto;
}
#hud-hp { display: flex; gap: 12px; flex: 1; min-width: 0; }
#hud-obj {
  color: var(--muted);
  font-size: 0.78rem;
  max-width: 32vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 48px;
  height: auto;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid transparent;
  text-align: left;
  font-weight: 500;
}
#hud-obj.is-open {
  white-space: normal;
  position: absolute;
  top: calc(100% - 4px);
  left: 8px;
  right: 8px;
  max-width: none;
  background: rgba(17, 19, 18, 0.94);
  border: 1px solid var(--line);
  z-index: 6;
}
.hp-mini { display: flex; flex-direction: column; gap: 2px; min-width: 72px; font-size: 0.7rem; color: var(--muted); }
.hp-mini i { display: block; height: 6px; background: #23252b; border: 1px solid #3e352a; }
.hp-mini b { display: block; height: 100%; background: #b06932; }
#interact-btn {
  margin-left: auto;
  min-width: 88px;
  z-index: 6;
}

#dialogue-panel {
  position: fixed;
  z-index: 6;
  left: 8px; right: 8px; bottom: 8px;
  display: flex;
  gap: 12px;
  max-height: 52vh;
  overflow: auto;
  background: rgba(17, 19, 18, 0.94);
  border: 1px solid var(--line);
  padding: 10px;
  pointer-events: auto;
}
#dialogue-panel[hidden] { display: none !important; }
.portrait {
  width: 120px;
  height: 150px;
  object-fit: cover;
  object-position: 50% 18%;
  border: 1px solid var(--bone);
  flex: 0 0 auto;
  image-rendering: auto;
  background: #020201;
}
.dialogue-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.nameplate {
  font-family: Georgia, serif;
  color: var(--lantern);
  letter-spacing: 0.04em;
}
#dialogue-text {
  margin: 0;
  min-height: 2.6em;
  line-height: 1.35;
  color: var(--bone);
}
#dialogue-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.choice {
  min-height: 48px;
  height: auto;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 8px 10px;
  font-weight: 600;
  overflow: visible;
}
.choice.is-pass { border-color: rgba(156, 196, 90, 0.55); }
.choice.is-fail { border-color: rgba(138, 74, 66, 0.7); }
.check-badge {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}
.check-badge.pass { color: var(--curse); }
.check-badge.fail { color: var(--fail); }
.choice-tag { font-size: 0.72rem; color: var(--muted); font-style: italic; font-weight: 400; }

.credit-body { font-family: Georgia, serif; font-size: max(14px, 1.05rem); margin: 0 0 8px; }
body[data-screen="credits"] .sheet-screen {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}
.credits-sheet {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 10px 12px 8px;
  gap: 6px;
  overflow: hidden;
}
.credits-sheet .sheet-head { flex: 0 0 auto; }
.credits-sheet .sheet-head h2 { font-size: max(16px, 1.1rem); }
.credits-sheet button { font-size: max(14px, 0.9rem); }
.credits-sheet .muted { font-size: max(14px, 0.85rem); margin: 8px 0 0; }
.credits-head {
  margin: 0 0 8px;
  font-size: max(14px, 0.95rem);
  line-height: 1.4;
  color: var(--lantern);
}
.credits-scroll {
  margin: 0;
  padding: 8px 12px;
  flex: 1 1 auto;
  min-height: 60vh;
  overflow: auto;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-size: max(14px, 0.95rem);
  line-height: 1.5;
  color: var(--bone);
  background: #111312;
  border: 1px solid var(--line);
}
.credits-scroll p, .credits-scroll .credits-line, .credits-scroll .credits-head, .credits-scroll .ai-note {
  font-size: max(14px, 0.95rem);
}
.credits-scroll p { margin: 0 0 0.7em; }
.credits-scroll .credits-line { margin: 0 0 0.15em; }
.credits-scroll a { color: var(--lantern); }

#boot-error {
  position: fixed; z-index: 20; left: 8px; right: 8px; bottom: 8px;
  background: #341e0f; color: var(--bone); padding: 10px;
}

@media (orientation: portrait) {
  #screen-title { justify-content: flex-end; background: linear-gradient(to top, rgba(8,8,6,0.88) 0%, rgba(8,8,6,0.35) 55%, transparent 100%); }
  .title-inner {
    width: 100%;
    margin: 0;
    padding: 12px 14px 18px;
    text-align: center;
  }
  .title-actions { grid-template-columns: 1fr; }
  .title-actions .primary { grid-column: auto; }
  #dialogue-panel {
    flex-direction: column;
    max-height: 58vh;
    align-items: stretch;
  }
  .portrait { width: 64px; height: 64px; }
  .dialogue-body { width: 100%; }
  #dialogue-choices { grid-template-columns: 1fr 1fr; }
  .choice { font-size: 0.88rem; }
  .party-wrap { grid-template-columns: 1fr; }
  .derived { grid-template-columns: 1fr 1fr; }
  #hud { flex-wrap: wrap; }
  #interact-btn {
    position: fixed;
    right: max(8px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    margin: 0;
  }
  #hud-obj { max-width: none; flex: 1 1 100%; }
}
@media (max-height: 430px) and (orientation: landscape) {
  #game-title { font-size: 1.7rem; }
  .kicker, .tag { display: none; }
  #battle-intro .kicker { display: block; }
  .title-inner { gap: 6px; }
  .sheet { padding: 10px 12px; gap: 6px; }
  .look canvas { width: 40px; height: 40px; }
  .portrait { width: 72px; height: 90px; }
  #dialogue-panel { max-height: 78vh; padding: 6px 8px; }
  #dialogue-text { min-height: 1.8em; font-size: 0.95rem; }
  .choice { min-height: 48px; padding: 6px 8px; }
  #hud {
    display: grid;
    grid-template-columns: 48px 1fr;
    grid-template-areas:
      "menu cluster"
      "obj obj";
    gap: 4px 8px;
    padding: 4px 8px;
    align-items: center;
    flex-wrap: nowrap;
  }
  #hud-left { display: contents; }
  #menu-btn {
    grid-area: menu;
    width: 48px;
    min-width: 48px;
    height: 48px;
    padding: 0;
    justify-content: center;
  }
  .menu-label { display: none; }
  #hud-cluster {
    grid-area: cluster;
    gap: 8px;
  }
  #hud-gold { min-width: 0; font-size: 0.85rem; padding: 0; }
  #hud-hp { flex: 0 1 auto; gap: 8px; }
  .hp-mini { min-width: 56px; }
  #hud-obj {
    grid-area: obj;
    max-width: none;
    min-height: 32px;
    font-size: 0.72rem;
    padding: 2px 4px;
  }
  #interact-btn {
    position: fixed;
    right: max(8px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    margin: 0;
    min-width: 48px;
    min-height: 48px;
  }
}
@media (max-width: 700px) and (orientation: landscape) {
  .title-inner { width: min(380px, 52vw); }
  .derived { grid-template-columns: 1fr 1fr 1fr 1fr; font-size: 0.85rem; }
  .attr-grid { grid-template-columns: 1fr 1fr; }
  .portrait { width: 88px; height: 112px; }
}

html[data-reduced="1"] #game-title {
  text-shadow: 0 1px 0 #3e352a, 0 2px 0 #171109;
}

.ico-px {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 32px; height: 32px; flex: 0 0 32px;
  background: #111312;
  border: 1px solid rgba(200,190,160,0.2);
}
.ico-px.sz-32 { width: 32px; height: 32px; flex-basis: 32px; }
.ico-px.sz-48 { width: 48px; height: 48px; flex-basis: 48px; }
.ico-px.sz-64 { width: 64px; height: 64px; flex-basis: 64px; }
.inv-split { display: grid; grid-template-columns: minmax(280px, 1.6fr) minmax(200px, 1fr); gap: 12px; min-height: 180px; }
.inv-list { display: flex; flex-direction: column; gap: 4px; max-height: 52vh; overflow: auto; min-width: 0; }
.inv-row, .shop-row, .craft-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 4px 8px;
  text-align: left;
  width: 100%;
}
.shop-row, .craft-row { grid-template-columns: 56px 1fr auto auto auto; min-height: 52px; }
.inv-detail-head .ico-px { width: 64px; height: 64px; flex-basis: 64px; }
.loot-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0;
}
.loot-row .ico-px { width: 64px; height: 64px; flex-basis: 64px; }
#toast {
  position: fixed; z-index: 30; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: #341e0f; color: var(--bone); border: 1px solid var(--line);
  padding: 10px 16px; min-height: 48px; max-width: 90vw;
}
#toast[hidden] { display: none !important; }
#battle-intro .kicker { margin-bottom: 4px; }
@media (max-width: 900px) {
  .inv-row .ico-px, .shop-row .ico-px, .craft-row .ico-px {
    width: 48px; height: 48px; flex-basis: 48px;
  }
  .inv-row { grid-template-columns: 56px 1fr auto auto; }
}
.inv-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#inventory-screen.sheet.wide { width: min(920px, 96vw); }
.inv-meta, .inv-wt { color: var(--muted); font-size: 0.85rem; }
.weight-bar { display: flex; align-items: center; gap: 10px; }
.weight-bar i { flex: 1; height: 8px; background: #23252b; border: 1px solid rgba(200,190,160,0.3); }
.weight-bar b { display: block; height: 100%; background: var(--ember); }
.cmp-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.cmp-up { color: #9cc45a; }
.cmp-down { color: #c07a72; }
.cmp-same { color: var(--muted); }
.inv-detail-head { display: flex; gap: 10px; align-items: flex-start; }
.inv-detail-head h3 { margin: 0; font-family: Georgia, serif; color: var(--lantern); }
.row-actions.wrap { flex-wrap: wrap; }
.row-actions.wrap button {
  flex: 1 1 auto;
  min-width: 7.2rem;
  white-space: nowrap;
}
#casebook-screen .sheet, #journal-screen .sheet { width: min(640px, 96vw); }
#casebook-body p { margin: 0.35em 0; }
.craft-row .inv-name { white-space: normal; }
.shop-line { font-family: Georgia, serif; color: var(--core); }
.eq-grid { display: grid; gap: 4px; margin-top: 8px; }
.eq-slot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid rgba(200,190,160,0.15); padding: 4px 0; min-height: 48px; }
.trees { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.tree { border: 1px solid rgba(200,190,160,0.2); padding: 8px; }
.tree h3 { margin: 0 0 6px; font-family: Georgia, serif; font-size: 1rem; }
.skill-line { border-bottom: 1px solid rgba(200,190,160,0.12); padding: 6px 0; }
.skill-line p { margin: 2px 0 6px; color: var(--muted); font-size: 0.85rem; }
.skill-line.is-later { opacity: 0.55; }
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(2,2,1,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.modal[hidden] { display: none !important; }
.story-screen {
  background: #020201;
  align-items: stretch;
  justify-content: stretch;
}
.story-card {
  width: 100%; height: 100%;
  background:
    linear-gradient(to top, rgba(8,8,6,0.92) 0%, rgba(8,8,6,0.55) 45%, rgba(8,8,6,0.35) 100%),
    url('../assets/art/oswy-scene.jpg') center/cover no-repeat;
  display: flex; align-items: flex-end;
  padding: 24px;
}
.story-card #story-card-body {
  width: min(640px, 96vw);
  background: rgba(17,19,18,0.82);
  border: 1px solid var(--line);
  padding: 16px 18px;
}
.story-copy { max-height: 48vh; overflow: auto; }
.story-copy p { margin: 0 0 0.7em; }
@media (max-width: 800px) {
  .inv-split, .trees, .party-wrap { grid-template-columns: 1fr; }
}
@media (max-height: 430px) and (orientation: landscape) {
  .inv-split {
    grid-template-columns: minmax(200px, 1.45fr) minmax(170px, 1fr);
    gap: 8px;
    min-height: 0;
  }
  .inv-list { max-height: 46vh; }
  #inventory-screen.sheet.wide { width: min(780px, 96vw); }
  .inv-detail-head .ico-px { width: 48px; height: 48px; flex-basis: 48px; }
}

#screen-title {
  background:
    linear-gradient(90deg, rgba(2,2,1,0.18) 0%, rgba(2,2,1,0.42) 48%, rgba(2,2,1,0.78) 100%);
}

.battle-overlay {
  background: transparent;
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
  pointer-events: none;
  z-index: 5;
}
#battle-root {
  width: 100%;
  height: 100%;
  position: relative;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}
#battle-turnbar {
  pointer-events: auto;
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  align-items: center;
  min-height: 48px;
  background: linear-gradient(to bottom, rgba(8,8,6,0.86), transparent);
}
.turn-pip {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(200,190,160,0.35);
  position: relative;
  overflow: hidden;
  background: #111312;
}
.turn-pip img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 40%; image-rendering: pixelated; }
.turn-pip i { position: absolute; left: 0; bottom: 0; height: 3px; background: #b06932; }
.turn-pip.is-on { border-color: #ecb362; box-shadow: 0 0 0 1px #ecb362; }
.turn-pip.is-dead { opacity: 0.35; filter: grayscale(0.6); }
#battle-preview {
  pointer-events: auto;
  position: absolute;
  left: 50%;
  top: 52px;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(17,19,18,0.94);
  border: 1px solid var(--lantern);
  box-shadow: 0 0 0 1px #111312, 0 8px 22px rgba(2,2,1,0.55);
  padding: 8px 14px;
  min-height: 36px;
  min-width: 220px;
  text-align: center;
  color: var(--core);
  font-family: Georgia, serif;
  font-size: 0.95rem;
}
#battle-log {
  pointer-events: auto;
  position: absolute;
  left: 8px;
  top: 52px;
  width: min(280px, 42vw);
  max-height: 28vh;
  overflow: hidden;
}
#battle-log-toggle {
  min-height: 36px;
  font-size: 0.75rem;
}
#battle-log-body { display: block; background: rgba(17,19,18,0.88); padding: 6px 8px; font-size: 0.82rem; line-height: 1.35; max-height: 22vh; overflow: auto; color: var(--bone); }
#battle-log.is-open #battle-log-body { display: block; max-height: 36vh; }
#battle-log-body p { margin: 0 0 4px; }
#battle-dock {
  pointer-events: auto;
  margin-top: auto;
  padding: 6px 8px 8px;
  background: linear-gradient(to top, rgba(8,8,6,0.92), rgba(8,8,6,0.2));
}
#battle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.battle-act {
  min-width: 64px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  padding: 4px 8px;
}
.ico {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  display: inline-block;
}
.ico-move { border-radius: 50%; }
.ico-attack { transform: rotate(45deg); width: 10px; height: 10px; }
.ico-trick { border-style: dashed; }
.ico-item { border-radius: 2px 2px 6px 6px; }
.ico-ward { border-radius: 0; }
.ico-breath { border-radius: 50% 50% 50% 0; }
.ico-wait { border: 0; border-top: 2px solid currentColor; width: 12px; }
.battle-confirm-row { display: flex; gap: 8px; justify-content: center; margin-top: 6px; }
#battle-confirm { min-width: 160px; min-height: 48px; font-size: 1.05rem; }
#battle-sub { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 6px; }
.battle-card {
  pointer-events: auto;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 6;
}
.battle-card[hidden] { display: none !important; }
.battle-card h2 { margin: 0; font-family: Georgia, serif; color: var(--lantern); }
#battle-intro.battle-card {
  top: 6px;
  transform: translate(-50%, 0);
  width: min(360px, 86vw);
  padding: 8px 12px;
  gap: 4px;
}
#battle-intro.is-fading { opacity: 0; transition: opacity 0.28s linear; pointer-events: none; }

@media (orientation: portrait) {
  #hud-obj { max-width: 90vw; }
  #battle-actions { display: grid; grid-template-columns: repeat(4, 1fr); }
  #battle-log { width: min(240px, 70vw); top: auto; bottom: 148px; }
}
@media (max-height: 430px) and (orientation: landscape), (max-width: 720px) and (orientation: landscape) {
  #battle-log {
    left: auto;
    right: 8px;
    top: 4px;
    width: auto;
    max-width: min(220px, 30vw);
    max-height: none;
  }
  #battle-log-body {
    display: none;
    font-size: 14px;
    line-height: 1.3;
    max-height: 28vh;
    min-width: 160px;
  }
  #battle-log.is-open #battle-log-body { display: block; }
  #battle-log-toggle { min-height: 36px; font-size: 0.8rem; }
}
@media (max-height: 430px) and (orientation: landscape) {
  #battle-intro.battle-card { padding: 4px 8px; width: min(240px, 42vw); gap: 2px; }
  #battle-intro h2 { font-size: 0.95rem; }
  #battle-intro .kicker { font-size: 0.62rem; margin-bottom: 0; }
  .battle-act { min-width: 52px; min-height: 48px; font-size: 0.68rem; padding: 2px 6px; }
  #battle-turnbar { min-height: 36px; padding: 2px 8px; }
  #battle-preview { top: 40px; font-size: 0.82rem; padding: 4px 10px; min-width: 180px; }
  #battle-dock {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 2px 6px 4px;
  }
  #battle-actions { margin: 0; flex-wrap: nowrap; }
  .battle-confirm-row { margin-top: 0; flex-shrink: 0; }
  #battle-confirm { min-width: 120px; min-height: 48px; }
}
