@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; }

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; }
/* 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; }

/* 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;
  font-size: 22px;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, #4a3f63, #26222f);
}
.track-icon.is-locked { filter: grayscale(1) brightness(0.6); }
.track-icon.is-locked::after {
  content: "🔒";
  position: absolute;
  right: -4px;
  bottom: -4px;
  font-size: 13px;
  filter: none;
}
.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 ----------------------------- */

#touch-blink {
  position: absolute;
  right: 24px;
  bottom: 24px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  font-size: 20px;
  background: rgba(255, 140, 0, 0.55);
  z-index: 5;
}

#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; }
}
