:root {
  --ink: #2a1d14;
  --soft: #6b5646;
  --paper: #f6efe2;
  --paper-2: #efe4d0;
  --line: #e0d2ba;
  --wood: #6e432c;
  --wood-2: #8a5840;
  --moss: #2f6a45;
  --moss-2: #3e8558;
  --gold: #a56b12;
  --ember: #c4492a;
  --warn: #b67a16;
  --shadow: 0 18px 50px rgba(28, 16, 10, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(242, 166, 110, 0.45), transparent 55%),
    #1c1410;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.1rem;
  background: var(--moss);
  color: #f4fff6;
}

button:hover:not(:disabled) { background: var(--moss-2); }

button:disabled { opacity: 0.45; cursor: not-allowed; }

button.alt, button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost { color: #f6efe2; border-color: rgba(246, 239, 226, 0.35); }

button.danger { background: var(--ember); color: #fff8f4; }

button.brand {
  background: transparent;
  color: #f8efe2;
  padding: 0;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-size: 1.25rem;
}

button.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 0;
  background: rgba(20, 12, 8, 0.55);
}

h1, h2, .brand {
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 0;
}

h1 { font-size: clamp(2.4rem, 6vw, 4.6rem); }

p { margin: 0.4rem 0; }

#app { max-width: 1080px; margin: 0 auto; padding: 22px 16px 48px; }

#app:has(.ranch),
#app:has(.battle-screen) {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  overflow: hidden;
}
#app:has(.battle-screen) { overflow: auto; padding: 8px 16px 4px; }

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: lowercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--gold);
}

.lede { font-size: 1.12rem; max-width: 38rem; }

.quiet { color: var(--soft); }

.fine { color: rgba(246, 239, 226, 0.72); font-size: 0.85rem; max-width: 34rem; }

.warning {
  background: #f8e2c8;
  color: #7a3418;
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
}

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.row.tight { margin-top: 6px; }
.row.wrap { display: flex; flex-wrap: wrap; gap: 8px; }

.title-screen, .hatch-screen, .hall, .farewell {
  color: #f6efe2;
  min-height: calc(100vh - 70px);
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 8px;
}

.title-screen { justify-items: center; text-align: center; }
.title-screen .lede, .title-screen .fine { margin-inline: auto; }
.parade, .title-actions { justify-content: center; }

.title-screen h1, .hatch-card h1, .hall h1, .farewell h1 { color: #f8f1e6; }

.parade { display: flex; gap: 8px; margin: 10px 0 16px; }
.parade .msvg, .parade svg { width: 150px; height: auto; }

.title-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 18px; }

.title-screen button.alt, .hatch-screen button.alt, .hall button.ghost, .farewell button.alt {
  color: #f6efe2;
  border-color: rgba(246, 239, 226, 0.35);
}

.hatch-card, .panel, .dialog, .log, .endcard {
  background: var(--paper);
  color: var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.hatch-card { padding: 28px 26px 24px; max-width: 520px; }
.hatch-card h1, .panel h2, .dialog h2, .reveal-copy h1, .farewell h1, .hall h1 { color: var(--ink); }
.farewell .panel h1 { color: var(--ink); }
.hall h1 { color: #f8f1e6; }

.farewell { grid-template-columns: 1.1fr 0.9fr; gap: 16px; align-items: stretch; }
.farewell .stage { min-height: 420px; border-radius: 22px; }
.farewell .panel, .reveal-copy { padding: 26px; }

label { display: grid; gap: 6px; font-size: 0.92rem; margin: 14px 0; }
input {
  border: 1px solid var(--line);
  background: #fffaf3;
  border-radius: 12px;
  padding: 0.75rem 0.8rem;
}

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  color: #f6efe2;
  margin-bottom: 12px;
}
.cal, .gold { margin: 0; }
.gold { margin-left: auto; font-variant-numeric: tabular-nums; }
.topbar .ghost { padding: 0.4rem 0.7rem; }

.layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 12px; }

.ranch, .battle-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.battle-screen { gap: 6px; }
.ranch .topbar, .battle-screen .topbar { margin-bottom: 0; }
.ranch .layout { flex: 1; min-height: 0; }
.ranch .panel { min-height: 0; overflow: auto; }
.ranch .stage { min-height: 0; height: 100%; }
.panel { padding: 16px 16px 12px; }
.who { display: flex; justify-content: space-between; gap: 12px; }
.rating { font-size: 0.92rem; }

