/* ======= SCHOOL OF HARD KNOCKS — GAME SECTION ======= */
.play {
  position: relative;
  padding: 7rem 0;
  background: var(--dark);
  overflow: hidden;
}
.play-grain {
  position: absolute; inset: 0; opacity: 0.06; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px;
}
.play-subtitle {
  margin-top: 0.5rem;
  font-family: var(--font-sub); font-size: 0.8rem; font-weight: 600;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--gray);
}

.game-wrap {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto;
  background: var(--dark2);
  border: 1px solid var(--dark3);
}

/* ---- FULLSCREEN (native via class synced on fullscreenchange, or CSS fallback on iOS) ---- */
.game-wrap.fs {
  position: fixed; inset: 0; z-index: 10000;
  height: 100dvh; bottom: auto; /* iOS: dvh keeps the panel buttons above the browser chrome */
  max-width: none; margin: 0; border: none;
  display: flex; flex-direction: column;
  background: var(--black);
}
.game-wrap.fs .game-panel {
  overflow-y: auto;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}
.game-wrap.fs .game-stage {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
body.fs-lock { overflow: hidden; }

/* ---- HUD ---- */
.game-hud {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 3rem 0.9rem 1.5rem;
  border-bottom: 1px solid var(--dark3);
  gap: 0.5rem;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; min-width: 72px; }
.hud-label { font-family: var(--font-sub); font-size: 0.62rem; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gray); }
.hud-value { font-family: var(--font-head); font-size: clamp(1.4rem, 4vw, 2rem); line-height: 1; color: var(--white); }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; min-width: 0; }
.hud-level {
  font-family: var(--font-sub); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--red-light);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.hud-level:empty { display: none; }
.hud-lives { display: flex; align-items: center; gap: 0.5rem; }
.life-pip {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--red-light);
  box-shadow: 0 0 8px var(--red-glow);
  transition: all var(--transition);
}
.life-pip.lost { background: transparent; border: 1.5px solid var(--dark3); box-shadow: none; opacity: 0.5; }
.life-pip.pip-hit { animation: pipHit 0.45s ease; }
@keyframes pipHit {
  0%   { transform: scale(1.8); background: var(--white); box-shadow: 0 0 16px var(--red-glow); }
  100% { transform: scale(1); }
}
.hud-value.bump, #game-combo-value.bump { animation: hudBump 0.22s ease; display: inline-block; }
@keyframes hudBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); color: var(--red-light); }
  100% { transform: scale(1); }
}
.game-combo {
  display: flex; align-items: center; gap: 0.4rem;
  font-family: var(--font-sub); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--gray);
}
.game-combo #game-combo-value { color: var(--red-light); font-size: 0.85rem; }
.beat-dot {
  width: 8px; height: 8px;
  background: var(--dark3);
  transition: background 0.05s linear, box-shadow 0.05s linear;
}
.beat-dot.tick { background: var(--red-light); box-shadow: 0 0 8px var(--red-glow); }
.fs-btn {
  position: absolute; top: 0.6rem; right: 0.6rem;
  background: none; border: 1px solid rgba(245,245,245,0.2);
  color: var(--gray-light); font-size: 0.95rem; line-height: 1;
  width: 30px; height: 30px; cursor: pointer;
  transition: all var(--transition);
}
.fs-btn:hover { color: var(--white); border-color: var(--red); }
.mute-btn { right: 3.1rem; font-size: 0.8rem; }
.pu-badge {
  font-family: var(--font-sub); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: #f0c060;
}
.pu-badge:empty { display: none; }

