/* PLUMBRUN - Polished mobile game UI */

:root {
  --bg: #071018;
  --bg-panel: rgba(10, 10, 12, 0.94);
  /* JBUS brand (jbuswv.com logo: red / black / white) */
  --jbus-red: #e30613;
  --jbus-red-deep: #8f0a14;
  --jbus-red-light: #ff4048;
  --jbus-black: #111111;
  --jbus-white: #f8f8f8;
  --accent: #e30613;
  --accent-deep: #8f0a14;
  --accent-glow: rgba(227, 6, 19, 0.45);
  --pipe: #2f9a56;
  --hat: #ffd84a;
  --text: #f0f6fc;
  --text-dim: rgba(240, 246, 252, 0.72);
  --danger: #ff6b6b;
  --panel-border: rgba(227, 6, 19, 0.35);
}

html, body, .game-root {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(40, 100, 160, 0.22) 0%, transparent 48%),
    radial-gradient(ellipse at 50% 30%, #0e2238 0%, var(--bg) 72%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.game-root {
  width: 100%;
  height: 100%;
  height: 100dvh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Game container - landscape pipe navigator */
#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  max-height: 100dvh;
  aspect-ratio: 16 / 9;
  background: #000;
  box-shadow:
    0 0 0 1px rgba(80, 160, 220, 0.28),
    0 0 50px rgba(40, 140, 200, 0.18),
    0 18px 56px rgba(0, 0, 0, 0.7);
  border-radius: 12px;
  overflow: hidden;
  margin: auto;
}

@media (orientation: landscape) {
  #game-container {
    width: min(100%, 94vw);
    height: min(100%, 90vh);
    height: min(100%, 90dvh);
  }
}

@media (orientation: portrait) {
  #game-container {
    /* Fill more of the phone screen so menus have room */
    width: min(100%, 100vw);
    height: min(100%, 70dvh);
    max-height: 70dvh;
    aspect-ratio: 16 / 9;
  }
}

/* Phones / short viewports: use almost the full screen for the game shell */
@media (max-width: 900px) {
  #game-container {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100dvh;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
  }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
  cursor: pointer;
  position: relative;
  z-index: 2;
}

#game-webgl {
  image-rendering: auto;
  z-index: 1;
  pointer-events: none;
}

/* Overlays — must scroll on short mobile screens (parent clips overflow) */
.overlay-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  text-align: center;
  padding: 12px 10px;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    radial-gradient(ellipse at 50% 36%, rgba(30, 100, 160, 0.28) 0%, transparent 52%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.28) 0%, rgba(5, 14, 24, 0.82) 100%);
  pointer-events: auto;
  backdrop-filter: blur(3px);
  z-index: 30;
  animation: fadeIn 0.35s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-center .panel {
  background:
    linear-gradient(165deg, rgba(18, 36, 56, 0.55) 0%, transparent 42%),
    var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 26px 28px 22px;
  width: min(94%, 400px);
  max-width: 100%;
  max-height: none;
  flex-shrink: 0;
  margin: auto 0; /* keep vertical room when scrolling short screens */
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 14px 44px rgba(0, 0, 0, 0.58),
    0 0 56px rgba(40, 160, 220, 0.14);
  position: relative;
  overflow: visible;
  box-sizing: border-box;
}

/* Title menu: wider so "PIPE RUNNER" + letter-spacing / glow aren't clipped */
.overlay-center .panel.panel-title {
  width: min(96%, 560px);
  padding: 28px 36px 24px;
  overflow: visible;
  box-sizing: border-box;
}

.overlay-center .panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: -20%;
  right: -20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(160, 230, 255, 0.55), transparent);
}

.hidden {
  display: none !important;
}

/* Title / Start screen */
.jbus-presents {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
}

.jbus-logo {
  display: block;
  height: 36px;
  width: auto;
  max-width: min(200px, 70vw);
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.55));
}

.jbus-presents-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.35em;
  color: rgba(255, 255, 255, 0.78);
  text-transform: uppercase;
}

.title-badge,
.over-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 3px;
  color: #ffd0d0;
  border: 1px solid rgba(227, 6, 19, 0.55);
  background: rgba(80, 10, 14, 0.55);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 10px;
}

#start-screen h1 {
  font-size: clamp(32px, 8vw, 52px);
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  padding: 4px 8px 10px; /* room for drop-shadow / descenders */
  line-height: 1.05;
  overflow: visible;
  white-space: nowrap;
  background: linear-gradient(180deg, #ffffff 8%, #ff8a90 48%, #e30613 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter:
    drop-shadow(0 3px 0 rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 22px var(--accent-glow));
}

#start-screen .subtitle {
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 18px;
  letter-spacing: 2.5px;
  font-weight: 700;
  color: var(--hat);
  text-transform: uppercase;
}

#start-screen .tap-hint {
  font-size: 15px;
  padding: 12px 34px;
  background: linear-gradient(180deg, #ff4a52 0%, var(--jbus-red) 45%, #a00812 100%);
  color: #fff;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 1px;
  display: inline-block;
  box-shadow:
    0 5px 0 var(--jbus-red-deep),
    0 8px 24px rgba(227, 6, 19, 0.4);
  animation: pulse 1.6s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 20px;
  text-align: left;
}

