:root {
  --ink: #070605;
  --blood: #9c1f18;
  --blood-2: #c4453c;
  --bone: #f0e4d2;
  --mute: #b09a88;
  --panel: rgba(8, 6, 6, 0.82);
  --line: rgba(196, 69, 60, 0.7);
  --dock: #120c0e;
  --dur-fast: 90ms;
  --dur-base: 180ms;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  background: #050403;
  color: var(--bone);
  font-family: "Noto Serif SC", "Songti SC", serif;
  overflow: hidden;
}
button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}
button:focus-visible {
  outline: 2px solid #e3896d;
  outline-offset: 2px;
}
#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050403;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
  touch-action: auto;
}
.screen.active { display: flex; }

/* title */
#scr-title {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  background: #100e13;
}
#title-scene { position: absolute; width: 100%; height: 100%; object-fit: cover; inset: 0; }
#scr-title::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(4,5,9,.93), rgba(4,5,9,.55) 45%, transparent 75%);
  z-index: 1;
  pointer-events: none;
}
.title-block {
  position: relative;
  z-index: 1;
  text-align: left;
  padding: 0 5vw;
  max-width: 620px;
}
.eyebrow {
  letter-spacing: .55em;
  font-size: 12px;
  color: var(--blood-2);
  text-transform: uppercase;
}
h1.logo {
  font-family: "Cinzel", "Noto Serif SC", serif;
  font-size: clamp(48px, 8vw, 92px);
  font-weight: 700;
  letter-spacing: 0.18em;
  margin: 8px 0 6px 0;
  text-shadow: 0 0 32px rgba(156,31,24,.55);
}
.sub {
  color: var(--mute);
  letter-spacing: .42em;
  font-size: 13px;
  margin-bottom: 28px;
}
.row-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn {
  min-width: 140px;
  min-height: 44px;
  padding: 12px 22px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.55);
  color: var(--bone);
  letter-spacing: .22em;
  font-size: 14px;
  transition: transform var(--dur-fast), background var(--dur-fast);
}
.btn:hover { background: rgba(156,31,24,.35); transform: translateY(-1px); }
.btn.primary { background: #7a1612; border-color: #c4453c; }
.hint { margin-top: 18px; color: var(--mute); font-size: 12px; letter-spacing: .12em; }

/* story */
#scr-story {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0707;
  padding: 40px;
}
#story-line {
  max-width: 640px;
  font-size: 22px;
  line-height: 1.8;
  text-align: center;
  min-height: 4em;
}
#story-idx { color: var(--mute); margin: 24px 0; letter-spacing: .3em; font-size: 12px; }

