:root {
  --bg: #140e09;
  --bg-2: #1c140d;
  --paper: #efe0c2;
  --paper-2: #e6d2a6;
  --ink: #24180e;
  --ink-soft: #5c4630;
  --brass: #c9a45a;
  --brass-dim: #8a7038;
  --rust: #9a3b22;
  --sage: #6d7a48;
  --good: #3f6b3a;
  --bad: #8f2d22;
  --line: #c4ae82;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: "Source Serif 4", Palatino, "Palatino Linotype", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
}

.site-back {
  flex: 0 0 auto;
  z-index: 50;
  padding: 8px 16px;
  background: #08151b;
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

.site-back a {
  color: #66c6cb;
  text-decoration: none;
}

#app {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  appearance: none;
  border: 0;
  cursor: pointer;
  color: inherit;
}

input {
  user-select: text;
  font-size: 16px;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  animation: fade .28s ease;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

h1, h2, h3 {
  font-family: Cinzel, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 0;
}

.muted { color: var(--ink-soft); }
.gold { color: var(--brass); }
.bad { color: #e07060; }
.good { color: #9dbe73; }

/* ----- Title ----- */
.title-screen {
  background: #0c0805 center/cover no-repeat;
}

.title-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(20,14,9,.15) 0%, rgba(20,14,9,.2) 38%, rgba(20,14,9,.92) 72%, #140e09 100%);
  pointer-events: none;
}

.title-copy {
  position: relative;
  z-index: 1;
  margin-top: auto;
  padding: 0 22px calc(18px + var(--safe-b));
}

.kicker {
  font-family: Cinzel, serif;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--brass);
  margin-bottom: 8px;
}

.title-copy h1 {
  font-size: clamp(34px, 10vw, 46px);
  line-height: 0.95;
  text-shadow: 0 4px 24px rgba(0,0,0,.7);
}

.title-copy p.lead {
  margin: 12px 0 18px;
  color: #d9c8a3;
  font-size: 15px;
  line-height: 1.45;
  max-width: 28em;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

/* ----- Buttons ----- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--brass);
  color: var(--ink);
  font-family: Cinzel, serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  box-shadow: 0 2px 0 #6d5420;
}

.btn:active { transform: translateY(1px); box-shadow: none; }

.btn.ghost {
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(201, 164, 90, 0.45);
  box-shadow: none;
}

.btn.danger {
  background: var(--rust);
  color: #f6e7d0;
  box-shadow: 0 2px 0 #5c1c10;
}

.btn.small {
  min-height: 40px;
  font-size: 12px;
  padding: 8px 12px;
}

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ----- Setup cards ----- */
.pad {
  padding: 18px 18px 12px;
}

.paper {
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--ink);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.paper h2 { font-size: 20px; margin-bottom: 6px; }
.paper p { margin: 0 0 10px; line-height: 1.45; }

.choice {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(36, 24, 14, 0.06);
  border: 1px solid rgba(36, 24, 14, 0.12);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--ink);
  margin-bottom: 10px;
}

.choice:active { background: rgba(36, 24, 14, 0.12); }
.choice b {
  display: block;
  font-family: Cinzel, serif;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.choice span { font-size: 14px; color: var(--ink-soft); }
.choice em {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: 13px;
  color: #6a4b18;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input {
  width: 100%;
  border: 1px solid #cbb892;
  background: #f7edd4;
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
}

/* ----- Trail HUD ----- */
.trail {
  background: #120d08;
}

.scene {
  position: relative;
  height: 28vh;
  min-height: 150px;
  max-height: 240px;
  background: #2a1c10 center/cover no-repeat;
  flex-shrink: 0;
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(20,14,9,.15), transparent 40%, #120d08);
}

.hud {
  position: absolute;
  left: 12px;
  right: 12px;
  top: calc(10px + var(--safe-t));
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.pill {
  background: rgba(20, 14, 9, 0.72);
  border: 1px solid rgba(201, 164, 90, 0.28);
  border-radius: 999px;
  padding: 5px 10px;
  backdrop-filter: blur(6px);
}

.trail-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 12px;
}

.place {
  font-family: Cinzel, serif;
  font-size: 20px;
  margin: 0 0 4px;
}

.subplace {
  margin: 0 0 10px;
  color: #cbb892;
  font-size: 13px;
}

.progress {
  height: 6px;
  background: #2a2116;
  border-radius: 99px;
  overflow: hidden;
  margin: 8px 0 14px;
  border: 1px solid #3a2d1e;
}

.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8a7038, var(--brass));
  border-radius: 99px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  background: #1c1510;
  border: 1px solid #32261a;
  border-radius: 10px;
  padding: 8px 8px 7px;
  text-align: center;
}

.stat b {
  display: block;
  font-family: Cinzel, serif;
  font-size: 16px;
  color: var(--brass);
}

