:root {
  --bg: #150a12;
  --panel: #2a1230;
  --panel-2: #361845;
  --ink: #501539;
  --text: #f8ece7;
  --muted: #c9a0c0;
  --orange: #f9b31a;
  --orange-dark: #d7802a;
  --orange-light: #ffc847;
  --pink: #f390a9;
  --pink-dark: #a8607e;
  --cream: #f390a9;
  --green: #58ff00;
  --green-dark: #2aa600;
  --red: #ff265c;
  --cyan: #00c7fc;
  --purple: #9b5de5;
  --gold: #f9b31a;
  --gold-dark: #d7802a;
  --font: 'Press Start 2P', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 82% -5%, rgba(250, 165, 0, 0.18), transparent 46%),
    radial-gradient(circle at 0% 100%, rgba(252, 107, 143, 0.14), transparent 42%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='%23faa500' fill-opacity='.045'%3E%3Ccircle cx='24' cy='26' r='6'/%3E%3Ccircle cx='39' cy='18' r='6'/%3E%3Ccircle cx='54' cy='26' r='6'/%3E%3Cpath d='M39 33c11 0 20 9 20 20 0 8-6 13-13 13-3 0-5-1-7-1s-4 1-7 1c-7 0-13-5-13-13 0-11 9-20 20-20z'/%3E%3C/g%3E%3C/svg%3E") repeat,
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.8;
  display: flex;
  flex-direction: column;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px);
  z-index: 100;
}

.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }

[hidden] { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 4px solid #000;
  background: rgba(21, 7, 17, 0.88);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-logo {
  width: auto;
  height: 36px;
  display: block;
  filter: drop-shadow(2px 2px 0 #000);
  flex: 0 0 auto;
}

.brand-name { color: var(--orange); font-size: 14px; letter-spacing: 1px; white-space: nowrap; }

.brand-tag {
  color: var(--muted);
  font-size: 8px;
  line-height: 1;
  padding: 6px 8px;
  border: 2px solid var(--panel-2);
  background: var(--panel);
  box-shadow: 2px 2px 0 #000;
  white-space: nowrap;
}

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px; }

.screen { display: none; }
.screen.active { display: block; animation: pop 0.25s steps(4); }

@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

footer { text-align: center; color: var(--muted); font-size: 9px; padding: 24px; }
footer p { margin: 8px 0; }
.foot-links { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; font-size: 10px; }
.foot-links a { color: var(--orange); text-decoration: none; }
.foot-links a:hover { color: var(--pink); }
.foot-links span { color: var(--panel-2); }

.panel {
  background: var(--panel);
  padding: 24px;
  border: 4px solid #000;
  box-shadow: inset 0 0 0 4px var(--panel-2), 8px 8px 0 #000;
}

h2 { color: var(--orange); font-size: 16px; margin: 0 0 16px; }

.btn {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--orange);
  border: 4px solid #000;
  padding: 14px 22px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  box-shadow: inset -4px -4px 0 var(--orange-dark), inset 4px 4px 0 var(--orange-light), 4px 4px 0 #000;
  transition: transform 0.05s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translate(2px, 2px); box-shadow: inset -4px -4px 0 var(--orange-dark), 2px 2px 0 #000; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-dark { background: var(--panel-2); color: var(--text); box-shadow: inset -4px -4px 0 #1a0c17, inset 4px 4px 0 #5a2a52, 4px 4px 0 #000; }
.btn-x { background: #fff; color: #000; box-shadow: inset -4px -4px 0 #bbb, 4px 4px 0 #000; }
.btn-small { font-size: 9px; padding: 8px 12px; }

.link-btn { font-family: var(--font); background: none; border: none; color: var(--muted); cursor: pointer; margin-top: 24px; font-size: 10px; }
.link-btn:hover { color: var(--pink); }

kbd {
  font-family: var(--font);
  font-size: 9px;
  background: var(--panel-2);
  border: 2px solid #000;
  box-shadow: 2px 2px 0 #000;
  padding: 2px 6px;
}

.hero { position: relative; text-align: center; padding: 16px 0 28px; }
.hero::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 6px;
  width: 190px;
  height: 190px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(250, 165, 0, 0.22), transparent 68%);
  pointer-events: none;
}
#hero-cat-img {
  position: relative;
  width: 190px;
  height: auto;
  margin-bottom: 8px;
  filter: drop-shadow(5px 5px 0 rgba(0, 0, 0, 0.55));
  animation: hero-bob 2.2s steps(8) infinite;
}
@keyframes hero-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
#hero-cat { position: relative; width: 114px; height: auto; filter: drop-shadow(4px 4px 0 rgba(0, 0, 0, 0.65)); display: none; }

.title {
  position: relative;
  font-size: clamp(36px, 8vw, 72px);
  margin: 12px 0;
  color: var(--orange);
  letter-spacing: 4px;
  text-shadow: 4px 4px 0 var(--pink), 8px 8px 0 #000;
}

.tagline { position: relative; color: var(--muted); font-size: 12px; line-height: 2.2; }
.tagline span { color: var(--pink); }

.enter-panel { max-width: 760px; margin: 0 auto 32px; }
.enter-panel label { display: block; margin-bottom: 12px; color: var(--orange); font-size: 11px; }

.input-row { display: flex; gap: 12px; }
.input-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 11px;
  padding: 14px;
  background: #180a18;
  color: var(--text);
  border: 4px solid #000;
  box-shadow: inset 4px 4px 0 #08030a;
  outline: none;
}
.input-row input:focus { border-color: var(--pink); }

