/* ===========================================================
   Pixel Cat Run — base styles
   Palette + a hand-rolled "pixel border" (box-shadow steps)
   so buttons/inputs read as pixel art with zero image assets.
   =========================================================== */

:root {
  --bg: #0f0f1a;
  --panel: #1b1b2e;
  --ink: #f4f1de;
  --accent: #ffb703;
  --accent-2: #06d6a0;
  --danger: #ef476f;
  --border: #f4f1de;
  --pixel: 4px;
  --banner-h: 34px;
  --footer-h: 28px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Press Start 2P", "Courier New", monospace;
  image-rendering: pixelated;
}

canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Full-viewport backdrop scene, behind everything. Gives the flat 2D UI a
   sense of 3D depth without the actual game being 3D -- a static painted
   background image, not a real environment. Falls back to a plain dark
   gradient (matching --bg) until assets/ui/backdrop.jpg is added. */
.bg-layer {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, #1b1b2e 0%, var(--bg) 70%);
}

.bg-layer-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.bg-layer-img[hidden] {
  display: none;
}

/* Dark scrim so pixel UI stays readable over a busy background image. */
.bg-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 18, 0.55);
}

/* Hidden during actual gameplay -- the game canvas is its own flat 2D
   scene and shouldn't have the atmospheric backdrop showing around it. */
body.is-playing .bg-layer {
  display: none;
}

/* ---------------- Loading screen ---------------- */
/* Covers the page until critical art (backdrop, podium, font) has
   loaded, so we don't show placeholders popping in/replaced live.
   z-index is explicit (not just relying on DOM order) because several
   elements elsewhere (corner scoreboard, podium play button, etc.) set
   their own z-index without an ancestor stacking context, so those
   values leak into the root stacking context -- this has to outrank
   all of them deliberately. */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.35s ease;
}

body.assets-loaded .loading-screen {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--ink);
  animation: loading-pulse 1.1s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#app {
  position: relative;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--banner-h)) 16px calc(24px + var(--footer-h));
}

/* ---------------- Persistent chrome (all screens) ---------------- */

.announcement-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--banner-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 40px;
  background: var(--accent);
  border-bottom: 2px solid #000;
  z-index: 10;
}

.announcement-banner p {
  margin: 0;
  font-size: 9px;
  letter-spacing: 0.5px;
  color: #1a1200;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* #btn-trade.trade-btn (id+class) so width/max-width reliably win over
   the plain .pixel-btn base rules regardless of source order. */
#btn-trade.trade-btn {
  position: fixed;
  top: calc(var(--banner-h) + 16px);
  left: 16px;
  width: auto;
  max-width: none;
  padding: 10px 14px;
  font-size: 10px;
  background: var(--accent);
  color: #1a1200;
  z-index: 10;
}

#btn-trade.trade-btn:hover {
  background: #ffc93c;
}

.ca-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 18, 0.85);
  border-top: 2px solid #2c2c4a;
  color: #8a8aa3;
  font-size: 8px;
  letter-spacing: 0.5px;
  z-index: 10;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 960px;
}

.screen.active {
  display: flex;
}

.title {
  font-size: 22px;
  text-align: center;
  letter-spacing: 2px;
  margin: 8px 0;
  text-shadow: 3px 3px 0 #000;
}

.title-sm {
  font-size: 16px;
}

.title-accent {
  color: var(--accent);
}

/* ---------------- Menu ---------------- */

/* Fixed top-right scoreboard: top 10, plus your own rank/score below if
   you're not already in that top 10. Always visible, no navigation
   needed to see where you stand. */
.scoreboard {
  position: fixed;
  top: calc(var(--banner-h) + 16px);
  right: 16px;
  width: 200px;
  background: var(--panel);
  border: var(--pixel) solid var(--border);
  box-shadow: 6px 6px 0 #000;
  padding: 10px 12px;
  z-index: 5;
}

.scoreboard-title {
  margin: 0 0 8px 0;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 1px;
}

.scoreboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 9px;
  max-height: 200px;
  overflow-y: auto;
}

.scoreboard-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
}

.scoreboard-list li .rank {
  color: #8a8aa3;
  flex: 0 0 auto;
}

.scoreboard-list li .wallet {
  color: var(--accent-2);
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

.scoreboard-list li .score {
  flex: 0 0 auto;
}

.scoreboard-list li.is-you {
  color: var(--accent);
}

.scoreboard-list li.is-you .wallet {
  color: var(--accent);
}

.scoreboard-you {
  margin: 8px 0 0 0;
  padding-top: 8px;
  border-top: 2px solid #2c2c4a;
  font-size: 9px;
  color: var(--accent);
}

.scoreboard-empty {
  margin: 0;
  text-align: left;
}

/* No border/panel/background -- the podium+cat sit directly on the page
   backdrop, not inside a bordered card. Just a positioning box.
   isolation:isolate scopes the z-index:1/2/3 children below to a local
   stacking context so they can't leak out and outrank unrelated
   elements elsewhere on the page (this is what caused the loading
   screen to render behind the podium/cat/button). */
.preview-wrap {
  position: relative;
  isolation: isolate;
  width: 320px;
  height: 348px;
}

/* Character sits in the top of the box, overlapping down onto the podium
   below it so it reads as "standing on" the podium. */
#preview-canvas,
.preview-gif {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  height: 200px;
  z-index: 2;
}

#preview-canvas {
  display: block;
}

#preview-canvas[hidden] {
  display: none;
}