.ctrl-chip {
  background: rgba(6, 14, 24, 0.72);
  border: 1px solid rgba(120, 190, 240, 0.18);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ctrl-chip span {
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
}

kbd {
  display: inline-block;
  font-family: inherit;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(160, 210, 255, 0.35);
  background: rgba(40, 70, 100, 0.55);
  color: #d8f4ff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.how-to {
  margin-top: 16px;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}

.how-to p {
  margin: 0 0 8px;
}

.how-to strong {
  color: var(--text);
}

.biome-trail {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 6px !important;
  flex-wrap: wrap;
}

.bt {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid;
}

.bt.rusty {
  color: #e07030;
  border-color: rgba(224, 112, 48, 0.45);
  background: rgba(80, 30, 10, 0.35);
}

.bt.chrome {
  color: #80e0ff;
  border-color: rgba(128, 224, 255, 0.45);
  background: rgba(20, 50, 80, 0.4);
}

.bt.sewer {
  color: #70d060;
  border-color: rgba(112, 208, 96, 0.45);
  background: rgba(20, 50, 20, 0.4);
}

.bt-arrow {
  opacity: 0.45;
  font-size: 12px;
}

.hint-keys {
  text-align: center !important;
  opacity: 0.7;
  font-size: 11px !important;
  margin-top: 4px !important;
}

/* In-game HUD */
#hud {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 20;
  pointer-events: none;
}

#score {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, rgba(12, 24, 40, 0.78), rgba(6, 14, 24, 0.9));
  padding: 6px 24px;
  border-radius: 999px;
  letter-spacing: 2.5px;
  border: 1px solid rgba(120, 200, 255, 0.3);
  min-width: 104px;
  text-align: center;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.42),
    0 0 22px rgba(60, 180, 255, 0.14);
  text-shadow: 0 0 12px rgba(100, 220, 255, 0.4);
}

#biome-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(8, 14, 22, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, transform 0.25s ease;
}

#biome-label.biome-flash {
  animation: biomePop 0.55s ease-out;
}

@keyframes biomePop {
  0% { transform: scale(0.85); filter: brightness(1.6); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); filter: brightness(1); }
}

#biome-label[data-biome="rusty"] {
  color: #e07030;
  border-color: rgba(224, 112, 48, 0.5);
  box-shadow: 0 0 16px rgba(224, 112, 48, 0.22);
}

#biome-label[data-biome="chrome"] {
  color: #80e0ff;
  border-color: rgba(128, 224, 255, 0.5);
  box-shadow: 0 0 16px rgba(128, 224, 255, 0.25);
}

#biome-label[data-biome="sewer"] {
  color: #70d060;
  border-color: rgba(112, 208, 96, 0.5);
  box-shadow: 0 0 16px rgba(112, 208, 96, 0.22);
}

#power-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 0;
}

.power-pill {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid;
  animation: pillIn 0.25s ease-out;
}

.power-pill[hidden] {
  display: none !important;
}

@keyframes pillIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

#power-wrench {
  color: #7dffb0;
  border-color: rgba(80, 230, 140, 0.45);
  background: rgba(10, 40, 24, 0.75);
  box-shadow: 0 0 12px rgba(80, 230, 140, 0.2);
}

#power-shoe {
  color: #ffb060;
  border-color: rgba(255, 150, 60, 0.45);
  background: rgba(50, 24, 8, 0.75);
  box-shadow: 0 0 12px rgba(255, 140, 40, 0.2);
}

#power-boost {
  color: #c8f0ff;
  border-color: rgba(120, 220, 255, 0.45);
  background: rgba(12, 36, 56, 0.75);
  box-shadow: 0 0 12px rgba(100, 200, 255, 0.22);
}

#power-star {
  color: #9ad4ff;
  border-color: rgba(80, 170, 255, 0.6);
  background: rgba(12, 40, 72, 0.85);
  box-shadow: 0 0 16px rgba(60, 160, 255, 0.4);
  animation: pillIn 0.25s ease-out, shieldPulse 0.65s ease-in-out infinite;
}

@keyframes shieldPulse {
  0%, 100% { filter: brightness(1); box-shadow: 0 0 12px rgba(60, 160, 255, 0.35); }
  50% { filter: brightness(1.3); box-shadow: 0 0 20px rgba(100, 200, 255, 0.55); }
}

/* Game Over panel */
#gameover-screen {
  background:
    radial-gradient(ellipse at 50% 28%, rgba(140, 40, 40, 0.32) 0%, transparent 52%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, rgba(8, 14, 24, 0.93) 100%);
}

#gameover-screen .panel-over {
  border-color: rgba(255, 120, 120, 0.28);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 44px rgba(255, 80, 80, 0.12);
}

#gameover-screen .over-badge {
  color: #ff9a9a;
  border-color: rgba(255, 120, 120, 0.4);
  background: rgba(60, 16, 16, 0.45);
}

#gameover-screen h2 {
  margin: 0 0 8px;
  font-size: 28px;
  color: var(--danger);
  letter-spacing: 3px;
  text-shadow: 0 0 18px rgba(255, 80, 80, 0.4);
}

