:root {
  --bg-top: #8f1a20;
  --bg-bottom: #142d59;
  --panel: rgba(15, 18, 29, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text-main: #f9f2e8;
  --text-soft: rgba(249, 242, 232, 0.75);
  --accent: #f2d86f;
  --accent-strong: #f7e7a4;
  --danger: #ff957c;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.1), transparent 32%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text-main);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
}

.game-shell {
  position: relative;
  width: min(100vw - 20px, calc((100vh - 20px) * 16 / 9));
  height: min(100vh - 20px, calc((100vw - 20px) * 9 / 16));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #0c1d3f;
}

#gpu-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #77c4ff 0%, #bfdff9 54%, #edf0d7 100%);
  touch-action: none;
}

.player-sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 180px;
  height: 180px;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  z-index: 1;
  opacity: 0;
  transform-origin: center center;
  will-change: transform;
  filter: drop-shadow(0 18px 18px rgba(9, 18, 34, 0.28));
}

.player-source {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.hud {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 18px 0;
  pointer-events: none;
  z-index: 2;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 12px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(11, 24, 44, 0.82), rgba(14, 29, 47, 0.62));
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
}

.brand-mark {
  font-size: clamp(1rem, 1.7vw, 1.35rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.brand small {
  color: var(--text-soft);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.scoreboard {
  display: flex;
  gap: 10px;
}

.stat-card {
  min-width: 92px;
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(11, 24, 44, 0.82), rgba(14, 29, 47, 0.62));
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
}

.stat-label {
  color: var(--text-soft);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: clamp(1.05rem, 2vw, 1.45rem);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 3;
  background: linear-gradient(180deg, rgba(6, 11, 22, 0.14), rgba(6, 11, 22, 0.5));
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(560px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border-radius: 26px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-strong);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

.panel h1,
.panel h2 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 5vw, 3.25rem);
  line-height: 0.95;
}

.lead,
.controls,
.status-line,
#errorText {
  margin: 0 auto;
  max-width: 44ch;
  color: var(--text-soft);
  line-height: 1.55;
}

.controls {
  margin-top: 16px;
}

.status-line {
  margin-top: 14px;
  font-size: 0.92rem;
}

button {
  margin-top: 22px;
  border: 0;
  border-radius: 999px;
  padding: 14px 24px;
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  color: #17233a;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  box-shadow: 0 10px 24px rgba(242, 216, 111, 0.28);
}

kbd {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-main);
  font: inherit;
  font-weight: 700;
}

.error-overlay .panel {
  border-color: rgba(255, 149, 124, 0.35);
}

.orientation-block {
  display: none;
}

@media (max-width: 900px) {
  .game-shell {
    border-radius: 20px;
  }

  .hud {
    padding: 12px 12px 0;
  }

  .brand,
  .stat-card {
    border-radius: 16px;
  }

  .scoreboard {
    gap: 6px;
  }

  .stat-card {
    min-width: 72px;
    padding: 10px 11px;
  }
}

@media (orientation: portrait) and (max-width: 1024px) {
  .game-shell {
    opacity: 0.1;
    filter: blur(8px);
    pointer-events: none;
  }

  .orientation-block {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 5;
  }

  .orientation-card {
    width: min(360px, 100%);
    padding: 24px;
    border-radius: 24px;
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
  }

  .orientation-card h2 {
    margin: 0 0 8px;
  }

  .orientation-card p {
    margin: 0;
    color: var(--text-soft);
  }
}
