:root {
  --bg: #12160f;
  --raise: #1c2418;
  --line: #31402c;
  --ink: #f3efe2;
  --muted: #b7c0aa;
  --gold: #e0b15a;
  --ok: #8fce7a;
  --bad: #e07a6a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body.playing { overflow: hidden; }

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

.screen {
  min-height: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: calc(1.25rem + var(--safe-top)) 1.1rem calc(1.5rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.hero h1 {
  margin: 0.15rem 0 0.45rem;
  font-size: 2.7rem;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

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

.lede, .detail { margin: 0; color: var(--muted); }

.panel {
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  padding: 1rem;
}

label { display: block; font-weight: 700; margin-bottom: 0.4rem; }

input {
  width: 100%;
  min-height: 48px;
  border-radius: 0.8rem;
  border: 1px solid var(--line);
  background: #12180f;
  padding: 0 0.9rem;
  font-size: 16px;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 0.8rem;
  background: var(--gold);
  color: #1a1408;
  font-weight: 750;
}

button:active { transform: translateY(1px); }

#play { width: 100%; margin-top: 0.8rem; }

.detail { margin-top: 0.8rem; }

.game {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  touch-action: none;
}

.hud {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr;
  gap: 0.4rem;
  padding: calc(0.35rem + var(--safe-top)) 0.7rem 0.4rem;
  background: #10150e;
  border-bottom: 1px solid var(--line);
}

.stat { min-height: 48px; display: flex; flex-direction: column; justify-content: center; }
.stat .k { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.stat strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--ok); font-size: 0.75rem; min-height: 0.9rem; }

.stage { position: relative; min-height: 0; }

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.banner, .toast, .info, #info {
  margin: 0;
}

.banner {
  position: absolute;
  left: 0.7rem;
  right: 0.7rem;
  top: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.8rem;
  background: rgba(18, 22, 15, 0.88);
  border: 1px solid var(--line);
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 0.7rem;
  right: 0.7rem;
  bottom: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.8rem;
  background: rgba(90, 32, 28, 0.94);
  pointer-events: none;
}

.bubble, .request {
  position: absolute;
  z-index: 2;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.7rem;
  touch-action: manipulation;
}

.bubble { width: min(16rem, calc(100% - 1.4rem)); }
.bubble p { margin: 0 0 0.45rem; font-weight: 700; }
.bubble button, .request button { width: 100%; margin-top: 0.4rem; }

.request {
  left: 0.7rem;
  right: 0.7rem;
  top: 3.2rem;
}
.request p { margin: 0 0 0.35rem; }
.request-actions { display: flex; gap: 0.45rem; }
.request-actions button { flex: 1; }
#refuse { background: #3a2a28; color: var(--ink); }

.dock {
  padding: 0.45rem 0.7rem calc(0.5rem + var(--safe-bottom));
  background: #10150e;
  border-top: 1px solid var(--line);
  touch-action: manipulation;
}

#info { color: var(--muted); font-size: 0.92rem; min-height: 1.3rem; }

.ratios, .modes { display: flex; gap: 0.45rem; margin-top: 0.4rem; }
.ratios button, .modes button {
  flex: 1;
  background: #2a3326;
  color: var(--ink);
}
.ratios button.on, .modes button.on { background: var(--gold); color: #1a1408; }
#cancel { width: 100%; margin-top: 0.4rem; background: var(--bad); color: #1a100e; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(10, 12, 8, 0.72);
  touch-action: manipulation;
}
.overlay .panel { width: min(22rem, 100%); }
.overlay h2 { margin: 0 0 0.4rem; }
.overlay p { color: var(--muted); }
.overlay button { width: 100%; margin-top: 0.8rem; }
