:root {
  color-scheme: dark;
  --panel: rgba(18, 24, 32, 0.72);
  --panel-strong: rgba(18, 24, 32, 0.9);
  --text: #f5f7f2;
  --muted: #aeb8b5;
  --accent: #f5c84b;
  --accent-2: #5dd0c5;
  --danger: #f06d5e;
  --shadow: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: #121820;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
}

button {
  color: inherit;
  font: inherit;
}

.game-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  background: #121820;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.stat-card {
  display: grid;
  gap: 5px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(18, 24, 32, 0.58);
  box-shadow: 0 8px 24px var(--shadow);
  backdrop-filter: blur(12px);
}

.score-card {
  gap: 8px;
}

.stat-title {
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.stat-grid {
  display: flex;
  gap: 6px;
}

.best-row {
  display: grid;
  grid-template-columns: auto repeat(4, minmax(44px, 1fr));
  align-items: center;
  gap: 8px;
  padding: 8px 7px 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.13);
  color: var(--muted);
}

.best-row span {
  display: block;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.best-row > span {
  color: var(--accent-2);
}

.best-row strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 13px;
  line-height: 1;
}

.meter {
  min-width: 66px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--panel);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.meter strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  line-height: 1;
}

.icon-button,
.primary-button,
.control-button {
  border: 0;
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 12px 32px var(--shadow);
  cursor: pointer;
}

.icon-button {
  width: 46px;
  height: 46px;
  margin-left: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--accent);
  font-size: 16px;
  font-weight: 900;
  pointer-events: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  background: linear-gradient(rgba(18, 24, 32, 0.24), rgba(18, 24, 32, 0.52));
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(440px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  text-align: center;
  backdrop-filter: blur(16px);
}

.kicker {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 8svh, 62px);
  line-height: 0.95;
}

.panel p {
  color: var(--muted);
}

.panel.game-over h1 {
  font-size: clamp(36px, 7svh, 58px);
  line-height: 1;
}

.panel.game-over #overlayText {
  margin: 12px 0 18px;
  color: var(--text);
  font-size: clamp(20px, 4svh, 30px);
  font-weight: 900;
  line-height: 1.08;
}

.panel.game-over .score-detail {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.primary-button {
  min-width: 156px;
  min-height: 50px;
  padding: 0 22px;
  background: var(--accent);
  color: #1c1605;
  font-weight: 900;
}

.primary-button.compact {
  min-width: 92px;
  min-height: 44px;
  padding: 0 14px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

.score-form {
  margin: 14px 0 12px;
  text-align: left;
}

.score-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.score-form-row {
  display: flex;
  gap: 8px;
}

.score-form input {
  min-width: 0;
  width: 100%;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.72);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  padding: 0 12px;
}

.leaderboard {
  margin: 12px 0 14px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.48);
  text-align: left;
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.leaderboard ol {
  display: grid;
  gap: 5px;
  max-height: 230px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.leaderboard small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.scoreboard-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.touch-controls {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.control-cluster {
  display: flex;
  flex: 1 1 0;
  gap: 8px;
  pointer-events: none;
}

.control-cluster:last-child {
  justify-content: flex-end;
}

.control-button {
  width: clamp(64px, 10svmin, 96px);
  height: clamp(64px, 10svmin, 96px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font-size: clamp(14px, 2.2svh, 18px);
  font-weight: 900;
  letter-spacing: 0;
  pointer-events: auto;
  user-select: none;
}

.control-button.small {
  width: clamp(58px, 8.5svmin, 82px);
  height: clamp(58px, 8.5svmin, 82px);
  background: rgba(18, 24, 32, 0.86);
}

.control-button.jump {
  background: rgba(245, 200, 75, 0.9);
  color: #1c1605;
}

.control-button:active,
.icon-button:active,
.primary-button:active {
  transform: translateY(1px) scale(0.98);
}

@media (max-width: 640px) {
  .hud {
    gap: 6px;
    align-items: flex-start;
  }

  .stat-card {
    padding: 5px;
    gap: 4px;
  }

  .stat-grid {
    gap: 4px;
  }

  .meter {
    min-width: 37px;
    padding: 5px;
  }

  .meter span {
    font-size: 8px;
  }

  .meter strong {
    font-size: 14px;
  }

  .best-row {
    grid-template-columns: auto repeat(4, minmax(29px, 1fr));
    gap: 5px;
    padding: 7px 5px 5px;
  }

  .best-row span {
    font-size: 8px;
  }

  .best-row strong {
    font-size: 11px;
  }

  .control-cluster {
    gap: 5px;
  }

  .control-button {
    width: min(18vw, 72px);
    height: min(18vw, 72px);
    font-size: clamp(10px, 3vw, 13px);
  }

  .control-button.small {
    width: min(15.5vw, 62px);
    height: min(15.5vw, 62px);
    font-size: clamp(9px, 2.7vw, 12px);
  }

  .panel {
    padding: 18px;
  }
}

@media (max-width: 760px) and (orientation: portrait) {
  .hud {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    right: calc(8px + env(safe-area-inset-right));
  }

  .touch-controls {
    left: calc(10px + env(safe-area-inset-left));
    right: calc(10px + env(safe-area-inset-right));
    bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
}

@media (max-height: 460px) and (orientation: landscape) {
  .hud {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
  }

  .stat-card {
    padding: 5px;
  }

  .meter {
    min-width: 48px;
    padding: 5px 6px;
  }

  .meter span,
  .best-row span {
    font-size: 8px;
  }

  .meter strong {
    font-size: 15px;
  }

  .best-row {
    padding: 5px;
  }

  .best-row strong {
    font-size: 10px;
  }

  .control-button {
    width: min(13.5vh, 62px);
    height: min(13.5vh, 62px);
    font-size: 11px;
  }

  .control-button.small {
    width: min(12vh, 54px);
    height: min(12vh, 54px);
    font-size: 10px;
  }
}