.preview-gif {
  object-fit: contain;
}

/* Podium the character rotates on. CSS-drawn placeholder (stone slab +
   pillar) until assets/ui/podium.png is added, which then covers it. */
.preview-podium {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 280px;
  height: 188px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-podium-slab {
  width: 100%;
  height: 34%;
  background: #2c2c4a;
  border: 2px solid #000;
}

.preview-podium-pillar {
  width: 46%;
  height: 66%;
  background: #6c6c8a;
  border: 2px solid #000;
  border-top: none;
}

.preview-podium-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom;
}

.preview-podium-img[hidden] {
  display: none;
}

.preview-podium.has-image .preview-podium-slab,
.preview-podium.has-image .preview-podium-pillar {
  visibility: hidden;
}

/* Play sits on top of the podium itself, roughly centered on its face.
   #btn-play.podium-play-btn (id+class) so width/max-width reliably win
   over the plain .pixel-btn base rules regardless of source order. */
#btn-play.podium-play-btn {
  position: absolute;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  width: 140px;
  max-width: 140px;
  z-index: 3;
}

.menu-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.label {
  font-size: 10px;
  align-self: flex-start;
  color: var(--ink);
}

.label-optional {
  color: #8a8aa3;
}

.pixel-input {
  width: 100%;
  font-family: inherit;
  font-size: 12px;
  padding: 10px 10px;
  background: #0a0a14;
  color: var(--accent-2);
  border: var(--pixel) solid var(--border);
  box-shadow: 4px 4px 0 #000;
  outline: none;
}

.pixel-input::placeholder {
  color: #4a4a63;
}

.pixel-input:focus {
  border-color: var(--accent);
}

.field-error {
  align-self: flex-start;
  color: var(--danger);
  font-size: 10px;
  margin: -4px 0 0 0;
}

.field-note {
  color: #8a8aa3;
  font-size: 10px;
  text-align: center;
}

.hint {
  font-size: 10px;
  color: #8a8aa3;
  margin-top: 8px;
}

/* ---------------- Pixel Button ---------------- */

.pixel-btn {
  font-family: inherit;
  font-size: 12px;
  width: 100%;
  padding: 14px 18px;
  background: var(--panel);
  color: var(--ink);
  border: var(--pixel) solid var(--border);
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
  transition: transform 0.05s ease;
}

.pixel-btn:hover {
  background: #26264a;
}

.pixel-btn:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 #000;
}

.pixel-btn-primary {
  background: var(--accent);
  color: #1a1200;
}

.pixel-btn-primary:hover {
  background: #ffc93c;
}

/* ---------------- Game screen ---------------- */

.hud {
  display: flex;
  gap: 24px;
  font-size: 12px;
  width: 100%;
  max-width: 900px;
  justify-content: space-between;
}

.hud-item span {
  color: var(--accent);
  margin-left: 6px;
}

#game-canvas {
  width: 100%;
  max-width: 900px;
  background: #10182a;
  border: var(--pixel) solid var(--border);
  box-shadow: 6px 6px 0 #000;
  touch-action: none;
}

.wallet-tag {
  font-size: 10px;
  color: #8a8aa3;
}

/* ---------------- Game over ---------------- */

.gameover-stats {
  text-align: center;
  font-size: 12px;
  line-height: 2;
}

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

#screen-gameover .pixel-btn,
#screen-menu .pixel-btn,
#screen-leaderboard .pixel-btn {
  max-width: 320px;
}

/* ---------------- Leaderboard ---------------- */

.leaderboard-wrap {
  width: 100%;
  max-width: 600px;
  background: var(--panel);
  border: var(--pixel) solid var(--border);
  box-shadow: 6px 6px 0 #000;
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.leaderboard-table th,
.leaderboard-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 2px solid #2c2c4a;
  white-space: nowrap;
}

.leaderboard-table th {
  color: var(--accent);
}

.leaderboard-table td.wallet-cell {
  color: var(--accent-2);
}

.leaderboard-table tr.is-you td {
  color: var(--accent);
}

/* Tablet-ish widths: the fixed corner scoreboard/trade-button are wide
   enough at full desktop size to collide with the centered title. Shrink
   just those, not the whole preview/podium layout (which still has
   plenty of room down to the true mobile breakpoint below). */
@media (max-width: 700px) {
  .title { font-size: 16px; }
  .scoreboard { width: 160px; }
  .scoreboard-list, .scoreboard-you { font-size: 8px; }
  #btn-trade.trade-btn { padding: 8px 10px; font-size: 9px; }
}

@media (max-width: 480px) {
  :root { --banner-h: 46px; --footer-h: 24px; }
  .announcement-banner p { white-space: normal; font-size: 8px; line-height: 1.3; }
  .title { font-size: 16px; }
  #btn-trade.trade-btn { left: 10px; padding: 8px 10px; font-size: 9px; }
  .ca-footer { font-size: 7px; }
  .scoreboard { right: 10px; width: 150px; padding: 8px 10px; }
  .scoreboard-title { font-size: 9px; }
  .scoreboard-list, .scoreboard-you { font-size: 8px; }
  .preview-wrap { width: 240px; height: 261px; }
  #preview-canvas, .preview-gif { width: 165px; height: 150px; }
  .preview-podium { width: 210px; height: 141px; }
  #btn-play.podium-play-btn { width: 105px; max-width: 105px; bottom: 45px; padding: 10px; font-size: 10px; }
}
