/* ============================================================
   SMASH CLUB — 16-bit UI
   Hard edges, double borders (black outer / white inner), zero
   blur, chunky monospace caps. Matches the pixel-art reference.
   ============================================================ */

:root {
  --ink:      #241436;
  --ink-2:    #3B2A57;
  --cream:    #FFF4E4;
  --pink:     #FF6FA5;
  --pink-hi:  #FFA8CB;
  --mint:     #5FD6B4;
  --sky:      #8ED2E6;
  --lemon:    #FFD23F;
  --grape:    #8F6BE8;
  --coral:    #FF6B6B;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --pixel-font: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #14102A;
  font-family: var(--pixel-font);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

#stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; }

/* The backbuffer is ~200px wide; nearest-neighbour keeps it crunchy. */
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

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

.hidden { display: none !important; }

/* ---------- shared 16-bit box: black outer, white inner ---------- */

.box {
  border: 3px solid var(--ink);
  box-shadow:
    inset 0 0 0 2px var(--cream),
    4px 4px 0 0 rgba(36, 20, 54, .55);
}

/* ------------------------------ HUD ------------------------------ */

#hud {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  left: 8px;
  right: 8px;
  pointer-events: none;
  z-index: 5;
}

.hud-row { display: flex; align-items: stretch; gap: 6px; }

.chip {
  background: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--cream), 3px 3px 0 rgba(0, 0, 0, .4);
  padding: 4px 9px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--cream);
}

.chip-label { font-size: 8px; letter-spacing: .2em; opacity: .7; }

#hud-time {
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  min-width: 62px;
  color: var(--lemon);
}

.chip-combo {
  background: var(--pink);
  color: var(--ink);
  font-size: 16px;
  padding: 4px 10px;
  animation: pop .14s steps(2, end);
}

#hud-combo { color: var(--ink); }

@keyframes pop {
  from { transform: translateY(-3px) scale(1.25); }
  to   { transform: none; }
}

/* In-game mute. The HUD is pointer-events:none, so this has to opt
   back in — and being a DOM button above the canvas, tapping it can
   never smash a pane underneath. */
.hud-mute {
  pointer-events: auto;
  margin-left: auto;
  flex: 0 0 auto;
  width: 40px;
  height: 34px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  background: var(--ink);
  color: var(--cream);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--cream), 3px 3px 0 rgba(0, 0, 0, .4);
  cursor: pointer;
}

.hud-mute:active { transform: translate(3px, 3px); box-shadow: inset 0 0 0 2px var(--cream); }
.hud-mute.is-muted { background: var(--coral); }

/* ---------------------------- FINALE ----------------------------- */

#finale-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 26px);
  z-index: 6;
  text-align: center;
  font-size: 10px;
  letter-spacing: .22em;
  color: var(--cream);
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
  animation: blink 1.1s steps(2, end) infinite;
}

@keyframes blink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: .15; }
}

/* ----------------------------- TOAST ----------------------------- */

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 60px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: 84%;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--cream);
  border: 3px solid #000;
  box-shadow: inset 0 0 0 2px var(--cream), 4px 4px 0 #000;
  font-size: 10px;
  letter-spacing: .1em;
  text-align: center;
  pointer-events: none;
  animation: toastIn .16s steps(3, end);
}

@keyframes toastIn {
  from { transform: translate(-50%, 8px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

/* --------------------------- BOARD STATUS ------------------------- */

.board-status {
  font-size: 8px;
  letter-spacing: .2em;
  margin: -6px 0 10px;
  color: var(--sky);
  opacity: .75;
}

.board-status.is-offline { color: var(--lemon); }
.board-status.is-local   { color: var(--pink-hi); }

.bar-wrap { margin-top: 6px; }

.bar {
  height: 11px;
  border: 3px solid var(--ink);
  background: #3B2A57;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .4);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 100%;
  background: repeating-linear-gradient(
    90deg,
    var(--pink) 0 4px,
    var(--pink-hi) 4px 8px
  );
  transition: width .12s steps(4, end);
}

.bar-label {
  margin-top: 4px;
  font-size: 9px;
  letter-spacing: .16em;
  color: var(--cream);
  text-shadow: 2px 2px 0 var(--ink);
}

/* ---------------------------- SCREENS ---------------------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 14px) 14px calc(var(--safe-bottom) + 14px);
  background: rgba(20, 16, 42, .82);
  overflow-y: auto;
}

.screen.transparent { background: transparent; pointer-events: none; }

.panel {
  width: 100%;
  max-width: 340px;
  background: var(--ink);
  border: 3px solid #000;
  box-shadow:
    inset 0 0 0 3px var(--cream),
    inset 0 0 0 6px var(--ink),
    6px 6px 0 rgba(0, 0, 0, .5);
  padding: 20px 16px 16px;
  text-align: center;
  color: var(--cream);
  animation: rise .16s steps(3, end);
}

@keyframes rise {
  from { transform: translateY(8px); opacity: .3; }
  to   { transform: none; opacity: 1; }
}

/* ----------------------------- TITLE ----------------------------- */

.logo {
  margin: 0;
  font-size: 34px;
  line-height: .95;
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--pink);
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink),
    0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    4px 5px 0 #000;
}

.logo span { display: block; color: var(--mint); }

.tag {
  margin: 12px 0 2px;
  font-size: 9.5px;
  letter-spacing: .1em;
  line-height: 1.6;
  color: var(--pink-hi);
}

.title-best {
  margin: 6px 0 0;
  font-size: 9px;
  letter-spacing: .16em;
  color: var(--lemon);
  text-shadow: 2px 2px 0 #000;
}

.hero-strip { display: flex; justify-content: center; margin: 4px 0 10px; }
/* keep in ratio with the 220x200 backing store, or she squashes */
#hero-canvas { width: 176px; height: 160px; }

.hint {
  margin: 12px 0 0;
  font-size: 8.5px;
  letter-spacing: .1em;
  line-height: 1.8;
  color: var(--sky);
  opacity: .8;
}

/* ----------------------------- BUTTONS --------------------------- */

.btn {
  display: block;
  width: 100%;
  border: 3px solid #000;
  box-shadow: inset 0 0 0 2px var(--ink), 4px 4px 0 #000;
  padding: 12px 12px;
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--cream);
  cursor: pointer;
  transition: none;
}

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

