@font-face {
  font-family: "GameFont";
  src: url("/assets/fonts/game-font.ttf") format("truetype");
  font-display: swap;
}

:root {
  --panel: rgba(31, 31, 38, 0.95);
  --btn: #33333f;
  --btn-hover: #444455;
  --text: #f2f2f2;
  --muted: #a0a0a8;
  --yellow: #f2e64d;
  --blue: #99cce6;
  --gold: #ffd700;
  --silver: #bfbfbf;
  --bronze: #cc8033;
  --red: #ff6666;
  --green: #66ff66;
  /* Pixel font for titles only; everything else uses a readable UI font */
  --title-font: "GameFont", system-ui, sans-serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win. Without this, rules like
   `form { display: flex }` kept the name/PIN form visible for signed-in players. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #111114;
  color: var(--text);
  font-family: var(--ui-font);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* The stage is a fixed 1152x648 box scaled to fit the window by main.js */
#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1152px;
  height: 648px;
  transform-origin: center center;
  overflow: hidden;
  background: #4d4d4d;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

#game {
  position: absolute;
  inset: 0;
  width: 1152px;
  height: 648px;
  display: block;
}

/* ----------------------------- Screens ----------------------------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }
/* THE OG page: the OG's own rusty Hi-Score plate */
#screen-og {
  background: #0c1a1c url("/assets/og/highscore-plate.png") center top / cover no-repeat;
}
.og-card {
  width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 26px 24px;
  border-radius: 14px;
  background: rgba(6, 6, 8, 0.82);
  border: 2px solid #6d5a2c;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.7), inset 0 0 30px rgba(255, 200, 60, 0.06);
  text-align: center;
}
#og-banana { width: 128px; height: 128px; }
.og-title {
  font-family: Impact, "Arial Black", var(--ui-font);
  font-size: 54px;
  letter-spacing: 3px;
  color: #ffc629;
  text-shadow: 0 3px 0 #7a4a00, 0 0 18px rgba(255, 190, 40, 0.5);
  margin: -6px 0 0;
}
.og-sub { color: #d9d2bc; font-size: 14px; }
.og-note { color: var(--muted); font-size: 13px; margin-top: 6px; }
.og-lock { font-size: 22px; font-weight: 800; color: #ff9b5a; }
.og-play { width: 260px; background: linear-gradient(135deg, #b8860b, #ffc629); color: #1b1300; font-weight: 800; }
.og-play:hover:not(:disabled) { background: linear-gradient(135deg, #cf9a12, #ffd452); }
.og-progress { width: 260px; height: 10px; border-radius: 5px; background: #2a2a33; overflow: hidden; margin: 8px auto 0; }
#og-progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #b8860b, #ffc629); }
#screen-og .row { width: 100%; margin-top: 6px; }

/* Menus sit on the animated backdrop (js/background.js) */
#bg-canvas {
  position: absolute;
  inset: 0;
  width: 1152px;
  height: 648px;
  display: block;
}
#bg-canvas[hidden] { display: none; }
.screen.bg { background: transparent; }

.modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  z-index: 10;
}
.modal.active { display: flex; }

.panel {
  width: 340px;
  max-height: 600px;
  background: var(--panel);
  border-radius: 16px;
  padding: 20px 25px 25px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
.panel.wide { width: 460px; }

.panel header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.panel header h2 { flex: 1; text-align: center; margin-right: 38px; }

h1, h2 {
  margin: 0;
  color: var(--yellow);
  text-align: center;
  font-family: var(--title-font);
  font-weight: normal;
}
h1 { font-size: 28px; margin-bottom: 8px; }
h2 { font-size: 24px; }

p { margin: 0; font-size: 14px; }

.muted { color: var(--muted); font-size: 13px; text-align: center; }
.mode-label { color: var(--blue); font-size: 13px; text-align: center; margin-top: -4px; }

/* ----------------------------- Controls ----------------------------- */

button {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--btn);
  border: 0;
  border-radius: 8px;
  min-height: 38px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
button:hover:not(:disabled) { background: var(--btn-hover); }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
button.big { min-height: 44px; font-size: 18px; }
button.small { min-height: 30px; font-size: 12px; padding: 4px 10px; }
button.back { width: 38px; padding: 0; font-size: 18px; }
button.link { background: none; color: var(--muted); font-size: 13px; min-height: 0; text-decoration: underline; }
button.selected { background: #5a5530; color: #fff6a8; }

input[type="text"], input[type="password"] {
  font: inherit;
  font-size: 16px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 2px solid #44444f;
  background: #18181e;
  color: var(--text);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--yellow); }
input[hidden] { display: none; }

input[type="range"] { width: 100%; accent-color: var(--yellow); }

form { display: flex; flex-direction: column; gap: 8px; }

.row { display: flex; gap: 8px; }
.row > button { flex: 1; }

.status { font-size: 13px; min-height: 16px; text-align: center; }
.status.error { color: var(--red); }
.status.ok { color: var(--green); }

.corner-left {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 13px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 10px;
  border-radius: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.corner-left.online { color: #66ff66; }
.corner-left.guest { color: #cccc66; }
.corner-left button.link { padding: 0; font-size: 12px; }

.corner-right {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 8px;
  border-radius: 6px;
}
.corner-right input { width: 120px; }

/* ----------------------------- Lists ----------------------------- */

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
}
.mode-btn b { font-size: 18px; }
.mode-btn small { color: var(--muted); font-size: 13px; font-weight: normal; }

.list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  max-height: 470px;
  padding-right: 4px;
}

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--btn);
  text-align: left;
  min-height: 0;
}
.item .icon { width: 26px; text-align: center; font-size: 18px; }
.item .text { flex: 1; display: flex; flex-direction: column; }
.item .text small { color: var(--muted); font-size: 13px; font-weight: normal; }
.item.locked { opacity: 0.55; }
.item.equipped { background: #5a5530; }
.item .check { color: var(--green); }
.item .cross { color: var(--muted); }

.count { color: var(--yellow); text-align: center; margin-top: 6px; }

.list > * { flex-shrink: 0; }

/* ---------------------------- Icons (js/icons.js) ---------------------------- */
.ico { flex: none; vertical-align: -0.2em; }
button .ico { margin-right: 8px; opacity: 0.92; }
button.back .ico, .icon-btn .ico { margin: 0; }
.panel > button:not(.link), .row > button { display: inline-flex; align-items: center; justify-content: center; }
button.link { display: inline-flex; align-items: center; justify-content: center; gap: 2px; }
button.link .ico { margin-right: 4px; }
.icon-btn { width: 34px; height: 30px; padding: 0; display: grid; place-items: center; }
.icon-btn.is-muted { color: var(--red); }
.corner-left .ico { color: currentColor; }
.og-lock .ico { margin-right: 6px; vertical-align: -0.15em; }

/* Mode buttons: glyph tile + text */
.mode-btn { flex-direction: row; justify-content: flex-start; gap: 14px; text-align: left; padding: 8px 14px; }
.mode-btn .mode-text { display: flex; flex-direction: column; gap: 2px; }
.mode-ico {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 35%, #4b4b5e, #24242e);
  color: var(--yellow);
}
.mode-ico .ico { margin: 0; }
.mode-btn[data-mode="1"] .mode-ico { color: #7cc8ff; }
.mode-btn[data-mode="2"] .mode-ico { color: #ff8a3d; }
.mode-btn[data-mode="4"] .mode-ico { color: #ffc629; }
.mode-btn[data-go="sandbox"] .mode-ico { color: #b8e986; }
.mode-btn:disabled .mode-ico { filter: grayscale(1); opacity: 0.6; }

/* Achievement medals */
.badge {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #2a1a00;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 2px 6px rgba(0, 0, 0, 0.35);
}
.badge .ico { margin: 0; }
.tier-bronze { background: radial-gradient(circle at 35% 30%, #f3b37a, #b0632a 70%); }
.tier-silver { background: radial-gradient(circle at 35% 30%, #ffffff, #9aa3ad 70%); }
.tier-gold { background: radial-gradient(circle at 35% 30%, #fff3a0, #d49b00 70%); }
.tier-platinum { background: radial-gradient(circle at 35% 30%, #ffffff, #8fd3e8 55%, #6c7fd8); }
.tier-secret { background: radial-gradient(circle at 35% 30%, #ffd452, #8a3a10 75%); color: #1b0f00; }
.badge.is-locked { background: #3a3a46; color: #8a8a96; box-shadow: inset 0 0 0 2px #4a4a58; }
.go-extra .badge { width: 20px; height: 20px; display: inline-grid; vertical-align: -0.35em; margin-right: 6px; box-shadow: none; }
.go-extra .ico { margin-right: 6px; vertical-align: -0.2em; }

/* How to Play: two-column rows, bigger text */
.howto-panel { width: 560px; max-height: 624px; overflow-y: auto; gap: 7px; font-size: 16px; line-height: 1.4; padding-top: 16px; padding-bottom: 18px; }
.howto-goal { font-size: 17px; font-weight: 600; text-align: center; color: #f4f4f6; margin: 2px 0 4px; }
.howto-h {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--yellow);
}
.howto-h small { font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--muted); margin-left: 6px; }
.howto-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  column-gap: 12px;
  row-gap: 7px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}
.howto-grid .keys { display: flex; gap: 4px; flex-wrap: wrap; }
.howto-grid img { width: 40px; height: 28px; object-fit: contain; justify-self: center; }
.howto-grid b { color: #fff; }
.howto-panel kbd { font-size: 14px; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: #4a4a58; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35); }
.howto-tip { font-size: 14px; color: var(--muted); text-align: center; margin-top: 4px; }

/* How to Play powerups use the real sprites */
ul.howto.plain { list-style: disc; }
ul.howto:not(.plain) { list-style: none; padding-left: 0; }
ul.howto li.pu { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
ul.howto li.pu img { width: 26px; height: 26px; object-fit: contain; flex: none; }

/* Music tracks: own icon per track, lock badge, equalizer on the playing one */
.track-icon {
  position: relative;
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--tile, #4a3f63) 70%, white), var(--tile, #4a3f63) 75%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
.track-icon .ico { margin: 0; }
.track-icon.is-locked { background: #3a3a46; color: #8a8a96; }
.track-icon .mini-lock {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #1e1e26;
  color: var(--yellow);
}
.track-item .eq { display: none; gap: 3px; align-items: flex-end; height: 18px; }
.track-item.equipped .eq { display: flex; }
.track-item .eq i {
  width: 4px;
  background: var(--yellow);
  border-radius: 2px;
  animation: eq 0.9s ease-in-out infinite;
}
.track-item .eq i:nth-child(2) { animation-delay: -0.3s; }
.track-item .eq i:nth-child(3) { animation-delay: -0.6s; }
.track-item .eq i:nth-child(4) { animation-delay: -0.15s; }
@keyframes eq {
  0%, 100% { height: 4px; }
  50% { height: 18px; }
}

#screen-skins .panel { width: 660px; }
#skin-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 520px;
}
#skin-list .count { grid-column: 1 / -1; }
.skin-item { padding: 4px 10px 4px 4px; min-height: 72px; }
.skin-item .text { min-width: 0; }
.skin-item .text small { line-height: 1.25; }
.skin-item .skin-preview {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 8px;
  background: radial-gradient(circle at 50% 55%, #3a3a4a, #22222b);
}
.skin-item.locked { opacity: 0.75; }
.skin-item.locked .n { color: var(--muted); }
.skin-item .blurb { color: #c9c9d4; font-style: italic; }

.stats {
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  margin: 0;
  white-space: pre-wrap;
}
.stats.scroll { max-height: 480px; overflow-y: auto; }

.scores {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.scores li {
  display: flex;
  justify-content: space-between;
  padding: 5px 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 16px;
}
.scores li.me { color: #ffd94d; }
.scores li.filler { color: var(--muted); font-style: italic; }

.go-extra {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}
.go-extra:empty { display: none; }
.go-extra .pb { color: var(--gold); font-weight: 700; font-size: 16px; }
.go-extra .unlock { color: var(--green); font-weight: 600; }
.go-extra .secret-unlock { color: #ff7a3d; font-weight: 800; font-size: 17px; }
.go-extra .next { color: var(--blue); }

.mode-btn.secret, .item.secret {
  background: linear-gradient(135deg, #5a1a10, #8a3a10);
  color: #ffd27a;
}
.scores li.rank-1 .rank { color: var(--gold); }
.scores li.rank-2 .rank { color: var(--silver); }
.scores li.rank-3 .rank { color: var(--bronze); }
.scores li .rank { width: 34px; }
.scores li .score { font-variant-numeric: tabular-nums; }
.scores li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores .empty { justify-content: center; color: var(--muted); background: none; }

.tabs button { font-size: 14px; }

.score-label {
  font-size: 22px;
  text-align: center;
  line-height: 1.35;
  white-space: pre-line;
}
.score-label.gold { color: var(--gold); }
.score-label.silver { color: var(--silver); }
.score-label.bronze { color: var(--bronze); }

ul.howto { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.6; }
kbd {
  font-family: inherit;
  font-size: 12px;
  background: #44444f;
  border-radius: 4px;
  padding: 1px 5px;
}

/* ----------------------------- Touch / misc ----------------------------- */

/* Phone controls live outside the scaled stage (positions set by fitStage) */
#touch-pad {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
#joy-zone, #action-zone {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}
#joy-base {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.04) 70%);
  border: 3px solid rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  transition: left 0.12s, top 0.12s, opacity 0.2s;
  opacity: 0.75;
}
#joy-base.active { transition: none; opacity: 1; border-color: rgba(242, 230, 77, 0.7); }
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff6b0, #f2c94c 55%, #b8860b);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
}
#action-zone { display: grid; place-items: center; }

#touch-blink {
  position: relative;
  width: min(110px, 80%);
  aspect-ratio: 1;
  height: auto;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  background: radial-gradient(circle at 50% 35%, rgba(255, 170, 60, 0.75), rgba(200, 90, 0, 0.6));
  border: 3px solid rgba(255, 220, 150, 0.7);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
#touch-blink[hidden] { display: none; }

#pause-btn {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 34px;
  z-index: 5;
  background: rgba(20, 20, 28, 0.55);
  opacity: 0.75;
}
#pause-btn:hover { opacity: 1; }
#pause-btn[hidden] { display: none; }
#touch-blink img { width: 46px; height: 34px; object-fit: contain; }

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--yellow);
  background: #1e1e26;
  z-index: 50;
}
#loading.hidden { display: none; }

#rotate-hint {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  color: var(--yellow);
  font-size: 16px;
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-hint { display: block; }
  body.touch-play #rotate-hint { display: none; } /* the controls use that space while playing */
}
