:root {
  --bg: #15110e;
  --panel: #231c16;
  --panel-2: #2e251d;
  --line: #43372b;
  --text: #f3eadf;
  --muted: #b5a797;
  --accent: #ffb547;
  --accent-2: #ff7b3a;
  --good: #5fd35f;
  --bad: #e8483a;
  --radius: 10px;
  --hud-h: 46px;
  --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);
}

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);
  letter-spacing: 0.5px;
}

.site-logo span {
  color: var(--accent);
  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 layout ---------- */

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: min(1400px, calc((100vh - var(--header-h) - var(--hud-h) - 24px) * 1.7778));
  max-width: min(1400px, calc((100dvh - var(--header-h) - var(--hud-h) - 24px) * 1.7778));
  min-width: min(100%, 320px);
  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;
  min-height: 240px;
}

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

.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  min-height: var(--hud-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.hud-title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34%;
}

.hud-ammo {
  display: flex;
  gap: 4px;
  align-items: center;
}

.hud-ammo canvas {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.hud-ammo canvas.next {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.hud-ammo .more {
  font-size: 12px;
  color: var(--muted);
}

.hud-spacer {
  flex: 1;
}

.hud-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 18px;
  min-width: 70px;
}

.hud-score .lbl {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  min-height: 36px;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

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

.btn-primary {
  background: linear-gradient(180deg, #ffc46b, #f59b2f);
  color: #2a1a07;
  border-color: #c77a1f;
}

.btn-primary:hover:not(:disabled) {
  border-color: #fff1d6;
}

.btn-icon {
  width: 36px;
  padding: 0;
  font-size: 16px;
}

.btn-tap {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 3;
  background: rgba(35, 28, 22, 0.85);
  border-color: var(--accent);
  font-size: 15px;
  padding: 12px 18px;
}

.tip {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  z-index: 2;
  background: rgba(20, 16, 12, 0.72);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 80%;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.tip.show {
  opacity: 1;
}

/* ---------- Overlays and menus ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12, 9, 7, 0.62);
  padding: 12px;
  overflow: auto;
}

.overlay.show {
  display: flex;
}

.menu {
  background: rgba(35, 28, 22, 0.97);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.menu.wide {
  width: min(820px, 100%);
}

.menu h2 {
  margin: 4px 0 10px;
  font-size: 24px;
}

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

.logo {
  font-size: clamp(34px, 7vw, 64px);
  font-weight: 900;
  letter-spacing: 4px;
  margin: 4px 0 2px;
  background: linear-gradient(180deg, #ffe0a3, #e08a2d 70%, #9c5a1c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.tagline {
  color: var(--muted);
  margin-bottom: 14px;
}

.menu-buttons {
  display: grid;
  gap: 10px;
  margin: 12px auto 4px;
  max-width: 340px;
}

.menu-buttons .btn {
  padding: 12px 16px;
  font-size: 17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.menu-buttons .btn small {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.btn-primary small {
  color: #5a3a10 !important;
}

.goal {
  margin: 12px auto 0;
  max-width: 340px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.bar {
  height: 8px;
  background: #140f0b;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-top: 4px;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffb547, #ff7b3a);
  width: 0;
  transition: width 0.4s;
}

.region-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.region-tabs .btn.active {
  border-color: var(--accent);
  background: #3a2d20;
}

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

.lvl {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 76px;
}

.lvl:hover:not(:disabled) {
  border-color: var(--accent);
}

.lvl .num {
  font-size: 22px;
  font-weight: 800;
}

.lvl .name {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.15;
}

.lvl:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.stars {
  color: #5a4a3a;
  letter-spacing: 1px;
  font-size: 14px;
}

.stars .on {
  color: #ffc93c;
}

.big-stars {
  font-size: 46px;
  letter-spacing: 6px;
  margin: 6px 0;
  color: #4a3d30;
}

.big-stars span {
  display: inline-block;
  transform: scale(0.4);
  opacity: 0.35;
  transition: transform 0.35s cubic-bezier(0.2, 1.8, 0.4, 1), opacity 0.2s, color 0.2s;
}

.big-stars span.on {
  color: #ffc93c;
  transform: scale(1);
  opacity: 1;
}

.result-score {
  font-size: 34px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.result-lines {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  text-align: left;
  max-width: 300px;
  margin: 8px auto;
  font-size: 14px;
  color: var(--muted);
}

.result-lines b {
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  background: #3a2d20;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
  margin: 2px;
}

.row-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.ach-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  text-align: left;
  margin: 10px 0;
}

.ach {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  opacity: 0.5;
}

.ach.done {
  opacity: 1;
  border-color: #6b5a2a;
}

.ach b {
  display: block;
  font-size: 14px;
}

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

.ammo-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px;
  text-align: left;
  margin: 8px 0;
  font-size: 13px;
}

.ammo-legend div {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ammo-legend canvas {
  width: 28px;
  height: 28px;
  flex: none;
}

.toast-ach {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  z-index: 6;
  background: #2e251d;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.toast-ach.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

.ad-slot[data-filled='true'] {
  min-height: 90px;
}

.about {
  max-width: 820px;
  margin: 24px auto 0;
  color: var(--muted);
  line-height: 1.55;
  padding: 0 8px;
}

.about h1,
.about h2 {
  color: var(--text);
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.9em;
  color: var(--text);
}

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

@media (max-width: 700px) {
  .hud {
    gap: 5px;
    padding: 4px 6px;
  }
  .hud-title {
    display: none;
  }
  .hud-ammo canvas {
    width: 24px;
    height: 24px;
  }
  .lvl-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  .lvl .name {
    display: none;
  }
  .lvl {
    min-height: 54px;
  }
  .menu {
    padding: 12px;
  }
  .menu h2 {
    font-size: 20px;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  .rotate-hint {
    display: block;
  }
}

/* Short landscape screens (phones held sideways): hide the site header while
   playing so the field gets the space. */
@media (orientation: landscape) and (max-height: 540px) {
  :root {
    --hud-h: 38px;
  }
  body.playing .site-header {
    display: none;
  }
  body.playing .page {
    padding: 0;
  }
  body.playing .game-root {
    max-width: calc((100vh - var(--hud-h) - 2px) * 1.7778);
    max-width: calc((100dvh - var(--hud-h) - 2px) * 1.7778);
    border-radius: 0;
    border-width: 0;
  }
  .stage {
    min-height: 0;
  }
  .hud {
    padding: 2px 6px;
    min-height: var(--hud-h);
  }
  .hud .btn-icon {
    height: 30px;
    min-height: 30px;
  }
  .hud-ammo canvas {
    width: 26px;
    height: 26px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .big-stars span,
  .bar-fill,
  .toast-ach,
  .tip {
    transition: none;
  }
}
