:root {
  --bg: #07070f;
  --panel: rgba(14, 14, 28, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f1ff;
  --muted: #a7a0c4;
  --accent: #ff4d8d;
  --accent-2: #7cf5ff;
  --good: #7dffa5;
  --warn: #ffd36a;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  --radius: 18px;
  --font-ui: "Rubik", system-ui, sans-serif;
  --font-pixel: "Press Start 2P", monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(900px 480px at 10% -10%, rgba(255, 77, 141, 0.16), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(124, 245, 255, 0.1), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body.is-playing {
  touch-action: none;
}

/* ─── App shell: fixed viewport, no page scroll ─── */
#app {
  width: 100%;
  max-width: 1100px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  padding:
    max(8px, var(--safe-t))
    max(10px, var(--safe-r))
    max(8px, var(--safe-b))
    max(10px, var(--safe-l));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  overflow: hidden;
}

.top-bar,
.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  font-size: 1.5rem;
  flex-shrink: 0;
  filter: drop-shadow(0 0 10px rgba(124, 245, 255, 0.5));
}

.brand h1 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: clamp(0.55rem, 1.8vw, 0.85rem);
  letter-spacing: 0.4px;
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 77, 141, 0.55);
  white-space: nowrap;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.stat {
  min-width: 64px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  text-align: right;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat span:last-child {
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

#combo {
  color: var(--accent-2);
}

/* Stage fills remaining space — no aspect forced scroll */
.stage-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255, 77, 141, 0.35);
  box-shadow:
    0 0 0 1px rgba(124, 245, 255, 0.12),
    0 0 40px rgba(255, 77, 141, 0.18),
    0 0 80px rgba(124, 245, 255, 0.08),
    0 12px 40px rgba(0, 0, 0, 0.5);
  background: #0b0b18;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
  background: #0b0b18;
  -webkit-user-select: none;
  user-select: none;
}

