:root {
  color-scheme: dark;
  --ink: #f6efe2;
  --muted: #d9cbb6;
  --brass: #e0b15d;
  --brass-deep: #8a5a22;
  --panel: rgba(10, 22, 28, 0.84);
  --line: rgba(224, 177, 93, 0.72);
  --danger: #c44938;
  --hp: #e0b15d;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-right: max(14px, env(safe-area-inset-right));
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
  --safe-left: max(14px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #143044;
  color: var(--ink);
  font-family: var(--sans);
  touch-action: none;
}

button, input { font: inherit; }

button {
  cursor: pointer;
  min-height: 44px;
}

button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(6, 12, 16, 0.45) 100%);
  transition: background 120ms linear;
}

.is-hurt #vignette {
  background: radial-gradient(ellipse at center, transparent 35%, rgba(120, 28, 20, 0.55) 100%);
}

#app { position: fixed; inset: 0; pointer-events: none; }

.panel, #fire, .top-actions button, #banner, #toast {
  pointer-events: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

h1, h2, .eyebrow {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0;
}

h1 { font-size: clamp(40px, 8vw, 64px); letter-spacing: -0.03em; line-height: 0.92; }
h2 { font-size: clamp(32px, 6vw, 48px); letter-spacing: -0.03em; }

.eyebrow {
  color: var(--brass);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  margin-bottom: 6px;
}

.lede, .fine, .meta, .hint { color: var(--muted); }
.lede { font-size: 17px; line-height: 1.4; margin: 10px 0 16px; }
.fine, .meta, .hint { font-size: 13px; line-height: 1.4; }
.meta { margin: 12px 0 0; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button { flex: 1 1 140px; }

.primary, .ghost {
  border-radius: 4px;
  padding: 12px 14px;
}

.primary {
  background: linear-gradient(#f0c57a, var(--brass) 40%, #b9843a);
  color: #24180d;
  border: 1px solid #f3ddb0;
  font-weight: 700;
}

.ghost {
  background: rgba(255, 248, 236, 0.04);
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost[aria-pressed="true"] {
  background: rgba(224, 177, 93, 0.22);
  color: #fff8ea;
}

.slim { min-height: 40px; padding: 8px 10px; }

#title-card {
  position: absolute;
  left: var(--safe-left);
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  max-width: 460px;
  margin: 0 auto;
  padding: 22px 22px 18px;
}

#combat-hud {
  position: absolute;
  inset: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip, .hp {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  min-height: 42px;
}

.chip {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
}

.chip strong { font-variant-numeric: tabular-nums; font-size: 18px; }

.hp {
  position: relative;
  flex: 1 1 140px;
  overflow: hidden;
  min-width: 120px;
}

#hp-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #2f6b4a, #e0b15d);
  transform-origin: left center;
  transform: scaleX(1);
}

#hp-fill[data-low="true"] { background: var(--danger); }

#hp-text {
  position: relative;
  display: grid;
  place-items: center;
  height: 42px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.top-actions { display: flex; gap: 6px; margin-left: auto; }

.hint {
  position: absolute;
  left: var(--safe-left);
  bottom: var(--safe-bottom);
  max-width: min(420px, calc(100% - 130px));
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

#fire {
  position: absolute;
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 0;
  color: #24180d;
  font-family: var(--serif);
  font-size: 22px;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 244, 220, 0.95), rgba(224, 177, 93, 0.2) 46%, rgba(20, 14, 8, 0.15) 47%),
    conic-gradient(#f0c57a calc(var(--charge) * 1turn), rgba(255, 248, 236, 0.16) 0);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35), inset 0 0 0 2px rgba(90, 52, 16, 0.45);
}

#fire span { display: block; margin-top: 28px; }

#fire:active { transform: translateY(1px) scale(0.98); }
#fire:disabled { filter: saturate(0.4); }

.modal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 28px));
  padding: 22px;
}

.modal p { line-height: 1.4; }

.banner, .toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  max-width: calc(100% - 32px);
  text-align: center;
}

.banner { top: calc(var(--safe-top) + 72px); font-family: var(--serif); font-size: 22px; }
.toast { bottom: calc(var(--safe-bottom) + 112px); font-size: 14px; }

#webgl-fail {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: #102028;
  padding: 20px;
}

#webgl-fail[hidden], [hidden] { display: none !important; }

#webgl-fail .panel { padding: 24px; max-width: 460px; }

@media (orientation: landscape) and (max-height: 520px) {
  #title-card {
    top: var(--safe-top);
    bottom: auto;
    right: auto;
    width: min(400px, 48vw);
    margin: 0;
    padding: 14px;
  }
  h1 { font-size: 36px; }
  .lede { display: none; }
  #fire { width: 78px; height: 78px; font-size: 18px; }
  #fire span { margin-top: 22px; }
  .hint { display: none; }
  .banner { font-size: 18px; }
}

@media (max-width: 720px) {
  .topbar {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas: "chip actions" "hp hp";
    align-items: stretch;
  }
  .chip { grid-area: chip; }
  .hp { grid-area: hp; }
  .top-actions { grid-area: actions; margin-left: 0; justify-content: flex-end; }
  .banner { top: calc(var(--safe-top) + 104px); max-width: calc(100% - 28px); }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #hp-fill, #vignette, #fire { transition: none; }
}
