:root {
  --bg: #15171c;
  --panel: #23262e;
  --panel2: #2c303a;
  --line: #3a4150;
  --ink: #e8eaf0;
  --muted: #8e96a3;
  --yellow: #f2c531;
  --yellow-dark: #8a6a10;
  --cyan: #42c6d2;
  --red: #d34a3e;
  --green: #57d36a;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

#game-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #101216;
}

canvas#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #1f2229;
  box-shadow: 0 0 0 3px #0b0c0f, 0 0 60px rgba(0, 0, 0, 0.6);
}

.hidden { display: none !important; }
.star, .stars, .big-stars { font-family: system-ui, 'Segoe UI Symbol', sans-serif; }
.star { color: var(--yellow); }
.muted { color: var(--muted); }
.small { font-size: 9px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 11px;
  color: var(--ink);
  background: var(--panel2);
  border: 0;
  padding: 12px 18px;
  cursor: pointer;
  position: relative;
  box-shadow: inset 0 0 0 3px var(--line), 0 4px 0 #0b0c0f;
  transition: transform 0.05s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--line), 0 1px 0 #0b0c0f; }
.btn.primary {
  background: var(--yellow);
  color: #1b1d24;
  box-shadow: inset 0 0 0 3px var(--yellow-dark), 0 4px 0 #4d3a06;
}
.btn.primary:active { box-shadow: inset 0 0 0 3px var(--yellow-dark), 0 1px 0 #4d3a06; }
.btn.danger { background: #3a1f1d; box-shadow: inset 0 0 0 3px var(--red), 0 4px 0 #0b0c0f; }
.btn.tiny { font-size: 9px; padding: 8px 10px; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }

/* ---------- Screens ---------- */
.screen, .overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background: rgba(21, 23, 28, 0.88);
}
.overlay { background: rgba(10, 11, 14, 0.7); }

.screen-head {
  width: min(880px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.screen-head h2 { font-size: 16px; color: var(--yellow); letter-spacing: 1px; }
.head-stat { font-size: 11px; color: var(--ink); display: flex; align-items: center; gap: 6px; }

.panel {
  background: var(--panel);
  box-shadow: inset 0 0 0 3px var(--line), 0 8px 0 #0b0c0f;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 280px;
}
.panel h2 { color: var(--yellow); font-size: 18px; }
.panel .btn { width: 100%; }
.menu-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.menu-row .btn { width: auto; }

/* ---------- Title ---------- */
.logo { text-align: center; line-height: 1; margin-bottom: 14px; }
.logo-line1 {
  font-size: clamp(28px, 7vw, 52px);
  color: var(--yellow);
  text-shadow: 4px 4px 0 #4d3a06, 8px 8px 0 #0b0c0f;
  letter-spacing: 4px;
}
.logo-line2 {
  font-size: clamp(28px, 7vw, 52px);
  color: var(--cyan);
  text-shadow: 4px 4px 0 #1a5a63, 8px 8px 0 #0b0c0f;
  letter-spacing: 4px;
  margin-top: 8px;
}
.tagline { font-size: 10px; color: var(--muted); margin-bottom: 14px; text-align: center; }
#title-preview {
  image-rendering: pixelated;
  width: 96px;
  height: 96px;
  margin-bottom: 18px;
}
.menu { display: flex; flex-direction: column; gap: 12px; width: 240px; }
.stats-row {
  display: flex;
  gap: 24px;
  margin-top: 20px;
  font-size: 10px;
  color: var(--ink);
}
.stats-row span { display: inline-flex; align-items: center; gap: 6px; }
.help { font-size: 8px; color: var(--muted); margin-top: 14px; text-align: center; max-width: 520px; }
#btn-reset { margin-top: 18px; }

.bolt-ico {
  display: inline-block;
  width: 12px;
  height: 12px;
  background: var(--yellow);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%);
  position: relative;
  vertical-align: middle;
  margin-right: 6px;
}

/* ---------- Level grid ---------- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  width: min(880px, 100%);
}
.level-card {
  background: var(--panel);
  box-shadow: inset 0 0 0 3px var(--line), 0 5px 0 #0b0c0f;
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.05s;
}
.level-card:hover { filter: brightness(1.15); }
.level-card:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--line), 0 2px 0 #0b0c0f; }
.level-card.locked { opacity: 0.45; cursor: not-allowed; }
.level-card .num { font-size: 20px; color: var(--yellow); }
.level-card .name { font-size: 9px; }
.level-card .stars { color: var(--yellow); font-size: 12px; letter-spacing: 2px; }
.level-card .stars .off { color: #3a4150; }
.level-card .best { font-size: 8px; color: var(--muted); }
.level-card canvas { image-rendering: pixelated; width: 100%; height: 64px; object-fit: contain; display: block; background: #1f2229; box-shadow: inset 0 0 0 2px #0b0c0f; }

/* ---------- Shop ---------- */
.shop-body {
  display: flex;
  gap: 24px;
  width: min(880px, 100%);
  align-items: flex-start;
}
.shop-side {
  flex: 0 0 180px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
#shop-preview {
  image-rendering: pixelated;
  width: 160px;
  height: 160px;
  background: #1f2229;
  box-shadow: inset 0 0 0 3px var(--line);
}
.loadout { width: 100%; font-size: 8px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.loadout b { color: var(--ink); font-weight: normal; }
.loadout .slot { display: flex; justify-content: space-between; gap: 6px; }
.shop-main { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tab {
  font-family: inherit;
  font-size: 9px;
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 8px 10px;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--line);
}
.tab.active { color: #1b1d24; background: var(--cyan); box-shadow: inset 0 0 0 2px #1a5a63; }
#shop-hint { margin-bottom: 10px; min-height: 14px; }
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.item {
  background: var(--panel);
  box-shadow: inset 0 0 0 3px var(--line), 0 5px 0 #0b0c0f;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.05s;
}
.item:hover { filter: brightness(1.12); }
.item:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--line), 0 2px 0 #0b0c0f; }
.item.equipped { box-shadow: inset 0 0 0 3px var(--yellow), 0 5px 0 #0b0c0f; }
.item.locked { opacity: 0.55; }
.item canvas { image-rendering: pixelated; width: 64px; height: 64px; background: #1f2229; }
.item .iname { font-size: 9px; color: var(--ink); }
.item .idesc { font-size: 7px; color: var(--muted); min-height: 22px; }
.item .iprice { font-size: 9px; color: var(--yellow); display: flex; align-items: center; gap: 4px; }
.item .iprice.owned { color: var(--green); }
.item .iprice.lock { color: var(--muted); }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 14px;
}
.hud-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  text-shadow: 2px 2px 0 #0b0c0f;
}
.hud-left, .hud-right, .hud-center { display: flex; align-items: center; gap: 10px; }
.hud-right .btn { pointer-events: auto; }
#hud-gear { display: flex; gap: 6px; margin-top: 6px; align-self: flex-start; }
#hud-gear canvas { image-rendering: pixelated; width: 24px; height: 24px; }
#hud-gear canvas.used { opacity: 0.3; }
#hud-tip {
  margin-top: auto;
  margin-bottom: 18px;
  font-size: 9px;
  color: var(--yellow);
  text-shadow: 2px 2px 0 #0b0c0f;
  text-align: center;
  padding: 0 12px;
}

/* ---------- Touch ---------- */
#touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  padding: 0 16px 16px;
  pointer-events: none;
}
.touch-group { display: flex; gap: 12px; pointer-events: auto; }
#touch button {
  width: 68px;
  height: 68px;
  font-size: 22px;
  font-family: inherit;
  color: var(--ink);
  background: rgba(44, 48, 58, 0.75);
  border: 0;
  box-shadow: inset 0 0 0 3px var(--line);
}
#touch button:active { background: rgba(242, 197, 49, 0.8); color: #1b1d24; }

/* ---------- Complete ---------- */
.big-stars { font-size: 28px; color: var(--yellow); letter-spacing: 6px; }
.big-stars .off { color: #3a4150; }
.result { border-collapse: collapse; font-size: 10px; width: 100%; }
.result td { padding: 4px 8px; }
.result td:first-child { color: var(--muted); }
.result td:last-child { text-align: right; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--panel);
  box-shadow: inset 0 0 0 3px var(--yellow), 0 4px 0 #0b0c0f;
  padding: 10px 16px;
  font-size: 9px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .shop-body { flex-direction: column; align-items: center; }
  .shop-side { flex-direction: row; flex: none; width: 100%; justify-content: center; }
  #shop-preview { width: 96px; height: 96px; }
  .screen { padding: 14px; }
  .screen-head h2 { font-size: 12px; }
  .logo-line1, .logo-line2 { letter-spacing: 2px; }
}
