/* ── Variables ──────────────────────────────────────────── */
:root {
  --bg:      #0d0d0d;
  --floor:   #0e1a12;
  --wall:    #0a1628;
  --accent:  #00f5ff;
  --accent2: #ff006e;
  --good:    #39ff14;
  --bad:     #ff1744;
  --panel:   #0f1f2e;
  --text:    #f4f4f4;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  image-rendering: pixelated;
}

/* ── CRT / Vignette ─────────────────────────────────────── */
#crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 200;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.06) 2px,
    rgba(0,0,0,0.06) 4px
  );
}
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 199;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.6) 100%);
}

/* ── App shell ──────────────────────────────────────────── */
#app {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}

.screen {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.screen.hidden { display: none !important; }

/* ── Buttons ────────────────────────────────────────────── */
.btn-primary {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.45rem, 2vw, 0.7rem);
  background: var(--accent); color: var(--bg);
  border: none; cursor: pointer;
  padding: 0.9rem 1.8rem;
  box-shadow: 4px 4px 0 var(--accent2);
  transition: transform 0.05s, box-shadow 0.05s;
  text-transform: uppercase; white-space: nowrap;
}
.btn-primary:hover:not(:disabled) { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--accent2); }
.btn-primary:active:not(:disabled){ transform: translate(2px,2px);  box-shadow: 2px 2px 0 var(--accent2); }
.btn-primary:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-secondary {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.4rem, 1.8vw, 0.6rem);
  background: transparent; color: var(--text);
  border: 2px solid var(--wall); cursor: pointer;
  padding: 0.7rem 1.4rem; margin-top: 0.5rem;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* ── TITLE ──────────────────────────────────────────────── */
#screen-title { background: var(--bg); text-align: center; position: relative; }

.title-box {
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}

.title-gym {
  font-size: clamp(3rem, 12vw, 7rem);
  color: var(--accent);
  text-shadow: 4px 4px 0 var(--accent2), 8px 8px 0 rgba(0,0,0,0.4);
  animation: glow 2s ease-in-out infinite alternate;
  line-height: 1;
}
.title-master {
  font-size: clamp(1.5rem, 6vw, 3.5rem);
  color: var(--accent2);
  text-shadow: 3px 3px 0 rgba(0,0,0,0.4);
  margin-top: -0.5rem;
}
.title-sub {
  font-size: clamp(0.3rem, 1.5vw, 0.55rem);
  color: var(--text); opacity: 0.7;
  letter-spacing: 3px; margin-bottom: 1.5rem;
}
.title-footer {
  position: absolute; bottom: 1.2rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.footer-credit {
  font-size: 0.35rem; color: rgba(244,244,244,0.35);
  letter-spacing: 1px;
}
.enhance-logo-wrap {
  background: #fff;
  padding: 4px 10px;
  border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
}
.enhance-logo-wrap img {
  height: 22px;
  display: block;
  image-rendering: auto;
}
.blink-btn { animation: blink 1.2s step-start infinite; }

@keyframes glow {
  from { text-shadow: 4px 4px 0 var(--accent2), 8px 8px 0 rgba(0,0,0,0.4); }
  to   { text-shadow: 4px 4px 0 var(--accent2), 8px 8px 0 rgba(0,0,0,0.4), 0 0 24px var(--accent); }
}
@keyframes blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ── PANELS (name entry, instructions) ──────────────────── */
.panel {
  background: var(--panel);
  border: 3px solid var(--accent);
  padding: 2rem 2.5rem;
  max-width: 520px; width: 92%;
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.4);
}
.panel-label {
  font-size: 0.55rem; color: var(--accent); letter-spacing: 2px;
}
.text-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.9rem;
  background: var(--bg); color: var(--text);
  border: 2px solid var(--accent);
  padding: 0.75rem 1rem; width: 100%;
  outline: none; text-align: center; text-transform: uppercase;
}
.text-input:focus { border-color: var(--accent2); box-shadow: 0 0 10px var(--accent2); }
.text-input::placeholder { opacity: 0.3; }