/* ─── Screens (no scroll) ─── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 10px;
  background: linear-gradient(180deg, rgba(5, 5, 12, 0.55), rgba(5, 5, 12, 0.88));
  backdrop-filter: blur(6px);
  overflow: hidden;
}

.overlay.hidden {
  display: none !important;
}

.screen-panel {
  width: 100%;
  max-width: 480px;
  margin: auto;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.screen-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 14px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.screen-footer {
  flex: 0 0 auto;
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
}

.screen-pause {
  max-width: 300px;
  height: auto;
  max-height: 100%;
  padding: 22px 18px;
  text-align: center;
  justify-content: center;
  gap: 14px;
}

.screen-pause h2 {
  margin: 0;
}

.screen-pause .btn {
  width: 100%;
}

/* Start layout */
.start-hero {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.start-copy {
  min-width: 0;
}

.badge {
  display: inline-block;
  margin: 0 0 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(124, 245, 255, 0.12);
  color: var(--accent-2);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.badge.over {
  background: rgba(255, 77, 141, 0.14);
  color: var(--accent);
}

.screen-panel h2 {
  margin: 0 0 4px;
  font-size: clamp(1.15rem, 3.5vw, 1.5rem);
  line-height: 1.15;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.avatar-preview {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(124, 245, 255, 0.45);
  background: linear-gradient(160deg, #1c1c35, #10101f);
  box-shadow: 0 0 18px rgba(124, 245, 255, 0.18);
}

#avatar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.nick-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
}

input[type="text"] {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  font-size: 16px; /* no iOS zoom */
  outline: none;
  width: 100%;
}

input[type="text"]:focus {
  border-color: rgba(124, 245, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(124, 245, 255, 0.12);
}

.controls-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.hint-mobile {
  display: none;
}

.hint-desktop {
  display: inline;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: #fff;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  width: 100%;
  background: linear-gradient(135deg, #ff4d8d, #ff7a4d);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255, 77, 141, 0.35);
}

.btn-start {
  font-size: 1.05rem !important;
  padding: 14px 16px !important;
  animation: ctaPulse 1.6s ease-in-out infinite;
}

@keyframes ctaPulse {
  0%,
  100% {
    box-shadow: 0 8px 24px rgba(255, 77, 141, 0.35);
  }
  50% {
    box-shadow: 0 10px 32px rgba(255, 77, 141, 0.6);
  }
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.tiny {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.row {
  display: flex;
  gap: 8px;
}

.row .btn {
  flex: 1;
}

/* Leaderboard: fixed 5 rows, no scroll */
.board-block {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  min-height: 0;
  overflow: hidden;
}

.board-block h3 {
  margin: 0;
  font-size: 0.82rem;
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  font-size: 0.8rem;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 6px;
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  align-items: center;
  min-height: 0;
}

.leaderboard li.me {
  border: 1px solid rgba(124, 245, 255, 0.45);
  background: rgba(124, 245, 255, 0.08);
}

.leaderboard li.muted {
  display: block;
  color: var(--muted);
  background: transparent;
  padding: 4px 2px;
}

.leaderboard .rank {
  color: var(--warn);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.leaderboard .pts {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
}

.leaderboard .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Game over compact */
.over-phrase {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 77, 141, 0.1);
  border: 1px solid rgba(255, 77, 141, 0.25);
  color: #ffd0e0;
  font-size: 0.78rem;
  line-height: 1.3;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.submit-status {
  margin: 0;
  min-height: 1em;
  font-size: 0.72rem;
  color: #7d769a;
}

.tiny {
  margin: 0;
  font-size: 0.72rem;
  color: #7d769a;
}

.loot-summary {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  overflow: hidden;
}

.loot-summary li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-size: 0.75rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.compact-board {
  margin: 0;
}

.footer-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Touch controls */
.touch-controls {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  padding: 10px 14px calc(10px + var(--safe-b));
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.35));
  opacity: 0;
}

.touch-controls.active {
  opacity: 1;
}

.touch-btn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(20, 16, 36, 0.75);
  color: #fff;
  font-size: 1.45rem;
  font-weight: 800;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.touch-btn:active,
.touch-btn.is-pressed {
  transform: scale(0.94);
  background: rgba(255, 77, 141, 0.45);
}

.touch-jump {
  width: 78px;
  height: 78px;
  border-color: rgba(124, 245, 255, 0.45);
}

.float-layer {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
}

.float-text {
  position: absolute;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--good);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  animation: floatUp 0.85s ease-out forwards;
  white-space: nowrap;
}

.float-text.rare {
  color: var(--warn);
}

.float-text.girl {
  color: #ff9ec8;
}

.float-text.bad {
  color: var(--accent);
}

.float-text.phrase {
  color: #ffe0f0;
  font-size: 0.78rem;
  font-weight: 600;
  max-width: 200px;
  white-space: normal;
  text-align: center;
  line-height: 1.25;
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.9);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-46px) scale(1.05);
  }
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls.active {
    display: flex;
  }

  .hint-mobile {
    display: inline;
  }

  .hint-desktop {
    display: none;
  }
}

/* Narrow phones */
@media (max-width: 700px) {
  #app {
    gap: 6px;
    padding:
      max(6px, var(--safe-t))
      max(8px, var(--safe-r))
      max(6px, var(--safe-b))
      max(8px, var(--safe-l));
  }

  .brand-mark {
    font-size: 1.25rem;
  }

  .subtitle {
    display: none;
  }

  .stat {
    min-width: 56px;
    padding: 5px 8px;
  }

  .stat span:last-child {
    font-size: 0.92rem;
  }

  .overlay {
    padding: 6px;
  }

  .avatar-preview {
    width: 60px;
    height: 60px;
  }

  .screen-main {
    padding: 12px 12px 6px;
    gap: 8px;
  }

  .loot-summary {
    grid-template-columns: 1fr 1fr;
  }

  body.is-playing .footer-hint {
    display: none;
  }

  body.is-playing .bottom-bar {
    justify-content: flex-end;
  }
}

/* Short height (landscape phone / small laptop) */
@media (max-height: 560px) {
  .lead {
    display: none;
  }

  .badge {
    display: none;
  }

  .avatar-preview {
    width: 48px;
    height: 48px;
  }

  .screen-main {
    padding: 8px 10px 4px;
    gap: 6px;
    justify-content: space-between;
  }

  .over-phrase {
    -webkit-line-clamp: 1;
    padding: 5px 8px;
  }

  .loot-summary {
    display: none;
  }

  .board-block {
    padding: 5px 8px;
  }

  .leaderboard li {
    padding: 3px 6px;
    font-size: 0.74rem;
  }

  .btn-start {
    padding: 10px !important;
    font-size: 0.95rem !important;
  }

  .controls-hint {
    display: none;
  }

  .screen-footer {
    padding: 6px 10px 8px;
  }
}

@media (max-height: 420px) {
  .top-bar .brand div p,
  .subtitle {
    display: none;
  }

  .stat-label {
    display: none;
  }

  .compact-board {
    display: none;
  }
}