#final-score {
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  margin: 6px 0 4px;
  background: linear-gradient(180deg, #fff 0%, #9ee8ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
  filter: drop-shadow(0 2px 8px rgba(100, 200, 255, 0.25));
}

.death-reason {
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ff9a8a;
  opacity: 0.9;
  margin-bottom: 6px;
}

#high-score {
  opacity: 0.85;
  margin-bottom: 14px;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--hat);
}

.over-hints {
  margin: 0 0 14px;
  font-size: 12px;
  opacity: 0.72;
  line-height: 1.4;
}

#gameover-screen .btn {
  display: block;
  width: 100%;
  padding: 13px;
  margin-top: 8px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}

#gameover-screen .btn-primary {
  background: linear-gradient(180deg, #ff4a52 0%, var(--jbus-red) 50%, #a00812 100%);
  color: #fff;
  box-shadow: 0 4px 0 var(--jbus-red-deep), 0 6px 18px rgba(227, 6, 19, 0.35);
}

#gameover-screen .btn-primary:hover {
  filter: brightness(1.05);
}

#gameover-screen .btn-primary:active {
  transform: scale(0.97) translateY(1px);
  box-shadow: 0 2px 0 var(--accent-deep);
}

#gameover-screen .btn-secondary {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
}

#gameover-screen .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.06);
}

#gameover-screen .btn-secondary:active {
  transform: scale(0.97);
}

/* ===== Mobile / short screens: compact menus so start + game over fit ===== */
@media (max-width: 900px), (max-height: 520px) {
  .overlay-center {
    justify-content: flex-start;
    padding: max(8px, env(safe-area-inset-top, 0px)) 8px max(10px, env(safe-area-inset-bottom, 0px));
  }

  .overlay-center .panel {
    width: min(96%, 420px);
    padding: 14px 14px 12px;
    border-radius: 14px;
  }

  .overlay-center .panel.panel-title {
    width: min(98%, 440px);
    padding: 12px 12px 10px;
  }

  .jbus-presents {
    gap: 3px;
    margin: 0 0 6px;
  }

  .jbus-logo {
    height: 26px;
    max-width: min(140px, 50vw);
  }

  .jbus-presents-label {
    font-size: 9px;
    letter-spacing: 0.28em;
  }

  .title-badge,
  .over-badge {
    font-size: 9px;
    letter-spacing: 2px;
    padding: 3px 10px;
    margin-bottom: 6px;
  }

  #start-screen h1 {
    font-size: clamp(26px, 8vw, 40px);
    letter-spacing: 0.08em;
    margin: 0 0 2px;
    padding: 2px 4px 6px;
  }

  #start-screen .subtitle {
    font-size: 10px;
    letter-spacing: 1.2px;
    margin-bottom: 8px;
  }

  #start-screen .tap-hint {
    font-size: 13px;
    padding: 9px 20px;
    box-shadow: 0 3px 0 var(--jbus-red-deep), 0 6px 16px rgba(227, 6, 19, 0.35);
  }

  .control-grid {
    gap: 6px;
    margin-top: 10px;
  }

  .ctrl-chip {
    padding: 6px 8px;
    font-size: 10px;
    border-radius: 10px;
  }

  .ctrl-chip span {
    font-size: 11px;
  }

  .how-to {
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.35;
  }

  .how-to p {
    margin: 0 0 5px;
  }

  .biome-trail {
    margin: 6px 0 4px !important;
    gap: 4px;
  }

  .bt {
    font-size: 9px;
    padding: 2px 7px;
  }

  .hint-keys {
    font-size: 10px !important;
    margin-top: 2px !important;
  }

  /* Game over */
  #gameover-screen h2 {
    font-size: 22px;
    margin: 0 0 4px;
  }

  #final-score {
    font-size: clamp(32px, 12vw, 48px);
    margin: 2px 0;
  }

  .death-reason {
    min-height: 14px;
    font-size: 11px;
    margin-bottom: 4px;
  }

  #high-score {
    margin-bottom: 8px;
    font-size: 13px;
  }

  .over-hints {
    margin: 0 0 8px;
    font-size: 11px;
  }

  #gameover-screen .btn {
    padding: 11px;
    margin-top: 6px;
    font-size: 14px;
  }
}

/* Very short landscape (phones held sideways): hide verbose help on title */
@media (max-height: 420px) {
  .how-to p:not(.biome-trail):not(.hint-keys) {
    display: none;
  }

  .control-grid {
    grid-template-columns: 1fr 1fr;
    margin-top: 6px;
  }

  #start-screen .tap-hint {
    padding: 8px 16px;
    font-size: 12px;
  }

  #final-score {
    font-size: 28px;
  }
}

/* Status bar safe area */
.status-bar-safe-area {
  display: none;
}

@supports (-webkit-touch-callout: none) {
  .status-bar-safe-area {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top);
    background: transparent;
    z-index: 50;
    pointer-events: none;
  }
}

/* Blazor error UI */
#blazor-error-ui {
  color-scheme: light only;
  background: #b32121;
  color: white;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}