/* ── AVATAR SELECT ──────────────────────────────────────── */
.screen-head {
  font-size: clamp(0.5rem, 2.5vw, 1rem);
  color: var(--accent); margin-bottom: 1.5rem; letter-spacing: 2px;
}
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  max-width: 860px; width: 92%; margin-bottom: 1.5rem;
}
@media (max-width: 480px) {
  .avatar-grid { grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
}
.avatar-tile {
  background: var(--panel);
  border: 2px solid var(--wall);
  padding: 1.2rem 0.5rem;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  transition: border-color 0.1s, box-shadow 0.1s;
  user-select: none;
}
.avatar-tile:hover  { border-color: var(--accent); }
.avatar-tile.selected {
  border-color: var(--accent);
  background: rgba(0,245,255,0.10);
  box-shadow: 0 0 10px var(--accent);
}
.avatar-emoji { font-size: clamp(2rem, 5vw, 3.5rem); }
.avatar-name  { font-size: clamp(0.35rem, 1vw, 0.55rem); text-align: center; }
.avatar-arch  { font-size: clamp(0.28rem, 0.8vw, 0.42rem); color: var(--accent2); text-align: center; }

/* ── INSTRUCTIONS ───────────────────────────────────────── */
.inst-panel { max-width: 560px; min-height: 260px; justify-content: space-between; }
.panel-title {
  font-size: clamp(0.5rem, 2.5vw, 0.75rem);
  color: var(--accent); text-align: center; letter-spacing: 2px;
}
.panel-body {
  font-family: 'VT323', monospace;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  color: var(--text); line-height: 1.7; flex: 1;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: 0.5rem 0; width: 100%; gap: 0.1rem;
}
.score-row {
  display: flex; align-items: baseline; gap: 0.6rem; width: 100%;
}
.score-label { color: var(--accent2); min-width: 13rem; flex-shrink: 0; }
.score-val   { color: var(--text); }
.key {
  display: inline-block;
  background: var(--bg); border: 1px solid var(--accent);
  padding: 1px 6px; margin: 0 3px;
  font-family: 'Press Start 2P', monospace; font-size: 0.55rem;
}
.ctrl-row  { margin-bottom: 0.4rem; }
.ctrl-touch { margin-top: 0.6rem; font-size: 1rem; color: var(--accent2); }
.c-good { color: var(--good); }
.c-bad  { color: var(--bad); }
.c-warn { color: var(--accent); }

/* ── HUD ────────────────────────────────────────────────── */
#screen-playing {
  justify-content: flex-start;
  position: relative;
  overflow: hidden;
}
#hud {
  display: flex; align-items: center; justify-content: space-around;
  background: var(--panel); border-bottom: 2px solid var(--accent);
  padding: 0.4rem 1rem; width: 100%; max-width: 980px;
  flex-shrink: 0;
}
.hud-lbl { font-size: clamp(0.25rem, 1.2vw, 0.4rem); color: var(--accent2); margin-bottom: 3px; }
.hud-val { font-size: clamp(0.5rem, 2.5vw, 0.85rem); }
#hud-combo.combo-high { color: var(--accent); animation: comboFlash 0.4s infinite alternate; }
@keyframes comboFlash { from { color: var(--accent); } to { color: var(--accent2); } }

.hud-timer-cell { flex: 1; max-width: 140px; }
#hud-timer-bar {
  height: 12px; background: var(--bg);
  border: 1px solid var(--accent); overflow: hidden; min-width: 80px;
}
.timer-fill { height: 100%; background: var(--good); transition: width 0.1s linear, background 0.4s; }
.timer-fill.warning { background: var(--accent); }
.timer-fill.danger  { background: var(--bad); animation: timerFlash 0.25s infinite; }
@keyframes timerFlash { 50% { opacity: 0.4; } }

/* ── Client request bar ─────────────────────────────────── */
#client-request {
  font-size: clamp(0.55rem, 2.8vw, 0.9rem);
  color: var(--accent);
  padding: 0.55rem 1rem; text-align: center;
  background: rgba(13,13,13,0.9);
  width: 100%; max-width: 980px;
  border-bottom: 2px solid var(--accent2);
  flex-shrink: 0;
}
.cr-label { color: var(--accent2); margin-right: 0.5rem; }

@keyframes exercise-pulse {
  0%, 100% {
    color: #ffffff;
    text-shadow: 0 0 6px var(--accent), 0 0 14px var(--accent);
  }
  50% {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent), 0 0 28px var(--accent), 0 0 48px var(--accent);
  }
}
#client-exercise {
  color: #ffffff;
  animation: exercise-pulse 1.4s ease-in-out infinite;
}

