:root {
  --blue: #1b0273;
  --blue-deep: #100147;
  --pink: #f2167d;
  --yellow: #f3df43;
  --teal: #0d9baf;
  --purple: #5b3ad6;
  --green: #34d399;
  --lavender: #e6e3f5;
  --muted: #8e89b5;
  --pix: "Press Start 2P", ui-monospace, monospace;
  --sans: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--blue-deep);
  color: #fff;
  font-family: var(--sans);
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

#game {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  image-rendering: pixelated;
  background: #000;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16, 1, 71, 0.72);
  padding: 16px;
  overflow-y: auto;
}
.overlay.hidden { display: none; }

.panel {
  width: min(560px, 100%);
  background: var(--blue);
  border: 4px solid var(--pink);
  border-radius: 20px;
  padding: 28px 28px 22px;
  text-align: center;
  box-shadow: 0 0 0 6px var(--blue-deep), 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.logo { width: 150px; }
.kicker { margin: 0; color: var(--muted); font-size: 14px; letter-spacing: 0.04em; }

h1 {
  font-family: var(--pix);
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.15;
  margin: 4px 0 0;
  color: #fff;
  text-shadow: 4px 4px 0 var(--pink);
}
h1 span { color: var(--yellow); }

h2 { font-family: var(--pix); font-size: 22px; line-height: 1.4; margin: 0; }
h2.pink { color: var(--pink); }
h2.green { color: var(--green); }

.tagline { font-family: var(--pix); font-size: 12px; color: var(--pink); margin: 0; }
.story { margin: 4px 0; line-height: 1.5; color: var(--lavender); font-size: 16px; }
.story b { color: var(--yellow); }
.sub { margin: 0; color: var(--lavender); line-height: 1.5; font-size: 16px; }

.btn {
  font-family: var(--pix);
  font-size: 13px;
  border: 0;
  border-radius: 999px;
  padding: 14px 24px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.08s ease, filter 0.15s;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--pink); color: #fff; box-shadow: 0 4px 0 #a30d55; }
.btn.ghost { background: transparent; color: var(--lavender); border: 2px solid #3d2a9a; font-size: 11px; padding: 10px 18px; }

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 18px;
  font-size: 14px;
  color: var(--lavender);
  text-align: left;
  margin: 4px 0;
}
kbd {
  font-family: var(--pix);
  font-size: 9px;
  background: var(--blue-deep);
  border: 1px solid #3d2a9a;
  border-radius: 6px;
  padding: 3px 6px;
  color: var(--yellow);
}

.stats { width: 100%; display: grid; gap: 6px; margin: 4px 0; }
.stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--blue-deep);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
}
.stat span { color: var(--muted); }
.stat b { font-family: var(--pix); font-size: 11px; color: #fff; align-self: center; }

.rank-wrap { font-size: 16px; color: var(--lavender); }
.rank-wrap b { font-family: var(--pix); font-size: 14px; color: var(--yellow); display: block; margin-top: 8px; }

.cta {
  width: 100%;
  background: var(--pink);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.cta p { margin: 0; font-weight: bold; line-height: 1.4; }
.cta small { font-weight: normal; opacity: 0.9; }
.cta .btn.primary { background: #fff; color: var(--pink); box-shadow: 0 4px 0 #a30d55; }

.slider { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--lavender); width: 100%; max-width: 280px; }
.slider input { accent-color: var(--pink); }

@media (max-width: 520px) {
  .panel { padding: 20px 16px; }
  .controls { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------- leaderboard */
.hs { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hs-entry { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; background: var(--blue-deep); border-radius: 14px; padding: 14px; }
.hs-title { margin: 0; font-family: var(--pix); font-size: 13px; color: var(--yellow); }
.hs-score { margin: 0; font-family: var(--pix); font-size: 22px; color: var(--green); }
.hs-rank { margin: 0; font-family: var(--pix); font-size: 12px; color: #fff; }
.hs-slots { display: flex; gap: 14px; }
.hs-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hs-letter {
  font-family: var(--pix); font-size: 34px; color: #fff; width: 56px; height: 56px; display: grid; place-items: center;
  border-bottom: 4px solid #3d2a9a; cursor: pointer; user-select: none;
}
.hs-slot.on .hs-letter { color: var(--pink); border-color: var(--pink); animation: blink 0.8s steps(2, start) infinite; }
.hs-arrow { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 2px 10px; }
.hs-arrow:hover { color: var(--yellow); }
.hs-help { margin: 0; font-size: 12px; color: var(--muted); }
.hs-error { margin: 0; min-height: 1em; font-size: 14px; color: var(--pink); font-weight: bold; }
.hs-note { margin: 0; font-size: 14px; color: var(--lavender); }
.hs-table { width: 100%; border-collapse: collapse; font-family: var(--pix); font-size: 11px; }
.hs-table th { color: var(--muted); font-weight: normal; font-size: 9px; padding: 0 4px 8px; text-align: left; }
.hs-table td { padding: 6px 4px; text-align: left; color: var(--teal); }
.hs-table td.pot { color: #fff; }
.hs-table tr.p1 td { color: var(--yellow); }
.hs-table tr.p2 td { color: #e6e3f5; }
.hs-table tr.p3 td { color: #f59e0b; }
.hs-table tr.me td { background: rgba(242, 22, 125, 0.25); color: #fff; }
.hs-table tr.gap td { color: var(--muted); text-align: center; }
.arcade-title { color: var(--yellow); text-shadow: 3px 3px 0 var(--pink); font-size: 26px; }
.blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
@media (max-width: 520px) { .hs-table { font-size: 9px; } .hs-letter { font-size: 26px; width: 44px; height: 46px; } }

/* ------------------------------------------------------------- mobile */
#game { width: min(100vw, calc(100dvh * 16 / 9)); height: min(100dvh, calc(100vw * 9 / 16)); }
html.is-touch, html.is-touch body { touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.touch-only { display: none !important; }
html.is-touch .touch-only { display: grid !important; }
html.is-touch .desk-only { display: none !important; }

#touch { position: fixed; inset: 0; z-index: 5; touch-action: none; }
#touch.hidden { display: none; }
.t-zone { position: absolute; top: 0; bottom: 0; touch-action: none; }
#t-move { left: 0; width: 45%; }
#t-look { right: 0; width: 55%; }
.t-stick {
  /* positioned only by transform (set in touch.js) from the top-left of the screen */
  position: fixed; left: 0; top: 0; width: 120px; height: 120px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.35); background: rgba(16,1,71,0.25); pointer-events: none;
  display: none; place-items: center; will-change: transform;
}
.t-stick.on { display: grid; }
.t-knob { width: 54px; height: 54px; border-radius: 50%; background: rgba(242,22,125,0.85); border: 3px solid #fff; pointer-events: none; }
.t-debug {
  position: fixed; left: 8px; bottom: 8px; z-index: 100; margin: 0; padding: 6px 8px; border-radius: 6px;
  background: rgba(0,0,0,0.75); color: #0f0; font: 11px/1.35 ui-monospace, monospace; pointer-events: none; white-space: pre;
}
.t-btn {
  position: absolute; border: 3px solid rgba(255,255,255,0.8); color: #fff; border-radius: 50%;
  font-family: var(--pix); touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none;
  background: rgba(16,1,71,0.45); display: grid; place-items: center; padding: 0;
}
.t-fire {
  right: calc(28px + env(safe-area-inset-right)); bottom: 30%; width: 104px; height: 104px;
  background: rgba(242,22,125,0.7); font-size: 13px; box-shadow: 0 5px 0 rgba(163,13,85,0.8);
}
.t-fire.on { background: rgba(242,22,125,1); transform: scale(0.94); }
.t-small { width: 56px; height: 56px; font-size: 10px; }
.t-use { right: calc(150px + env(safe-area-inset-right)); bottom: 36%; }
.t-kit { right: calc(150px + env(safe-area-inset-right)); bottom: calc(36% + 70px); font-size: 9px; }
.t-top { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); display: flex; gap: 10px; }
.t-top .t-btn { position: static; width: 48px; height: 48px; font-size: 20px; font-family: inherit; }
.t-btn:active { background: rgba(242,22,125,0.85); }

#rotate {
  display: none; position: fixed; inset: 0; z-index: 50; background: var(--blue);
  flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px;
}
#rotate p { margin: 0; font-family: var(--pix); font-size: 14px; line-height: 1.6; color: #fff; }
#rotate small { color: var(--muted); font-size: 14px; }
.rotate-phone { font-size: 72px; animation: rotate-hint 2s ease-in-out infinite; }
@keyframes rotate-hint { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) { html.is-touch #rotate { display: flex; } }

/* short landscape screens (phones) */
@media (max-height: 520px) {
  .overlay { align-items: start; padding: 10px; }
  .panel { padding: 16px 18px; gap: 8px; border-width: 3px; margin: auto; }
  .logo { width: 110px; }
  h1 { font-size: 26px; }
  h2 { font-size: 16px; }
  .story, .sub { font-size: 13px; }
  .kicker, .tagline { font-size: 11px; }
  .btn { padding: 11px 18px; font-size: 11px; }
  .controls { font-size: 12px; gap: 4px 14px; }
  .stat { padding: 6px 10px; font-size: 13px; }
  .hs-letter { font-size: 24px; width: 42px; height: 42px; }
  .cta { padding: 10px; }
}

/* ------------------------------------------------------------ loading */
html.loading .needs-ready { display: none !important; }
html:not(.loading) .loader { display: none; }
.loader { width: min(340px, 100%); display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 6px 0; }
.loader-bar { width: 100%; height: 22px; padding: 3px; border: 3px solid var(--pink); border-radius: 6px; background: var(--blue-deep); }
.loader-bar span {
  display: block; height: 100%; width: 0; border-radius: 2px; transition: width 0.25s steps(6);
  background: repeating-linear-gradient(90deg, var(--yellow) 0 10px, #c9a20f 10px 12px);
}
#loader-text { margin: 0; font-family: var(--pix); font-size: 10px; color: var(--lavender); min-height: 1em; }
