:root {
  --bg: #14110f;
  --panel: #221c18;
  --panel-2: #2d2520;
  --line: #43372d;
  --text: #f3ece4;
  --muted: #b3a597;
  --accent: #ff5a3d;
  --accent-2: #ffb547;
  --good: #6bd66b;
  --bad: #ff5a4a;
  --radius: 10px;
  --header-h: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent-2);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.site-logo {
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  color: var(--text);
}

.site-logo span {
  color: var(--accent-2);
  font-weight: 600;
  font-size: 13px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.page {
  padding: 8px 8px 40px;
}

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: min(1280px, calc((100vh - var(--header-h) - 28px) * 1.7778));
  max-width: min(1280px, calc((100dvh - var(--header-h) - 28px) * 1.7778));
  min-width: min(100%, 300px);
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
}

.stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage.aiming > canvas {
  cursor: none;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

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

.hud-row.bottom {
  align-items: flex-end;
}

.hud-box {
  background: rgba(15, 12, 10, 0.55);
  border-radius: 8px;
  padding: 5px 9px;
}

.hud-box.center {
  text-align: center;
}

.hud-box.right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-stage {
  font-weight: 800;
  color: var(--accent-2);
  font-size: 13px;
  letter-spacing: 0.5px;
}

.hud-weapon {
  font-size: 13px;
  color: var(--text);
}

.hud-score {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hud-streak {
  font-size: 12px;
  color: var(--accent-2);
  min-height: 14px;
}

.nerves {
  display: flex;
  gap: 4px;
}

.nerve {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5);
}

.nerve.lost {
  background: #3a3431;
}

.hud-buttons {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

.icon-btn {
  background: rgba(40, 32, 27, 0.9);
  border: 1px solid var(--line);
  border-radius: 7px;
  min-width: 34px;
  height: 30px;
  cursor: pointer;
  font-size: 13px;
}

.wind {
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.wind-arrow {
  display: inline-block;
  color: #7fd0ff;
}

.dist {
  font-size: 12px;
  color: var(--muted);
}

.breath-box {
  min-width: 150px;
  flex: 0 1 220px;
}

.breath-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

.breath-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 5px;
  overflow: hidden;
}

.breath-fill {
  height: 100%;
  width: 100%;
  background: #7fd0ff;
  transition: background 0.2s;
}

.breath-fill.strain {
  background: var(--bad);
}

.touch-controls {
  display: none;
  gap: 10px;
  pointer-events: auto;
}

.touch .touch-controls {
  display: flex;
}

.touch-btn {
  border-radius: 50%;
  width: 74px;
  height: 74px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  font-weight: 800;
  font-size: 13px;
  line-height: 1.1;
  touch-action: none;
}

.touch-btn.hold {
  background: rgba(40, 110, 160, 0.55);
}

.touch-btn.hold.on {
  background: rgba(60, 160, 230, 0.85);
}

.touch-btn.fire {
  background: rgba(200, 40, 30, 0.75);
  font-size: 16px;
}

.flash-msg {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: clamp(20px, 4vw, 38px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  text-align: center;
  white-space: nowrap;
}

.flash-msg.show {
  opacity: 1;
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(8, 6, 5, 0.55);
  overflow: auto;
}

.overlay.show {
  display: flex;
}

.overlay.clear {
  background: transparent;
  pointer-events: none;
}

@media (min-width: 800px) {
  .overlay.clear {
    justify-content: flex-end;
    align-items: flex-start;
  }
  .overlay.clear .card {
    width: min(430px, 46%);
  }
}

.card {
  pointer-events: auto;
  background: rgba(30, 24, 20, 0.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.card h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.card p {
  margin: 6px 0;
  color: var(--muted);
  line-height: 1.45;
}

.card .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.logo {
  font-size: clamp(34px, 7vw, 64px);
  font-weight: 900;
  letter-spacing: 3px;
  margin: 0;
  color: #fff;
  text-shadow: 0 4px 0 #8e1410;
}

.logo span {
  color: var(--accent);
}

.menu {
  text-align: center;
  background: rgba(20, 16, 13, 0.78);
}

.menu .row {
  justify-content: center;
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 800;
  font-size: 15px;
}

.btn:hover:not(:disabled) {
  border-color: #7a6552;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary {
  background: linear-gradient(180deg, #ff7a57, #d9361f);
  border-color: #ff9a7a;
  color: #fff;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.stat {
  background: #19140f;
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.stat b {
  display: block;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 12px;
  color: var(--muted);
}

.card canvas {
  width: 100%;
  height: 90px;
  display: block;
  margin: 6px 0;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 14px;
  margin: 4px 0 8px;
}

.facts b {
  color: var(--text);
}

.tip {
  font-size: 14px;
  border-left: 3px solid var(--accent-2);
  padding-left: 10px;
}

.big {
  font-size: 34px;
  font-weight: 900;
  margin: 0;
}

.big.good {
  color: var(--good);
}

.big.bad {
  color: var(--bad);
}

.points {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-2);
}

.near {
  color: #ffd27a !important;
  font-weight: 700;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #19140f;
  border-radius: 8px;
  padding: 8px 10px;
}

.item .desc {
  font-size: 12px;
  color: var(--muted);
}

.item.done {
  border: 1px solid #3f6b3f;
}

.item.locked {
  opacity: 0.6;
}

.pips {
  font-size: 12px;
  color: var(--accent-2);
  letter-spacing: 2px;
}

.brass {
  color: #e7c05a;
  font-weight: 800;
}

.goal {
  margin-top: 10px;
}

.goal .bar {
  height: 8px;
  background: #0d0a08;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 4px;
}

.goal .bar div {
  height: 100%;
  background: linear-gradient(90deg, #c9952c, #ffd466);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  background: transparent;
  border: 0;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}

.seg button.on {
  background: var(--panel-2);
  color: var(--text);
}

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  flex-wrap: wrap;
}

/* ---------- Page ---------- */

.ad-slot:empty {
  display: none;
}

.ad-slot {
  max-width: 970px;
  margin: 16px auto;
  min-height: 90px;
}

.about {
  max-width: 820px;
  margin: 20px auto;
  padding: 0 8px;
  line-height: 1.55;
}

.about h1 {
  margin-bottom: 4px;
}

.warning {
  background: #2a1512;
  border: 1px solid #5a2a22;
  border-radius: 8px;
  padding: 8px 12px;
}

kbd {
  background: #2d2520;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

.rotate-hint {
  display: none;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin: 6px 0;
}

@media (orientation: portrait) and (max-width: 700px) {
  .stage {
    aspect-ratio: 4 / 5;
    max-height: calc(100dvh - var(--header-h) - 40px);
  }
  .game-root {
    max-width: 100%;
  }
  .hud {
    font-size: 12px;
    padding: 4px;
  }
  .hud-score {
    font-size: 16px;
  }
  .breath-box {
    min-width: 80px;
  }
  .touch-btn {
    width: 58px;
    height: 58px;
    font-size: 11px;
  }
  .card {
    padding: 12px;
  }
  .card h2 {
    font-size: 19px;
  }
  .big {
    font-size: 24px;
  }
}