/* ── Gym floor ──────────────────────────────────────────── */
#floor-wrap {
  flex: 1;
  display: flex; align-items: flex-start; justify-content: center;
  width: 100%; overflow: hidden;
  height: 768px;
}
#gym-floor {
  position: relative;
  width: 1280px; height: 768px;        /* 20×12 tiles @ 64px */
  background-color: var(--floor);
  background-image:
    linear-gradient(rgba(0,245,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,245,255,0.06) 1px, transparent 1px);
  background-size: 64px 64px;
  border: 4px solid var(--accent);
  box-shadow: 0 0 30px rgba(0,245,255,0.15), inset 0 0 60px rgba(0,0,0,0.4);
  flex-shrink: 0;
}

/* ── Machines ───────────────────────────────────────────── */
.machine-tile {
  position: absolute;
  width: 96px; height: 96px;
  /* centre the 96px tile on the 64px grid cell */
  transform: translate(-16px, -16px);
  background: rgba(10,22,40,0.92);
  border: 1px solid rgba(0,245,255,0.4);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  overflow: visible; z-index: 2;
  transition: background 0.12s, box-shadow 0.12s;
}
.machine-tile svg {
  width: 80px; height: 80px;
  color: var(--accent);
  filter: drop-shadow(0 0 3px var(--accent));
  transition: filter 0.12s;
}
.machine-label {
  position: absolute; top: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  background: rgba(13,13,13,0.95);
  color: var(--accent);
  font-family: 'VT323', monospace; font-size: 24px;
  white-space: nowrap; padding: 2px 6px;
  border: 1px solid rgba(0,245,255,0.4);
  display: block; z-index: 10;
  pointer-events: none;
}
.machine-tile:hover { border-color: var(--accent); box-shadow: 0 0 8px rgba(0,245,255,0.4); }
.machine-tile:hover .machine-label { color: #fff; border-color: var(--accent); }

.machine-tile.feedback-good {
  background: rgba(57,255,20,0.15);
  box-shadow: 0 0 20px var(--good);
  border-color: var(--good);
}
.machine-tile.feedback-good svg { color: var(--good); filter: drop-shadow(0 0 6px var(--good)); }

.machine-tile.feedback-bad {
  background: rgba(255,23,68,0.15);
  box-shadow: 0 0 20px var(--bad);
  border-color: var(--bad);
}
.machine-tile.feedback-bad svg { color: var(--bad); filter: drop-shadow(0 0 6px var(--bad)); }

/* ── Avatar ─────────────────────────────────────────────── */
.avatar {
  position: absolute;
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  font-size: 54px; z-index: 5; pointer-events: none;
  filter: drop-shadow(0 0 6px var(--accent2));
}

/* flip horizontally when facing left */
.avatar[data-facing="left"]  { transform: scaleX(-1); }
.avatar[data-facing="right"] { transform: scaleX(1); }

/* walking bob: 2-frame retro bounce synced to the 80ms step */
@keyframes walk {
  0%, 100% { margin-top: 0px; }
  50%       { margin-top: -10px; }
}
.avatar.walking {
  animation: walk 0.16s steps(2, end) infinite;
}

/* ── Float text ─────────────────────────────────────────── */
.float-text {
  position: absolute;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px; pointer-events: none; z-index: 20;
  animation: floatUp 0.65s ease-out forwards;
}
.float-good { color: var(--good); }
.float-bad  { color: var(--bad); }
@keyframes floatUp {
  0%   { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-44px); opacity: 0; }
}

/* ── Screen shake ───────────────────────────────────────── */
@keyframes shake {
  0%,100% { transform: translate(0); }
  10%     { transform: translate(-7px,-2px) rotate(-0.5deg); }
  20%     { transform: translate(7px, 2px) rotate(0.5deg); }
  30%     { transform: translate(-5px, 0); }
  40%     { transform: translate(5px, 0); }
  50%     { transform: translate(-3px,-1px); }
  60%     { transform: translate(3px, 1px); }
  75%     { transform: translate(-2px, 0); }
  90%     { transform: translate(1px, 0); }
}
.shake { animation: shake 0.45s ease-in-out; }

/* ── Touch controls ─────────────────────────────────────── */
#touch-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0.5rem 1.2rem 0.7rem;
  background: linear-gradient(transparent, rgba(13,13,13,0.75) 40%);
  z-index: 30;
}
#touch-controls.hidden { display: none; }

