/* Mobile-first: designed for 360px-wide portrait, one thumb.
   Look: old home-computer screen. Black background, white text, inverse-video buttons. */

:root {
  --bg: #000000;
  --surface: #000000;
  --text: #f2f2f2;
  --muted: #9aa6b2;
  --accent: #7fd4ff;
  --danger: #ff5a5a;
  --warn: #ffd45a;
  --border: #f2f2f2;
  --border-dim: #4a5562;
  --disabled-text: #5c6670;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen[hidden] {
  display: none;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

h1 {
  font-size: 2rem;
  margin-top: 18vh;
}

h2 {
  font-size: 1.4rem;
}

.end-title {
  margin-top: 8vh;
}

p {
  margin: 0;
}

.center {
  margin: auto;
}

.version {
  text-align: center;
  font-size: 0.7rem;
  color: var(--disabled-text);
}

.tagline {
  color: var(--muted);
}

/* Buttons sit at the bottom of the screen, within thumb reach. */
.actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  min-height: 48px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active:not(:disabled) {
  background: var(--text);
  color: var(--bg);
}

.btn:focus-visible {
  outline: 3px dashed var(--accent);
  outline-offset: 3px;
}

/* Inverse video, like an old computer's highlighted menu item. */
.btn-primary {
  background: var(--text);
  color: var(--bg);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
}

.btn:disabled {
  color: var(--disabled-text);
  border-color: var(--border-dim);
  background: var(--bg);
  cursor: not-allowed;
}

.btn-quiet {
  align-self: center;
  min-height: 44px;
  min-width: 120px;
  padding: 8px 18px;
  font-weight: 400;
  border-color: var(--border-dim);
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 0;
}

.stats-3 {
  grid-template-columns: repeat(3, 1fr);
}

.stat {
  border: 1px solid var(--border-dim);
  padding: 3px 6px;
  min-width: 0;
}

.stat dt {
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Running low (warnAt / dangerAt in config.json). The inset shadow thickens
   the outline to 2px without changing the box size. */
.stat-warn {
  border-color: var(--warn);
  box-shadow: inset 0 0 0 1px var(--warn);
}

.stat-warn dd {
  color: var(--warn);
}

.stat-danger,
.stat-dead {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}

.stat-danger dd,
.stat-dead dd {
  color: var(--danger);
}

/* Extends into the side padding so a 360px phone still gets 2× pixels. */
.scene {
  display: flex;
  justify-content: center;
  margin: 0 -16px;
}

.scene canvas {
  display: block;
  max-width: 100%;
  border: 3px solid var(--border-dim);
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

#scene {
  width: 320px; /* replaced by render.js with a whole-number scale */
}

#arena {
  width: 320px;
  touch-action: none;
}

.progress {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Travel screen: fits one phone screen, no page scrolling ----------
   #app gets the "fit" class while the travel screen shows. The message box
   takes whatever height is left and scrolls inside itself if it's too long. */

#app.fit {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding-top: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

#app.fit .screen {
  gap: 8px;
  min-height: 0;
}

#app.fit .messages {
  flex: 1 1 auto;
  min-height: 3.5em;
  overflow-y: auto;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- Radio knob (turns the music on/off) ---------- */

.radio {
  flex: none;
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 48px;
  padding: 0 2px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.radio:focus-visible {
  outline: 3px dashed var(--accent);
  outline-offset: 2px;
}

.radio-mark {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--disabled-text);
}

/* The little tick marks between the labels and the knob */
.radio-off::after,
.radio-on::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 2px;
  background: currentColor;
  vertical-align: middle;
}

.radio-off::after {
  margin-left: 3px;
}

.radio-on::before {
  margin-right: 3px;
}

.radio:not(.is-on) .radio-off {
  color: var(--text);
}

.radio.is-on .radio-on {
  color: var(--danger);
  text-shadow: 0 0 4px var(--danger);
}

.knob {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, #dfe3e8 22%, #a3aab3 58%, #61676f 100%);
  box-shadow:
    0 0 0 2px #23262b,
    0 2px 5px rgba(0, 0, 0, 0.7),
    inset 0 -2px 3px rgba(0, 0, 0, 0.35);
}

/* Ridged rim */
.knob::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(0, 0, 0, 0.22) 0 5deg, transparent 5deg 10deg);
  -webkit-mask: radial-gradient(circle, transparent 66%, #000 68%);
  mask: radial-gradient(circle, transparent 66%, #000 68%);
}

.knob-text {
  position: relative;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1b1e23;
}

/* The pointer notch: left = OFF, right = ON */
.knob-pointer {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
  transition: transform 0.2s ease-out;
}

.knob-pointer::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 3px;
  width: 3px;
  height: 7px;
  margin-left: -1.5px;
  border-radius: 1px;
  background: #1b1e23;
}

.radio.is-on .knob-pointer {
  transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
  .knob-pointer {
    transition: none;
  }
}

/* Choice buttons: primary full width, the rest two per row. */
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choices .btn {
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.875rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.choices .btn-primary,
.choices .btn-wide {
  grid-column: 1 / -1;
}

.choices .btn-primary {
  font-size: 1rem;
}

.messages {
  border: 1px solid var(--border-dim);
  padding: 10px 12px;
  min-height: 5em;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-wrap: anywhere;
}

.event-text {
  font-weight: 700;
  color: var(--accent);
}

.summary {
  color: var(--muted);
}

.note {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- Hunt screen ---------- */

.battle-title {
  font-size: 1.1rem;
  color: var(--accent);
}

.banner {
  min-height: 1.45em;
  text-align: center;
  font-weight: 700;
  color: var(--warn);
}

.battle-controls {
  margin-top: -8px; /* tucked up close under the banner */
  display: flex;
  /* Both columns get the same height: d-pad and SHOOT share a top edge,
     SWITCH and Run away share a bottom edge. */
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dpad {
  position: relative;
  width: 128px;
  height: 128px;
  flex: none;
  border: 2px solid var(--border);
  border-radius: 50%;
  touch-action: none;
}

.dpad .arrow {
  position: absolute;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  pointer-events: none;
}

.dpad .up {
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
}

.dpad .down {
  bottom: 9px;
  left: 50%;
  transform: translateX(-50%);
}

.dpad .left {
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
}

.dpad .right {
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
}

.dpad[data-dir*="up"] .up,
.dpad[data-dir*="down"] .down,
.dpad[data-dir*="left"] .left,
.dpad[data-dir*="right"] .right {
  color: var(--text);
}

.battle-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.btn-shoot {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  touch-action: none;
}

.btn-switch {
  width: 128px;
  min-height: 44px;
  padding: 6px 10px;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
}

/* Hidden (but keeping its space) when only one brother is alive */
.btn-switch.is-hidden {
  visibility: hidden;
}

@media (hover: none) {
  .keys-hint {
    display: none;
  }
}