.btn-primary { background: var(--lemon); }
.btn-ghost   { background: var(--sky); font-size: 10px; padding: 10px 8px; }
.btn-danger  { background: var(--coral); }

.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .btn { margin: 0; }
#btn-mute { flex: 0 0 52px; font-size: 14px; }

/* ---------------------------- COUNTDOWN -------------------------- */

#screen-countdown { align-items: center; }

.countdown-stack { text-align: center; }

/* Same face as the counter, sized down so two lines fit any phone. */
#countdown-msg {
  font-size: 34px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--pink);
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink),
    0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    5px 6px 0 #000;
  animation: msgPunch .9s steps(5, end);
}

@keyframes msgPunch {
  0%   { transform: scale(.3); opacity: 0; }
  40%  { transform: scale(1.15); opacity: 1; }
  60%  { transform: scale(1); }
  100% { transform: scale(1); opacity: 1; }
}

#countdown-num {
  font-size: 84px;
  font-weight: 800;
  color: var(--lemon);
  text-shadow:
    4px 0 0 var(--ink), -4px 0 0 var(--ink),
    0 4px 0 var(--ink), 0 -4px 0 var(--ink),
    6px 8px 0 #000;
  animation: countPop .6s steps(6, end);
}

@keyframes countPop {
  0%   { transform: scale(1.9); opacity: 0; }
  30%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(.8); opacity: .2; }
}

/* ----------------------------- RESULT ---------------------------- */

.result-kicker {
  margin: 0;
  font-size: 15px;
  letter-spacing: .18em;
  color: var(--pink);
  text-shadow: 2px 2px 0 #000;
}

.result-time {
  font-size: 44px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--mint);
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink),
    0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    5px 6px 0 #000;
  margin: 8px 0 10px;
}

.result-meta {
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: 8.5px;
  letter-spacing: .1em;
  color: var(--sky);
  margin-bottom: 12px;
}

.result-meta b { color: var(--lemon); }

.rank-note {
  background: var(--lemon);
  color: var(--ink);
  border: 3px solid #000;
  box-shadow: inset 0 0 0 2px var(--ink), 3px 3px 0 #000;
  padding: 8px 8px;
  font-size: 9.5px;
  letter-spacing: .1em;
  line-height: 1.5;
  margin-bottom: 12px;
}

/* ----------------------------- FIELDS ---------------------------- */

.field { display: block; text-align: left; margin-bottom: 9px; }

.field span {
  display: block;
  font-size: 8px;
  letter-spacing: .18em;
  color: var(--pink-hi);
  margin: 0 0 4px 2px;
}

.field input {
  width: 100%;
  border: 3px solid #000;
  box-shadow: inset 0 0 0 2px var(--ink);
  padding: 10px 10px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--cream);
  color: var(--ink);
  outline: none;
  border-radius: 0;
  -webkit-appearance: none;
}

.field input:focus { box-shadow: inset 0 0 0 2px var(--pink); }
.field input::placeholder { color: #9A8CA8; }

#entry-form { margin-bottom: 4px; }

/* --------------------------- LEADERBOARD ------------------------- */

.board-title {
  margin: 0 0 12px;
  font-size: 20px;
  letter-spacing: .12em;
  color: var(--lemon);
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink),
    0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    4px 5px 0 #000;
}

.board-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  text-align: left;
  max-height: 44vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.board-list li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 3px solid #000;
  box-shadow: inset 0 0 0 2px rgba(36, 20, 54, .35), 3px 3px 0 #000;
  padding: 7px 8px;
  margin-bottom: 7px;
  background: var(--cream);
  color: var(--ink);
}

.board-list li.is-you { outline: 3px solid var(--pink); outline-offset: 2px; }
.board-list li.rank-1 { background: var(--lemon); }
.board-list li.rank-2 { background: var(--sky); }
.board-list li.rank-3 { background: var(--mint); }

.b-rank {
  flex: 0 0 22px;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.b-body { flex: 1; min-width: 0; }

.b-top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }

.b-name {
  font-weight: 800;
  font-size: 11px;
  letter-spacing: .08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.b-time {
  font-weight: 800;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.b-msg {
  font-size: 9px;
  letter-spacing: .04em;
  text-transform: none;
  opacity: .8;
  margin-top: 3px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.b-date {
  font-size: 7.5px;
  letter-spacing: .12em;
  opacity: .5;
  margin-top: 3px;
}

/* Short viewports (iPhone SE) */
@media (max-height: 680px) {
  .logo { font-size: 27px; }
  #hero-canvas { width: 140px; height: 118px; }
  .result-time { font-size: 36px; }
  .board-list { max-height: 34vh; }
  .panel { padding: 16px 14px 14px; }
}