/* ---- STAGE / CANVAS ---- */
.game-stage {
  position: relative;
  background: var(--black);
}
/* DOM-level punch on death, rage smash and musical drops (reuses the global shake keyframes) */
.game-stage.stage-shake { animation: shake 0.45s ease; }
#game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  background: var(--black);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- TOAST + TUTORIAL PROMPT ---- */
.game-toast {
  position: absolute; top: 12%; left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-head); font-size: clamp(1.2rem, 3.5vw, 1.9rem);
  letter-spacing: 0.1em; color: var(--white);
  text-shadow: 0 0 14px var(--red-glow), 0 2px 4px rgba(0,0,0,0.9);
  pointer-events: none; opacity: 0; z-index: 3;
  white-space: nowrap;
}
.game-toast.show { animation: toastPop 0.9s ease forwards; }
@keyframes toastPop {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.6); }
  15%  { opacity: 1; transform: translateX(-50%) scale(1.08); }
  30%  { transform: translateX(-50%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(1); }
}
.tut-prompt {
  position: absolute; bottom: 26%; left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-sub); font-size: clamp(0.8rem, 2.2vw, 1rem); font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--white);
  background: rgba(10,10,10,0.75);
  border: 1px solid var(--red);
  box-shadow: 0 0 16px var(--red-glow);
  padding: 0.45rem 1rem;
  pointer-events: none; opacity: 0; z-index: 3;
  transition: opacity 0.25s ease;
  white-space: nowrap; max-width: 94%;
}
.tut-prompt.show { opacity: 1; }

/* ---- OVERLAY PANELS (all states live in ONE screen as overlays) ---- */
.game-panel {
  position: absolute; inset: 0; z-index: 4;
  display: none;
  flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 0.7rem; padding: 1rem;
  background: rgba(10, 10, 10, 0.9);
}
.game-stage[data-state="title"]    .game-titlescreen,
.game-stage[data-state="levels"]   .game-levels,
.game-stage[data-state="scores"]   .game-scores,
.game-stage[data-state="loading"]  .game-loading,
.game-stage[data-state="paused"]   .game-paused,
.game-stage[data-state="complete"] .game-complete,
.game-stage[data-state="gameover"] .game-over,
.game-stage[data-state="finale"]   .game-finale { display: flex; }