/* select */
#scr-select, #scr-bestiary, #scr-curve, #scr-rest, #scr-defeat, #scr-end {
  flex-direction: column;
  background: radial-gradient(ellipse at top, #1a1010, #070505 60%);
  padding: 28px 32px 40px;
  padding-top: calc(28px + var(--safe-t));
}
.screen h2 {
  font-size: 22px;
  letter-spacing: 0.14em;
  font-weight: 600;
  margin-bottom: 8px;
}
.lead { color: var(--mute); margin-bottom: 20px; font-size: 14px; }
#hero-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}
.hero-card {
  text-align: left;
  border: 1px solid rgba(156,31,24,.35);
  background: rgba(0,0,0,.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .15s, transform .15s;
}
.hero-card img { width: 100%; height: 220px; object-fit: cover; object-position: top; background: #cbbba4; display: block; }
.hero-card.on { border-color: var(--blood-2); box-shadow: 0 0 0 1px var(--blood-2); transform: translateY(-4px); }
.hc-body { padding: 12px 14px 16px; }
.hc-role { color: var(--blood-2); font-size: 12px; letter-spacing: .3em; }
.hero-card h3 { font-size: 18px; margin: 4px 0 8px; }
.hero-card p { font-size: 13px; color: var(--mute); line-height: 1.55; }
#select-stats { max-width: 1100px; width: 100%; margin: 16px auto 8px; font-size: 13px; color: var(--mute); }
#select-skills { max-width: 1100px; width: 100%; margin: 0 auto 18px; }
.sk-basic { color: var(--blood-2); margin: 8px 0; letter-spacing: .12em; }
.sk-line { display: grid; grid-template-columns: 120px 48px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.06); font-size: 13px; }
.sk-line i { color: var(--mute); font-style: normal; }
.select-actions {
  display: flex;
  gap: 10px;
  max-width: 1100px;
  width: 100%;
  margin: 8px auto 0;
  position: sticky;
  bottom: 0;
  padding: 14px 0 6px;
  background: linear-gradient(transparent, #070505 40%);
  z-index: 3;
}

/* battle */
#scr-battle {
  flex-direction: column;
  background: #000;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.stage {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  display: flex;
  flex-direction: column;
  background: #070508;
}
.playfield {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}
#game {
  width: 100%;
  height: 100%;
  display: block;
  background: #141018;
  object-fit: contain;
  object-position: center bottom;
}
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  z-index: 2;
}
.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.hp-wrap { flex: 1; max-width: 420px; }
.bar {
  height: 12px;
  background: rgba(0,0,0,.62);
  border: 1px solid rgba(232, 180, 150, 0.45);
  position: relative;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, #7a1612, #e05648); width: 100%; }
.xp-bar { height: 6px; margin-top: 4px; }
#xp-fill { background: linear-gradient(90deg, #3a2a18, #e0c07a); }
.meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-top: 4px;
  color: var(--bone);
  letter-spacing: .08em;
  text-shadow: 0 1px 3px #000;
}
.right-meta { text-align: right; font-size: 13px; text-shadow: 0 1px 3px #000; pointer-events: auto; }
.right-meta b { color: #ff8a72; }
.hud-tools { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.mini {
  pointer-events: auto;
  padding: 6px 10px;
  min-height: 36px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.62);
  font-size: 11px;
  letter-spacing: .08em;
}
.mini.on { background: rgba(156,31,24,.55); border-color: #c4453c; }

#battle-dock {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 3;
  pointer-events: none;
  padding: 0 12px calc(10px + var(--safe-b));
}
#battle-dock > * { pointer-events: auto; }
.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
}
#skills { display: flex; gap: 8px; }
.attack-main {
  width: 96px; height: 96px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid #e3896d; color: #fff0d9;
  background: radial-gradient(circle at 38% 28%, #a94033, #421319 70%);
  box-shadow: 0 0 0 5px #211215, 0 0 0 6px #794137, 0 5px 26px #0009;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
  touch-action: none; user-select: none; cursor: pointer; margin: 0 0 4px auto;
}
.attack-main b { font-size: 22px; letter-spacing: .1em; }
.attack-main small { font-size: 10px; }
.attack-main span { font-size: 10px; color: #f2b190; }
.attack-main.down, .attack-main.striking { border-color: #fff1c6; box-shadow: 0 0 0 5px #441c22, 0 0 26px #c95137aa; }
.attack-main.down { transform: scale(.95); }
body.touch .attack-main { display: none; }
.skill-btn {
  width: 70px;
  background: none;
  border: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  touch-action: none;
}
.skill-face {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid #c4453c;
  background: radial-gradient(circle at 30% 25%, #3a2222, #100808 70%);
  position: relative;
  overflow: hidden;
}
.skill-btn canvas { width: 100%; height: 100%; pointer-events: none; }
.skill-btn .cd {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0;
  background: rgba(0,0,0,.72);
  color: var(--bone);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.skill-btn .sk-name {
  white-space: nowrap;
  font-size: 11px;
  color: var(--bone);
  text-shadow: 0 1px 4px #000;
}
.skill-btn.locked { filter: grayscale(1) brightness(.55); }
#toast {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  opacity: 0;
  padding: 8px 16px;
  background: rgba(0,0,0,.78);
  border: 1px solid var(--line);
  letter-spacing: .2em;
  font-size: 13px;
  pointer-events: none;
  transition: opacity var(--dur-base), transform var(--dur-base);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#pause-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.72);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
  z-index: 8;
}
#pause-overlay.active { display: flex; }
#pause-overlay h3 { letter-spacing: 0.2em; margin-bottom: 8px; }
#pause-overlay .hint { margin: 0 0 6px; }

.coach {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(transparent 30%, rgba(0,0,0,.55));
  pointer-events: auto;
}
.coach[hidden] { display: none !important; }
.coach-card {
  width: min(420px, 100%);
  background: rgba(12, 8, 10, 0.92);
  border: 1px solid var(--line);
  padding: 16px 18px;
}
.coach-kicker { color: var(--blood-2); letter-spacing: .28em; font-size: 12px; margin-bottom: 8px; }
.coach-card ul { list-style: none; font-size: 14px; line-height: 1.7; color: var(--bone); margin-bottom: 12px; }
.coach-card b { color: #ffb39a; }

/* rest / end */
.panel {
  max-width: 720px;
  width: 100%;
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 28px 32px;
}
.picks { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 16px 0; }
.pick {
  border: 1px solid rgba(156,31,24,.35);
  padding: 14px 10px;
  background: rgba(0,0,0,.35);
  text-align: center;
}
.pick.on { border-color: var(--blood-2); background: rgba(156,31,24,.25); }
.pick b { display: block; margin-bottom: 6px; }
.pick span { color: var(--mute); font-size: 12px; }
#camp-meta { color: var(--bone); margin: 8px 0 4px; font-size: 14px; }
#camp-meta b { color: #c9a36a; }
.shop {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}
.shop-item {
  border: 1px solid rgba(156,31,24,.35);
  padding: 12px 14px;
  background: rgba(0,0,0,.35);
  text-align: left;
}
.shop-item:hover:not(:disabled) { border-color: var(--blood-2); }
.shop-item:disabled { opacity: 0.38; cursor: default; }
.shop-item b { display: block; margin-bottom: 4px; }
.shop-item span { display: block; color: var(--mute); font-size: 12px; line-height: 1.45; }
.shop-item .price { color: #c9a36a; margin-top: 6px; }
.camp-nav { flex-wrap: wrap; justify-content: flex-start; }
.panel.camp { max-width: 760px; }

#bestiary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  overflow: auto;
}
.be-card {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  background: rgba(0,0,0,.4);
  border: 1px solid rgba(156,31,24,.3);
  padding: 8px;
  align-items: center;
}
.be-card img { width: 88px; height: 88px; object-fit: contain; background: #cbbba4; }
.be-card em { color: var(--blood-2); font-style: normal; font-size: 12px; margin-left: 8px; }
.be-card p { color: var(--mute); font-size: 12px; margin-top: 4px; line-height: 1.45; }

table.curve {
  width: 100%;
  max-width: 720px;
  border-collapse: collapse;
  font-size: 14px;
}
table.curve th, table.curve td {
  border-bottom: 1px solid rgba(255,255,255,.08);
  padding: 8px 10px;
  text-align: right;
}
table.curve th:first-child, table.curve td:first-child { text-align: left; }

#end-text { font-size: 20px; line-height: 1.8; margin: 12px 0 20px; }
#end-stats { color: var(--mute); margin-bottom: 20px; }

#touch {
  display: none;
  position: relative;
  justify-content: space-between;
  align-items: flex-end;
  padding: 8px 4px 0;
  pointer-events: none;
  margin-top: 4px;
}
body.touch #touch { display: flex; }
#touch .tc-left, #touch .tc-right { display: flex; gap: 10px; align-items: flex-end; pointer-events: auto; }
#touch button {
  -webkit-tap-highlight-color: transparent;
  width: 56px; height: 56px;
  min-width: 48px; min-height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(226, 170, 140, 0.75);
  background: rgba(18, 10, 12, 0.72);
  color: var(--bone);
  font-size: 18px;
  letter-spacing: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#touch button.big { width: 72px; height: 72px; font-size: 22px; background: rgba(122,22,18,.78); }
#touch button.down { background: rgba(196,69,60,.85); transform: scale(.94); }

@media (max-width: 820px) {
  #hero-row { grid-template-columns: 1fr; }
  .sk-line { grid-template-columns: 1fr; }
  .skill-btn { width: 56px; }
  .skill-face { width: 52px; height: 52px; }
  h1.logo { letter-spacing: .18em; }
  .picks { grid-template-columns: 1fr; }
  .shop { grid-template-columns: 1fr; }
  .title-block { max-width: 92%; }
  .title-block .hint { font-size: 10px; }
}

/* Portrait / tall playfield: dock sits UNDER the canvas, not on top of it */
@media (max-aspect-ratio: 10/11) {
  #scr-title::before {
    background: linear-gradient(180deg, rgba(4,5,9,.55), rgba(4,5,9,.88) 55%, rgba(4,5,9,.94));
  }
  .title-block { padding-top: 8vh; }
  .stage {
    width: 100vw;
    height: 100dvh;
    max-width: none;
  }
  .playfield { flex: 1 1 auto; min-height: 42vh; }
  #game { object-fit: fill; object-position: center; }
  .hud-top { flex-wrap: wrap; }
  .hp-wrap { max-width: none; width: 100%; }
  .right-meta {
    width: 100%;
    max-width: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    gap: 8px;
  }
  .hud-tools { margin-top: 0; max-width: none; }
  #toast { top: auto; bottom: 12px; }
  #battle-dock {
    position: relative;
    flex: 0 0 auto;
    background: linear-gradient(180deg, #1a1014, #0c0809);
    border-top: 1px solid rgba(196, 69, 60, 0.35);
    padding: 8px 10px calc(8px + var(--safe-b));
    pointer-events: auto;
  }
  .hud-bottom { align-items: center; }
  .attack-main { width: 72px; height: 72px; }
  .attack-main b { font-size: 16px; }
  .hud-tools .mini { font-size: 10px; padding: 5px 8px; min-height: 32px; }
  #touch button { width: 52px; height: 52px; }
  #touch button.big { width: 64px; height: 64px; }
  .coach { align-items: center; background: rgba(0,0,0,.45); }
}

/* Both thumbs stay outside the combat plane on short landscape screens too. */
@media (max-height: 540px) and (min-aspect-ratio: 11/10) {
  body.touch .stage { width: 100vw; height: 100dvh; }
  body.touch #battle-dock { position: relative; flex: 0 0 82px; display: flex; align-items: center; gap: 20px; padding: 6px 14px calc(6px + var(--safe-b)); background: linear-gradient(#22171b,#0c080b); border-top: 1px solid var(--line); }
  body.touch .hud-bottom { flex: 0 0 auto; }
  body.touch #skills { gap: 5px; }
  body.touch .skill-btn { width: 54px; }
  body.touch .skill-face { width: 48px; height: 48px; }
  body.touch .sk-name { font-size: 9px; }
  body.touch #touch { flex: 1; padding: 0; margin: 0; gap: 16px; }
  body.touch #touch button { width: 50px; height: 50px; }
  body.touch #touch button.big { width: 60px; height: 60px; }
  body.touch #touch .tc-left, body.touch #touch .tc-right { gap: 6px; }
  body.touch #game { object-fit: fill; }
  body.touch .hp-wrap { max-width: 280px; }
  body.touch .hud-tools { margin-top: 4px; }
  #pause-overlay { gap: 6px; overflow-y: auto; padding: 12px; }
  #pause-overlay .btn { min-height: 42px; padding: 7px 18px; }
  #pause-overlay h3 { font-size: 25px; margin: 0; }
  #pause-overlay .hint { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; }
  .btn:hover, .hero-card.on, .attack-main.down, #touch button.down { transform: none; }
  #toast { transition: none; }
}
html.reduce-motion { --dur-fast: 0ms; --dur-base: 0ms; }
/* Secondary controls are still real touch targets, not 32px text links. */
body.touch .hud-tools .mini { min-width: 48px; min-height: 48px; }