.meter { margin: 7px 0; }
.sheet {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
  margin-top: 8px;
}
.sheet .meter { margin: 3px 0; }
.sheet .bar { height: 6px; }
.sheet .meter-top { font-size: 0.75rem; }
.meter-top { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--soft); }
.meter-top b { color: var(--ink); font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: #e5d8c2; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--moss); border-radius: inherit; transition: width 0.35s ease; }
.bar.hp > span { background: #c4492a; }
.bar.guts > span { background: #c8962e; transition: width 0.08s linear; }
.regen { margin: 2px 0 0; text-align: center; font-size: 0.75rem; color: #3d2b20; }
.battle-hint { margin: 8px 0; text-align: center; }
.meter.bad .bar > span { background: var(--ember); }
.meter.warn .bar > span { background: var(--warn); }
.meter.good .bar > span { background: var(--moss); }

.candle {
  width: 18px;
  height: 72px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fffaf3;
  display: flex;
  align-items: flex-end;
  padding: 3px;
}
.candle span {
  display: block;
  width: 100%;
  background: linear-gradient(#f3d27a, #e07a32);
  border-radius: 7px;
}

.stage {
  position: relative;
  min-height: 340px;
  border-radius: 22px;
  overflow: hidden;
  background: #e7b48a;
  box-shadow: var(--shadow);
}
.scenery { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage-monster { position: absolute; left: 50%; bottom: 18px; width: min(280px, 70%); transform: translateX(-50%); }
.stage-copy {
  position: relative;
  z-index: 1;
  margin: 22px;
  max-width: 420px;
  padding: 18px;
  color: var(--ink);
  background: rgba(246, 239, 226, 0.94);
  border-radius: 18px;
}
.sky-night .stage-copy, .sky-night .bubble { color: var(--ink); }
.bubble {
  position: absolute;
  z-index: 1;
  left: 22px;
  top: 18px;
  max-width: 220px;
  background: rgba(246, 239, 226, 0.94);
  color: var(--ink);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 12px;
}
.week-pips { position: absolute; z-index: 1; right: 16px; top: 16px; display: flex; gap: 6px; }
.week-pips i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,0.35); display: block; }
.week-pips i.on { background: #fff8ea; }

.msvg { width: 100%; height: auto; display: block; }
.sprite-bob { animation: bob 2.8s ease-in-out infinite; }
.flip { transform: scaleX(-1); }
.mood-old { filter: saturate(0.72); }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 236, 210, 0.08), transparent 30%),
    #5a3424;
  box-shadow: inset 0 0 0 1px rgba(255, 220, 180, 0.18), var(--shadow);
}
.actions .act {
  border-radius: 16px;
  min-height: 64px;
  padding: 0.55rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  text-align: left;
  gap: 3px;
  background: linear-gradient(180deg, #fffaf3, #f3e6d2);
  color: var(--ink);
  border: 1px solid rgba(90, 52, 36, 0.18);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}
.actions .act strong { font-family: Palatino, Georgia, serif; font-size: 1.05rem; }
.actions .act small { color: var(--soft); }
.actions .act:hover:not(:disabled) { border-color: #c9b496; background: #fffaf3; transform: translateY(-1px); }
.actions .act[data-act="preview-spar"],
.actions .act[data-act="preview-cup"] { background: linear-gradient(180deg, #fff6ea, #f6d7b4); }

.log { margin-top: 12px; padding: 12px 14px; background: #2a211b; color: #f3e6d4; box-shadow: none; }
.ranch .actions, .ranch .log { margin-top: 0; }
.ranch .log { max-height: 4.4rem; overflow: auto; }
.log ul { list-style: none; margin: 0; padding: 0; }
.log li + li { color: #cbbba6; margin-top: 4px; }

.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; }
.dialog { position: relative; z-index: 1; width: min(560px, 100%); max-height: min(86vh, 820px); overflow: auto; padding: 20px; }
.dialog.wide { width: min(760px, 100%); }
.dialog h2 { font-size: 1.8rem; margin-bottom: 8px; }

.help-list { margin: 0 0 12px; padding-left: 1.1rem; }
.help-list li { margin: 0.35rem 0; }

.drill-grid, .moves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.drill, .move {
  border-radius: 14px;
  background: #fffaf3;
  color: var(--ink);
  border: 1px solid var(--line);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drill b { color: var(--moss); }
.move:hover:not(:disabled),
.drill:hover:not(:disabled) { background: #fff; color: var(--ink); }
.move { padding: 0.35rem 0.65rem; }
.move.kind-push:hover:not(:disabled) { background: #fff1e4; }

.item-list { display: grid; gap: 8px; }
.item, .stable-card, .hall-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffaf3;
  color: var(--ink);
}
.item p, .item small, .stable-card small { color: var(--soft); }
.item-actions, .stable-card .row { display: flex; gap: 6px; }
.stable-grid { display: grid; gap: 8px; }
.stable-card { grid-template-columns: 1fr; }
.stable-card.picked { border-color: var(--moss); box-shadow: inset 0 0 0 1px var(--moss); }
.pick {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  background: transparent;
  color: var(--ink);
  border-radius: 12px;
  text-align: left;
  padding: 0;
}
.pick .sprite, .stable-card .msvg, .hall-card .msvg { width: 92px; }
.pick span { display: grid; }

.preview-row { display: flex; gap: 12px; align-items: center; }
.preview-row .sprite { width: 160px; }

.reveal-screen { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.reveal-stage { min-height: 520px; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.mini-stats span { background: #fffaf3; border-radius: 999px; padding: 4px 8px; font-size: 0.82rem; }

.disc {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(from 30deg, #f3d2b0, #d9f0ff, #f7c6d8, #d7f3d2, #ffe6a8, #f3d2b0);
  box-shadow: inset 0 0 0 8px rgba(255,255,255,0.35), 0 8px 18px rgba(0,0,0,0.12);
  margin-bottom: 8px;
}
.disc span {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #2a2118;
  color: #f6efe2;
  font-size: 0.58rem;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 4px;
  overflow: hidden;
}

.battle-screen { color: #f6efe2; }
.battle-screen .arena {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  overflow: visible;
}
.battle-screen .ring { display: flex; flex-direction: column; }
.battle-screen .range-lane { height: 110px; min-height: 110px; }
.battle-screen .deck,
.battle-screen .battle-log,
.battle-screen .endcard,
.battle-screen .warning { flex: none; }
.arena {
  background:
    radial-gradient(120% 80% at 50% 0%, #f6c89a 0%, #e08a62 42%, transparent 43%),
    linear-gradient(#c46a45 0 46%, #3f6b45 46% 62%, #2c4c34 62% 100%);
  border-radius: 26px;
  padding: 10px 12px 8px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 236, 214, 0.2);
}
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: stretch;
}
.hud-card {
  background: rgba(246, 239, 226, 0.94);
  color: var(--ink);
  border-radius: 18px;
  padding: 8px 12px 6px;
  box-shadow: 0 10px 24px rgba(28, 16, 10, 0.16);
}
.hud-card .meter { margin: 4px 0; }
.hud-card.foe { text-align: right; }
.hud-card.foe h2, .hud-card.foe .eyebrow, .hud-card.foe .regen { text-align: right; }
.hud-card h2 { font-size: 1.45rem; }
.hud-mid {
  display: grid;
  align-content: center;
  justify-items: center;
  min-width: 148px;
  text-align: center;
}
.range-readout {
  margin: 0;
  color: #fff8ee;
  font-family: Palatino, Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.1;
  text-shadow: 0 2px 0 rgba(42, 20, 10, 0.25);
}
.range-readout b { font-weight: 600; }
.proximity {
  display: none;
  margin: 4px 0 0;
  color: #fff1c9;
  background: rgba(125, 30, 20, 0.82);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
}
.range-readout.pushable + .proximity { display: inline-block; }
.edge-note {
  display: none;
  margin: 4px 0 0;
  color: #fff1c9;
  background: rgba(42, 24, 14, 0.78);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
}
.hud-mid.walled .edge-note { display: inline-block; }
.ring { margin-top: 8px; }
.rail {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 0;
}
.band {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 248, 238, 0.78);
  background: rgba(20, 12, 8, 0.22);
  border-radius: 999px;
  padding: 3px 10px;
}
.band.on { color: #2a1d14; background: #ffe08a; font-weight: 700; }
.range-lane {
  position: relative;
  height: 110px;
  margin: 0 4%;
}
.range-lane::before { content: none; }
.wall {
  position: absolute;
  bottom: 0;
  z-index: 1;
  width: 18px;
  height: 78%;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 228, 196, 0.45), transparent 42%),
    linear-gradient(#d7a36e, #6a3b24);
  border-radius: 4px 4px 2px 2px;
  box-shadow: 0 8px 0 rgba(20, 12, 8, 0.28);
}
.wall.left { left: var(--wall-left); transform: translateX(-75%); }
.wall.right { left: var(--wall-right); transform: translateX(-25%); }
.range-lane .fighter {
  position: absolute;
  width: min(118px, 22%);
  bottom: 4px;
  left: var(--spot);
  transform: translateX(-50%);
  transition: left 0.08s linear;
  filter: drop-shadow(0 10px 0 rgba(20, 12, 8, 0.18));
  z-index: 2;
}
.fighter.dodging .sprite-bob { animation: dodge-slip 0.36s ease; }
@keyframes dodge-slip {
  40% { transform: translateY(-18px) rotate(-7deg); }
  100% { transform: none; }
}
.deck {
  margin-top: 0;
  padding: 8px 10px 2px;
  border-radius: 22px;
  background: rgba(246, 239, 226, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.deck-travel, .deck-util {
  display: grid;
  gap: 6px;
}
.deck-travel { grid-template-columns: 1fr 1.15fr 1fr; }
.deck-util { grid-template-columns: 1fr 1fr; margin-top: 6px; }
.deck .battle-hint { color: var(--soft); margin: 4px 0; }
.locked-line {
  margin: 4px 2px 0;
  color: var(--soft);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.moves { margin-top: 0; }
.move.armed { border-color: #2f6a45; box-shadow: inset 0 0 0 1px #2f6a45; background: #f3faf4; }
.move.kind-step, .move.kind-push, .move.kind-guard, .move.kind-focus { background: #fffaf3; }
.move.kind-push:not(:disabled) { background: #fff1e4; border-color: #e07a32; }
.move.range-jauh { border-top: 3px solid #6d8fbf; }
.move.range-sedang { border-top: 3px solid #d2a04a; }
.move.range-pendek { border-top: 3px solid #3e8558; }
.move.range-dekat { border-top: 3px solid #c4492a; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.chips span {
  background: #fffaf3;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.75rem;
}
.drill .row button { padding: 0.45rem 0.7rem; font-size: 0.82rem; }
.fighter { position: relative; text-align: center; }
.fighter h2 { font-size: 1.5rem; color: #2a1d14; }
.fighter .meter-top { justify-content: flex-start; gap: 8px; }
.fighter .quiet, .fighter .meter-top { color: #3d2b20; }
.fighter .meter-top b { color: #2a1d14; }
.fighter .sprite { width: min(230px, 100%); margin: 0 auto; }
.floater {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  font-family: Palatino, Georgia, serif;
  font-size: 1.6rem;
  animation: floatUp 0.8s ease forwards;
  pointer-events: none;
}
.floater.hurt { color: #7d1e14; }
.floater.heal { color: #1d5a34; }
.floater.miss { color: #5c4a3a; font-size: 1.1rem; }
@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, 8px); }
  to { opacity: 0; transform: translate(-50%, -26px); }
}
.shake { animation: shake 0.35s linear; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.battle-log {
  margin: 0;
  max-height: 2.7rem;
  overflow: auto;
  font-size: 0.88rem;
  padding: 4px 12px;
  background: rgba(28, 18, 12, 0.55);
  border-radius: 14px;
  color: #f6efe2;
}
.battle-log ul { margin: 0; padding-left: 1rem; }
.moves { margin-top: 0; }
.endcard { margin-top: 0; padding: 16px; }
.endcard h2 { font-size: 2rem; }

.hall-list { display: grid; gap: 10px; width: min(720px, 100%); }
.hall-card { grid-template-columns: 110px 1fr; }
.hall .back, .hatch-screen .back { margin-bottom: 8px; }

.back { justify-self: start; }

@media (max-width: 800px) {
  #app:has(.ranch) {
    height: auto;
    overflow: visible;
    padding: 12px 12px calc(28px + env(safe-area-inset-bottom));
  }
  .layout, .reveal-screen, .farewell, .actions, .arena, .drill-grid, .moves { grid-template-columns: 1fr 1fr; }
  .layout, .reveal-screen, .farewell { grid-template-columns: 1fr; }
  .ranch { flex: none; }
  .ranch .layout { flex: none; }
  .ranch .panel { overflow: visible; }
  .ranch .stage {
    order: -1;
    height: 260px;
    min-height: 260px;
  }
  .sheet { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr 1fr; }
  .ranch .log { max-height: none; }
  .parade svg, .parade .msvg { width: 96px; }
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
  }
  .topbar .brand { grid-column: 1 / -1; justify-self: start; }
  .topbar .ghost { justify-self: start; width: auto; }
  .gold { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sprite-bob, .floater, .shake, .bar > span { animation: none; transition: none; }
}