.warn { color: var(--orange-light); font-size: 9px; margin: 14px 0 0; }
.error { color: var(--red); font-size: 10px; margin: 12px 0 0; }
.small { color: var(--muted); font-size: 9px; line-height: 2; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }

.controls { list-style: none; padding: 0; margin: 0 0 20px; }
.controls li { margin-bottom: 12px; font-size: 10px; }
.controls span { color: var(--muted); display: block; margin-top: 4px; }

.legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 8px; }
.legend div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; text-align: center; font-size: 8px; background: #1e0f21; border: 3px solid #000; padding: 12px 6px; min-height: 110px; }
.legend span { color: var(--muted); line-height: 1.8; }

.tiers { width: 100%; border-collapse: collapse; font-size: 10px; }
.tiers th { color: var(--muted); text-align: left; font-size: 8px; padding: 8px; border-bottom: 3px solid #000; }
.tiers td { padding: 14px 8px; border-bottom: 2px dashed var(--panel-2); }

.leaderboard { list-style: none; padding: 0; margin: 0; counter-reset: rank; }
.leaderboard li.row {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  font-size: 10px;
  border-bottom: 2px dashed var(--panel-2);
}
.leaderboard li.row::before { content: counter(rank); color: var(--muted); }
.leaderboard li.row:nth-child(1)::before { content: '1ST'; color: var(--orange); }
.leaderboard li.row:nth-child(2)::before { content: '2ND'; color: var(--cream); }
.leaderboard li.row:nth-child(3)::before { content: '3RD'; color: #cd7f32; }
.leaderboard .lb-addr { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .lb-score { text-align: right; }
.leaderboard .lb-tier { display: block; font-size: 7px; margin-top: 4px; }

.events { list-style: none; padding: 0; margin: 16px 0 0; }
.events li { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 2px dashed var(--panel-2); }
.events b { font-weight: normal; font-size: 11px; }
.events span { color: var(--muted); font-size: 9px; line-height: 1.9; }
.ev-whale { color: #a8c8ff; }
.ev-sec, .ev-liq { color: var(--red); }
.ev-bull { color: var(--green); }

.game-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 4px solid #000;
  box-shadow: 8px 8px 0 #000, 0 0 60px rgba(250, 165, 0, 0.22), 0 0 110px rgba(252, 107, 143, 0.12);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  background: #0b0408;
}
#game { width: 100%; height: 100%; display: block; }

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px;
  font-size: clamp(8px, 1.3vw, 13px);
  pointer-events: none;
  text-shadow: 2px 2px 0 #000;
}
.hud-item { display: flex; align-items: center; gap: 8px; }
.hud-item b { color: var(--orange); font-weight: normal; }
.hud-item:last-child { margin-left: auto; }
.hud-item b.hud-bull { color: var(--green); margin-right: 8px; animation: shine 0.5s steps(2) infinite; }
.hud-icon { display: block; flex: 0 0 auto; filter: drop-shadow(2px 2px 0 #000); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#overlay-text {
  font-size: clamp(32px, 9vw, 96px);
  color: var(--orange);
  text-shadow: 6px 6px 0 var(--pink), 12px 12px 0 #000;
  animation: pulse 0.7s steps(3) infinite;
}
@keyframes pulse { 50% { transform: scale(1.15); } }

.hint { text-align: center; color: var(--muted); font-size: 9px; margin-top: 20px; }

.result-panel { max-width: 720px; margin: 0 auto; text-align: center; }
.addr { color: var(--muted); font-size: 10px; word-break: break-all; }
.big-score {
  font-size: clamp(40px, 10vw, 80px);
  color: var(--orange);
  text-shadow: 4px 4px 0 var(--pink), 9px 9px 0 #000;
  margin: 16px 0;
}
.tier-badge {
  display: inline-block;
  font-size: 18px;
  padding: 12px 18px;
  border: 4px solid;
  box-shadow: 4px 4px 0 #000;
  background: #180a18;
  animation: shine 1.2s steps(2) infinite;
}
@keyframes shine { 50% { filter: brightness(1.4); } }
.allocation { font-size: 16px; margin: 20px 0 8px; color: var(--cream); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0; }
.stats div { background: #201020; border: 3px solid #000; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.stats span { color: var(--muted); font-size: 8px; }
.stats b { font-weight: normal; color: var(--orange); }

.run-id-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 18px auto 6px;
  padding: 12px 18px;
  border: 3px dashed var(--orange);
  background: #180a18;
  max-width: 480px;
}
.run-id-label { color: var(--muted); font-size: 10px; }
.run-id-value { font-weight: normal; color: #fff; font-size: 16px; letter-spacing: 2px; text-shadow: 2px 2px 0 #000; }
.run-id-note { color: var(--muted); font-size: 9px; line-height: 2; margin: 8px auto 0; max-width: 480px; }
.runid-inline { color: var(--orange); }

.actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 4, 10, 0.84);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-box { max-width: 560px; text-align: center; }

.save-steps {
  list-style: none;
  counter-reset: step;
  margin: 18px auto;
  padding: 0;
  display: inline-flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.save-steps li {
  counter-increment: step;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.save-steps li::before { content: counter(step) "."; color: var(--muted); margin-right: 4px; }

@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
  .input-row { flex-direction: column; }
  main { padding: 16px; }
  .hud { gap: 10px; padding: 6px 8px; }
  .stats { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .brand-tag { display: none; }
  .brand-logo { height: 30px; }
  #hero-cat-img { width: 150px; }
  #hero-cat { width: 92px; height: auto; }
}