#dpad { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dpad-mid { display: flex; gap: 2px; }
.dpad-center { width: 44px; height: 44px; background: transparent; }

.dpad-btn {
  width: 44px; height: 44px;
  font-family: 'Press Start 2P', monospace; font-size: 0.9rem;
  background: rgba(15,31,46,0.75); color: var(--text);
  border: 2px solid var(--accent); cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  display: flex; align-items: center; justify-content: center;
}
.dpad-btn:active { background: var(--accent); color: var(--bg); }

.action-btn {
  width: 52px; height: 52px;
  font-family: 'Press Start 2P', monospace; font-size: 1.1rem;
  background: rgba(255,0,110,0.75); color: var(--text);
  border: 2px solid var(--accent2); cursor: pointer; border-radius: 50%;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  align-self: center;
}
.action-btn:active { background: var(--accent2); }

/* ── Pause button (in HUD) ──────────────────────────────── */
.btn-pause, .btn-fs {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  background: transparent;
  color: var(--accent2);
  border: 1px solid var(--accent2);
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-pause { letter-spacing: 2px; }
.btn-fs    { font-family: system-ui, sans-serif; font-size: 1rem; line-height: 1; padding: 0.1rem 0.45rem; }
.btn-pause:hover, .btn-fs:hover { background: rgba(255,0,110,0.15); }
.btn-pause.active               { background: rgba(255,0,110,0.25); color: var(--text); }

.fs-tip {
  position: absolute; top: 3.5rem; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent);
  color: var(--text); font-family: 'VT323', monospace; font-size: 1rem;
  padding: 0.4rem 0.8rem; white-space: nowrap; z-index: 60;
  animation: fadeInOut 4s ease forwards;
}
.fs-tip.hidden { display: none; }
.fs-tip strong { color: var(--accent); }

@keyframes fadeInOut {
  0%   { opacity: 0; }
  10%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Pause overlay ──────────────────────────────────────── */
#pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13,13,13,0.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
#pause-overlay.hidden { display: none; }

.pause-box {
  display: flex; flex-direction: column; align-items: center; gap: 2rem;
}
.pause-title {
  font-size: clamp(1.5rem, 6vw, 3rem);
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent);
  animation: glow 1.5s ease-in-out infinite alternate;
}

/* ── GAME OVER ──────────────────────────────────────────── */
#screen-game-over { gap: 1rem; overflow-y: auto; padding: 1rem; }

.go-title {
  font-size: clamp(1.2rem, 6vw, 2.5rem);
  color: var(--bad);
  text-shadow: 4px 4px 0 rgba(0,0,0,0.5);
  animation: shake 0.5s ease-in-out;
}

.stats-box {
  background: var(--panel); border: 2px solid var(--accent);
  padding: 0.8rem 2rem; min-width: 280px;
}
.stat-row {
  display: flex; justify-content: space-between;
  font-size: clamp(0.4rem, 2vw, 0.65rem);
  padding: 0.45rem 0; border-bottom: 1px solid var(--wall);
}
.stat-row:last-child { border-bottom: none; }

.submit-status {
  font-family: 'VT323', monospace; font-size: 1.1rem;
  color: var(--bad); min-height: 1.2rem;
}

#lb-wrap {
  max-width: 480px; width: 92%;
}
.lb-head {
  font-size: clamp(0.4rem, 2vw, 0.6rem);
  color: var(--accent); text-align: center; margin-bottom: 0.5rem;
}
#leaderboard-list {
  background: var(--panel); border: 2px solid var(--accent);
  max-height: 220px; overflow-y: auto;
}
.lb-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.75rem; border-bottom: 1px solid var(--wall);
  font-family: 'VT323', monospace; font-size: 1.2rem;
}
.lb-row:last-child { border-bottom: none; }
.lb-row.gold   { background: rgba(0,245,255,0.12); }
.lb-row.silver { background: rgba(255,255,255,0.04); }
.lb-row.bronze { background: rgba(255,0,110,0.08); }
.lb-rank   { color: var(--accent2); min-width: 2.2rem; }
.lb-name   { flex: 1; }
.lb-score  { color: var(--accent); min-width: 5rem; text-align: right; }
.lb-clients{ color: var(--accent2); min-width: 3rem; text-align: right; }
.lb-loading{ padding: 1rem; text-align: center; font-family: 'VT323', monospace; font-size: 1.2rem; color: var(--accent2); }

.go-buttons { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