.stat span {
  font-size: 11px;
  color: #b9a37d;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.party {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.member {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: #1c1510;
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid #2c2218;
}

.member .nm { font-size: 14px; }
.member .st { font-size: 12px; color: #b9a37d; }

.hp {
  height: 6px;
  background: #2a2116;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 5px;
}

.hp > i {
  display: block;
  height: 100%;
  background: #6d7a48;
}

.hp.poor > i { background: #c9a45a; }
.hp.bad > i { background: #9a3b22; }

.log {
  font-size: 13px;
  color: #cbb892;
  line-height: 1.4;
  margin: 0 0 8px;
  min-height: 2.8em;
}

.dock {
  flex-shrink: 0;
  padding: 10px 12px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, transparent, #120d08 18%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ----- Store ----- */
.store-top {
  padding: 16px 16px 8px;
}

.store-top h2 { font-size: 22px; }
.keeper { color: #d9c8a3; font-size: 14px; line-height: 1.45; margin: 8px 0 0; }

.good {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  padding: 12px 0;
  border-bottom: 1px solid #2c2218;
}

.good .nm { font-family: Cinzel, serif; font-size: 15px; }
.good .meta { font-size: 12px; color: #b9a37d; }
.good.out { opacity: 0.72; }
.good .stock-out { color: #e07060; }
.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #2a2116;
  border: 1px solid #4a3a24;
  color: var(--brass);
  font-size: 20px;
  line-height: 1;
}
.stepper button:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.stepper .qty {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cashbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 2px 4px;
  font-size: 14px;
}

/* ----- Modal sheet ----- */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 3, 0.62);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  padding: 12px 12px calc(12px + var(--safe-b));
  animation: fade .2s ease;
}

.sheet {
  width: 100%;
  max-height: 86%;
  overflow: auto;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--ink);
  border-radius: 16px 16px 12px 12px;
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
}

.sheet h2 { font-size: 20px; margin-bottom: 8px; }
.sheet p { margin: 0 0 10px; line-height: 1.45; }
.sheet .stack { margin-top: 8px; }
.sheet .btn { color: var(--ink); }
.sheet .btn.ghost {
  color: var(--ink);
  border-color: rgba(36,24,14,.25);
}

.sheet .choice { margin-bottom: 8px; }

/* ----- Hunt ----- */
.hunt-art {
  height: 26vh;
  min-height: 140px;
  background: center/cover no-repeat;
  position: relative;
}

.hunt-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, #140e09);
}

/* ----- Map ----- */
.map-list { list-style: none; margin: 0; padding: 0; }
.map-list li {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid rgba(36,24,14,.1);
  font-size: 14px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b9a37d;
  margin-top: 4px;
}

.dot.here { background: var(--brass); box-shadow: 0 0 0 4px rgba(201,164,90,.25); }
.dot.done { background: var(--good); }

/* ----- End ----- */
.end-screen {
  background: #0c0805 center/cover no-repeat;
}

.end-screen .title-copy { padding-bottom: calc(22px + var(--safe-b)); }

.scorebox {
  background: rgba(20,14,9,.72);
  border: 1px solid rgba(201,164,90,.35);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0 16px;
}

.scorebox b {
  font-family: Cinzel, serif;
  font-size: 28px;
  color: var(--brass);
}

/* ----- Help ----- */
.help p { color: #d9c8a3; line-height: 1.5; }
.help li { margin: 0 0 8px; color: #d9c8a3; }

@media (min-height: 780px) {
  .scene { height: 32vh; }
}

@media (max-height: 640px) {
  .scene { height: 22vh; min-height: 120px; }
  .title-copy h1 { font-size: 32px; }
}

/* ----- Cut-scene overlay ----- */
.cutscene {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: #0c0805;
  opacity: 0;
  transition: opacity .35s ease;
}
.cutscene.show { opacity: 1; }
.cutscene iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.cutscene .skip {
  position: absolute;
  right: calc(12px + var(--safe-r));
  bottom: calc(12px + var(--safe-b));
  z-index: 2;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(20, 14, 9, 0.7);
  border: 1px solid rgba(201, 164, 90, 0.4);
  color: var(--paper);
  font-family: Cinzel, serif;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
}

/* ----- Store buy/sell toggle ----- */
.mode-toggle {
  display: inline-flex;
  gap: 6px;
  margin-top: 10px;
  background: rgba(20, 14, 9, 0.4);
  border: 1px solid rgba(201, 164, 90, 0.3);
  border-radius: 999px;
  padding: 3px;
}
.mode-toggle .mode {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 7px 18px;
  border-radius: 999px;
  background: transparent;
  color: var(--paper);
  font-family: Cinzel, serif;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.mode-toggle .mode.on {
  background: var(--brass);
  color: var(--ink);
  box-shadow: 0 2px 0 #6d5420;
}