/* panels pop in every time they appear (display switch restarts the animation) */
.game-panel { animation: panelIn 0.28s ease; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.game-panel-title {
  font-family: var(--font-head); font-size: clamp(1.5rem, 4vw, 2.2rem);
  letter-spacing: 0.05em; color: var(--white); line-height: 1;
}
.game-panel-text { font-size: 0.82rem; color: rgba(245,245,245,0.72); line-height: 1.55; max-width: 480px; }

.btn-lg { padding: 0.9rem 2.3rem; font-size: 0.95rem; min-height: 50px; }

.game-hint { display: none; font-size: 0.7rem; color: var(--gray); letter-spacing: 0.05em; }
.game-touch-hint { display: block; font-size: 0.7rem; color: var(--gray); letter-spacing: 0.05em; }
@media (hover: hover) and (pointer: fine) {
  .game-hint { display: block; }
  .game-touch-hint { display: none; }
}

/* ---- TITLE SCREEN ---- */
.game-logo {
  font-family: var(--font-head);
  font-size: clamp(1.9rem, 5.5vw, 3rem);
  line-height: 0.95; letter-spacing: 0.06em;
  color: var(--white);
  text-shadow: 3px 3px 0 var(--red), 0 0 24px var(--red-glow);
}
.game-logo span { color: var(--red-light); font-size: 0.6em; }
.title-skins { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.title-skins-label { font-family: var(--font-sub); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gray); }
.title-secondary { display: flex; gap: 0.6rem; }
.title-secondary .btn { padding: 0.55rem 1.2rem; font-size: 0.75rem; }

/* ---- CHARACTER ROW ---- */
.char-row { display: flex; gap: 0.45rem; justify-content: center; flex-wrap: wrap; }
.char-slot {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
  background: rgba(245,245,245,0.04);
  border: 1px solid var(--dark3);
  padding: 0.4rem 0.4rem 0.35rem;
  cursor: pointer;
  transition: all var(--transition);
}
.char-slot:hover { border-color: var(--red); }
.char-slot.selected { border-color: var(--red-light); box-shadow: 0 0 14px var(--red-glow); background: rgba(139,26,26,0.12); }
.char-slot.locked { cursor: default; opacity: 0.5; }
.char-slot.locked:hover { border-color: var(--dark3); }
.char-thumb {
  width: 60px; height: 60px; /* 40×40-Portrait ×1.5 */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
.char-name {
  font-family: var(--font-sub); font-size: 0.58rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--white);
}
.char-slot.locked .char-name { color: var(--gray); }
.char-lock { font-size: 0.5rem; color: var(--gray); letter-spacing: 0.04em; line-height: 1.2; }

/* ---- STORY BANNER (over the running level) ---- */
.story-banner {
  position: absolute; top: 8%; left: 4%;
  max-width: 62%;
  display: flex; flex-direction: column; gap: 0.2rem;
  text-align: left;
  background: rgba(10,10,10,0.78);
  border-left: 3px solid var(--red);
  box-shadow: 0 0 18px rgba(0,0,0,0.5);
  padding: 0.55rem 0.8rem;
  pointer-events: none; z-index: 3;
  opacity: 0; transform: translateX(-12px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.story-banner.show { opacity: 1; transform: translateX(0); }
.story-tag {
  font-family: var(--font-sub); font-size: 0.58rem; font-weight: 700;
  letter-spacing: 0.25em; text-transform: uppercase; color: var(--red-light);
}
.banner-title {
  font-family: var(--font-head); font-size: 1.15rem; letter-spacing: 0.06em;
  color: var(--white); line-height: 1;
}
.story-banner.show .banner-title { animation: stampIn 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes stampIn {
  from { transform: scale(2.1); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.banner-text {
  font-size: 0.68rem; color: rgba(245,245,245,0.75); line-height: 1.45;
  font-style: italic;
}
@media (max-width: 480px) {
  .story-banner { max-width: 80%; padding: 0.4rem 0.6rem; }
  .banner-text { font-size: 0.6rem; }
}

/* ---- LEVEL SELECT ---- */
.level-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem;
  width: 100%; max-width: 480px;
}
.level-tile {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: rgba(245,245,245,0.04);
  border: 1px solid var(--dark3);
  padding: 0.5rem 0.25rem 0.4rem;
  cursor: pointer;
  transition: all var(--transition);
}
.level-tile:hover { border-color: var(--red); }
.level-tile.locked { opacity: 0.45; cursor: default; }
.level-tile.locked:hover { border-color: var(--dark3); }
.level-num { font-family: var(--font-head); font-size: 1.15rem; color: var(--red-light); line-height: 1; }
.level-name {
  font-family: var(--font-sub); font-size: 0.55rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--white);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.level-tile.locked .level-name { color: var(--gray); }
.level-best { font-size: 0.55rem; color: var(--gray); }
.training-note { font-size: 0.68rem; }

/* ---- SCORES ---- */
.scores-note { font-size: 0.68rem; color: var(--gray); letter-spacing: 0.08em; text-transform: uppercase; }
.scores-note.hidden { display: none; }
.scores-list {
  list-style: none; width: 100%; max-width: 340px;
  max-height: 52%; overflow-y: auto;
  font-family: var(--font-sub); font-size: 0.82rem;
  border-top: 1px solid var(--dark3);
}
.scores-list li {
  display: flex; align-items: baseline; gap: 0.6rem;
  padding: 0.32rem 0.5rem;
  border-bottom: 1px solid var(--dark3);
}
.scores-list .sc-rank { color: var(--red-light); font-family: var(--font-head); min-width: 1.7em; }
.scores-list .sc-name { color: var(--white); letter-spacing: 0.15em; font-weight: 700; }
.scores-list .sc-score { margin-left: auto; color: var(--gray-light); font-variant-numeric: tabular-nums; }
.scores-list li.sc-me { background: rgba(139,26,26,0.15); }
.scores-list li.sc-empty { justify-content: center; color: var(--gray); }

/* ---- COMPLETE / GAME OVER / FINALE ---- */
.game-final-score { font-family: var(--font-sub); font-size: 0.95rem; color: var(--white); letter-spacing: 0.05em; }
.game-final-score span:last-child { font-family: var(--font-head); font-size: 1.45rem; color: var(--red-light); }
.game-newhigh {
  font-family: var(--font-head); font-size: 1.2rem; letter-spacing: 0.08em;
  color: var(--red-light);
  text-shadow: 0 0 16px var(--red-glow);
  animation: pulse 1.2s infinite;
}
.game-newhigh.hidden { display: none; }
.game-unlock-info { font-size: 0.72rem; color: var(--gray); letter-spacing: 0.05em; min-height: 1em; }
.game-unlock-info.unlocked { color: var(--red-light); font-weight: 600; animation: pulse 1.2s infinite; }
.game-unlock-info:empty { display: none; }
.game-over-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }

.game-over-watermark {
  position: absolute; inset: 0; margin: auto;
  width: 200px; height: 200px;
  background-image: url("Assets/Logos/Skull Transparent.png");
  background-size: contain; background-repeat: no-repeat; background-position: center;
  filter: grayscale(100%);
  opacity: 0.08;
  pointer-events: none;
}
.game-over > * { position: relative; z-index: 1; }

.finale-title {
  color: var(--red-light);
  text-shadow: 0 0 24px var(--red-glow), 2px 2px 0 rgba(0,0,0,0.8);
}
.name-entry { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; justify-content: center; }
.name-entry label { font-family: var(--font-sub); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gray); }
#name-input {
  width: 4.6em; text-align: center;
  background: rgba(245,245,245,0.05);
  border: 1px solid var(--red);
  color: var(--white);
  font-family: var(--font-head); font-size: 1.3rem; letter-spacing: 0.35em;
  padding: 0.3rem 0 0.3rem 0.35em;
  text-transform: uppercase;
  outline: none;
}
#name-input:focus { box-shadow: 0 0 12px var(--red-glow); }
.name-entry .btn { padding: 0.6rem 1.3rem; font-size: 0.8rem; }
.submit-status { font-size: 0.72rem; color: var(--red-light); letter-spacing: 0.05em; min-height: 1em; }
.submit-status:empty { display: none; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .play { padding: 2.5rem 0; }
  .game-hud { padding: 0.7rem 2.6rem 0.7rem 0.9rem; }
  .hud-stat { min-width: 54px; }
  .hud-value { font-size: 1.3rem; }
  /* flex-start: with justify-content center, overflowing panel content would clip unreachably at the top */
  .game-panel { gap: 0.55rem; padding: 0.8rem; justify-content: flex-start; overflow-y: auto; }
  .fs-btn { top: 0.5rem; right: 0.5rem; }
}
@media (max-width: 480px) {
  .life-pip { width: 10px; height: 10px; }
  .game-panel { gap: 0.45rem; padding: 0.55rem; }
  .game-panel-title { font-size: 1.2rem; }
  .game-logo { font-size: 1.55rem; }
  .char-row { gap: 0.3rem; }
  .char-slot { padding: 0.3rem 0.25rem 0.25rem; width: 52px; }
  .char-thumb { width: 40px; height: 40px; }
  .char-name { font-size: 0.5rem; }
  .level-grid { gap: 0.3rem; }
  .level-tile { padding: 0.35rem 0.2rem 0.3rem; }
  .btn-lg { padding: 0.65rem 1.4rem; min-height: 42px; font-size: 0.82rem; }
  .game-panel-text { font-size: 0.7rem; }
  .game-over-watermark { width: 150px; height: 150px; }
  .scores-list { font-size: 0.72rem; }
}

/* Fullscreen: panels may center again (plenty of room) */
.game-wrap.fs .game-panel { justify-content: center; }

/* ---- REDUCED MOTION ---- */
@media (prefers-reduced-motion: reduce) {
  .game-toast.show { animation-duration: 0.01s; }
  .game-newhigh, .game-unlock-info.unlocked { animation: none; }
  .game-panel { animation: none; }
  .game-stage.stage-shake { animation: none; }
  .hud-value.bump, #game-combo-value.bump { animation: none; }
  .life-pip.pip-hit { animation: none; }
}
