:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.88);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --brand-1: #38bdf8;
  --brand-2: #818cf8;
  --brand-3: #c084fc;
  --brand-bg: #0a0f1a;
  --success: #4ade80;
  --danger: #fb7185;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  touch-action: manipulation;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: var(--app-h, 100%);
  height: var(--app-h, 100dvh);
  min-height: -webkit-fill-available;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  pointer-events: none;
}

#game.is-playing {
  cursor: pointer;
  pointer-events: auto;
}

#hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  padding: 0 20px;
  pointer-events: none;
  z-index: 2;
}

.hud-menu-btn {
  position: absolute;
  top: 0;
  right: 20px;
  pointer-events: auto;
  padding: 6px 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.72);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.hud-menu-btn:hover {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.35);
}

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 1.25rem;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

#best {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.combo {
  margin-top: 8px;
  text-align: center;
  color: var(--success);
  font-weight: 800;
  letter-spacing: 0.08em;
  animation: pop 0.35s ease;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at top, rgba(56, 189, 248, 0.12), transparent 55%),
              rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  z-index: 3;
  overflow: hidden;
}

.panel {
  width: min(100%, 360px);
  max-height: min(calc(var(--app-h, 100dvh) - 32px), 720px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 28px 24px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.panel-menu {
  width: min(100%, 400px);
  padding: 22px 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
}

.panel-rankings {
  width: min(100%, 400px);
  max-height: 85dvh;
  text-align: left;
}

.menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.menu-header .studio-mark {
  margin: 0;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.logo-inline {
  font-size: 1.75rem;
  line-height: 1.1;
}

.menu-header .studio-name {
  margin: 0 0 2px;
}

.panel-menu .tagline {
  margin: 0 0 16px;
  font-size: 0.9rem;
  text-align: left;
}

.tagline-tight {
  margin-bottom: 12px !important;
  text-align: center !important;
}

.player-card,
.leaderboard-card {
  padding: 14px;
  margin-bottom: 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.14);
  min-width: 0;
  overflow: hidden;
}

.player-card,
.leaderboard-card,
.input-text {
  user-select: text;
  -webkit-user-select: text;
}

.input-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.player-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
}

.player-actions .btn,
.player-actions .btn.btn-compact {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin-top: 0;
  padding: 12px 8px;
  font-size: 0.84rem;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow: hidden;
}

.player-actions .btn.primary {
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.22);
}

.player-actions .btn:only-child {
  grid-column: 1 / -1;
}

@media (max-width: 420px) {
  .player-actions {
    grid-template-columns: 1fr;
  }
}

.input-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.player-input-row {
  display: flex;
  gap: 8px;
}

.input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  user-select: text;
  touch-action: manipulation;
}

.input:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.error {
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 0.78rem;
  line-height: 1.4;
}

.player-greeting {
  margin: 10px 0 0;
  color: var(--success);
  font-size: 0.85rem;
  font-weight: 600;
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.leaderboard-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand-1);
}

.btn-text {
  padding: 4px 8px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-text:hover {
  color: var(--brand-1);
}

.leaderboard-list {
  display: grid;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}

.leaderboard-list-full {
  max-height: 50dvh;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.88rem;
}

.leaderboard-row:nth-child(odd) {
  background: rgba(148, 163, 184, 0.06);
}

.leaderboard-row.is-you {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.lb-rank {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.8rem;
}

.leaderboard-row:nth-child(1) .lb-rank { color: #fbbf24; }
.leaderboard-row:nth-child(2) .lb-rank { color: #cbd5e1; }
.leaderboard-row:nth-child(3) .lb-rank { color: #d97706; }

.lb-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 800;
  color: var(--brand-1);
}

.leaderboard-empty,
.leaderboard-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center;
}

.leaderboard-status {
  margin-top: 8px;
}

.menu-best {
  margin: 0 0 12px;
  text-align: center;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.menu-secondary {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.menu-secondary .btn {
  flex: 1;
  margin-top: 0;
}

.btn-compact {
  margin-top: 0;
}

.player-card .btn-compact {
  width: 100%;
  white-space: normal;
}

.btn-sm {
  padding: 11px 14px;
  font-size: 0.88rem;
}

.panel-menu .btn.primary,
.panel-menu .btn.support {
  margin-top: 8px;
}

.hud-player {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brand-1);
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-row-sub {
  margin-top: 2px;
  font-size: 0.95rem;
}

.gameover-rank {
  margin: -8px 0 16px;
  color: var(--brand-1);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.45;
}

.panel-rankings .logo.small {
  text-align: center;
}

.panel-rankings .btn.primary {
  margin-top: 14px;
}

.logo {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo.small {
  font-size: 2rem;
}

.tagline {
  margin: 12px 0 8px;
  color: var(--muted);
  line-height: 1.5;
}

.menu-best, .final-score {
  margin: 8px 0 20px;
  font-size: 1.1rem;
}

.tagline-free {
  margin-top: -4px;
  margin-bottom: 12px;
  font-size: 0.88rem;
  color: var(--success);
  font-weight: 600;
}

.menu-support {
  margin: -8px 0 16px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  font-weight: 500;
}

.studio-mark {
  display: block;
  margin: 0 auto 10px;
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 8px 24px rgba(56, 189, 248, 0.22));
}

.studio-name {
  margin: 0 0 6px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--brand-1), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.splash {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 38%, rgba(56, 189, 248, 0.14), transparent 48%),
    radial-gradient(circle at 50% 62%, rgba(129, 140, 248, 0.1), transparent 42%),
    var(--brand-bg);
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

.splash.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: splash-in 1.1s ease both;
}

.splash-mark {
  width: 72px;
  height: 72px;
  filter: drop-shadow(0 12px 32px rgba(56, 189, 248, 0.28));
}

.splash-logo {
  width: min(78vw, 300px);
  height: auto;
}

.splash-present {
  margin: 20px 0 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--brand-1), var(--brand-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: splash-in 1.1s ease 0.25s both;
}

.splash-sub {
  margin: 18px 0 0;
  max-width: 280px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: center;
  animation: splash-in 1.1s ease 0.45s both;
}

.panel-about .about-logo {
  width: min(70vw, 220px);
  height: auto;
  margin: 0 auto 12px;
  display: block;
}

.about-game {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
}

.about-tagline {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.about-support {
  margin: 0 0 12px;
  color: #cbd5e1;
  font-size: 0.88rem;
  line-height: 1.5;
}

.about-privacy {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.about-credit {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  font-style: italic;
}

@keyframes splash-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn.support {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #0a0f1a;
  box-shadow: 0 10px 30px rgba(56, 189, 248, 0.22);
}

.support-link {
  display: block;
  margin-top: 14px;
  padding: 8px 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center;
  text-decoration: none;
  font-weight: 500;
}

.support-link:hover {
  color: var(--brand-1);
}

.final-score span {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--accent);
}

.new-record {
  margin: -12px 0 16px;
  color: var(--success);
  font-weight: 800;
}

.btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 14px 18px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  box-shadow: 0 10px 30px rgba(56, 189, 248, 0.25);
}

.btn.ghost {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.actions {
  display: grid;
  gap: 4px;
}

body.itch-embed,
html.itch-embed {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.itch-embed #app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: var(--app-h, 100%);
  max-height: var(--app-h, 100%);
  overflow: hidden;
}

body.itch-embed .menu-web-only {
  display: none !important;
}

body.itch-embed .itch-quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
}

body.itch-embed .itch-quick-actions #about-btn {
  grid-column: 1 / -1;
}

body.itch-embed .itch-only-back {
  display: block;
  margin: 0 0 12px;
  padding: 0;
  text-align: left;
}

body:not(.itch-embed) .itch-only-back,
body:not(.itch-embed) .itch-quick-actions {
  display: none;
}

body.itch-embed .overlay {
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(56, 189, 248, 0.16), transparent 52%),
    rgba(10, 15, 26, 0.92);
}

body.itch-embed .panel {
  width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

body.itch-embed .panel-menu {
  padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  background: transparent;
}

body.itch-embed .menu-itch-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}

body.itch-embed .panel-menu.show-account .menu-itch-main {
  display: none;
}

body.itch-embed .panel-menu .player-card {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

body.itch-embed .panel-menu.show-account .player-card {
  display: flex;
  flex-direction: column;
}

body.itch-embed .menu-header {
  margin-bottom: 12px;
}

body.itch-embed .menu-header .studio-mark {
  width: 52px;
  height: 52px;
}

body.itch-embed .logo-inline {
  font-size: clamp(1.6rem, 6vw, 2rem);
}

body.itch-embed .panel-menu .tagline {
  margin: 0 0 18px;
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: left;
}

body.itch-embed .btn-play-hero {
  margin-top: 0;
  padding: 16px 20px;
  font-size: 1.15rem;
  border-radius: 16px;
}

body.itch-embed .menu-best {
  margin: 10px 0 0;
  text-align: center;
  font-size: 0.9rem;
}

body.itch-embed .panel-rankings {
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
}

body.itch-embed .panel-about {
  padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  justify-content: center;
}

body.itch-embed .leaderboard-list-full {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}

body.itch-embed #game-over.overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

body.itch-embed .panel-gameover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(100%, 340px);
  height: auto;
  max-height: calc(100% - 16px);
  margin: 0;
  padding: 24px 20px 20px;
  text-align: center;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  overflow-y: auto;
}

body.itch-embed .panel-gameover .gameover-mark {
  margin-bottom: 8px;
  filter: drop-shadow(0 8px 20px rgba(56, 189, 248, 0.25));
}

body.itch-embed .panel-gameover .logo.small {
  font-size: 1.5rem;
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  color: #f8fafc;
  margin-bottom: 4px;
}

body.itch-embed .panel-gameover .final-score {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--muted);
}

body.itch-embed .panel-gameover .final-score span {
  display: block;
  font-size: 2.75rem;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 2px;
}

body.itch-embed .panel-gameover .new-record {
  margin: 0 0 8px;
  font-size: 0.92rem;
}

body.itch-embed .panel-gameover .gameover-rank {
  margin: 0 0 12px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: #cbd5e1;
}

body.itch-embed .panel-gameover .actions {
  width: 100%;
  gap: 0;
}

body.itch-embed .panel-gameover #gameover-rankings-btn,
body.itch-embed .panel-gameover #share-btn,
body.itch-embed .panel-gameover .support-link {
  display: none;
}

body.itch-embed .panel-gameover #menu-btn {
  display: block;
  margin-top: 8px;
}

body.itch-embed .hud-menu-btn {
  top: max(10px, env(safe-area-inset-top));
  right: 14px;
  padding: 7px 13px;
  font-size: 0.82rem;
}

body.itch-embed .panel-gameover .btn {
  margin-top: 0;
  padding: 14px 18px;
  width: 100%;
}

body.itch-embed .gameover-tip {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.07);
  border: 1px solid rgba(56, 189, 248, 0.16);
  color: #cbd5e1;
  font-size: 0.8rem;
  line-height: 1.45;
  font-weight: 500;
}

body.itch-embed .menu-tip {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
  text-align: center;
}

body:not(.itch-embed) .itch-only-tip {
  display: none !important;
}

body.itch-embed .hud-row {
  font-size: 1.1rem;
}

body.itch-embed #hud {
  top: max(10px, env(safe-area-inset-top));
  padding: 0 14px;
}

.hidden {
  display: none !important;
}

@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Phone browsers (Safari, Chrome): compact menu like itch embed */
@media (max-width: 640px) {
  body:not(.itch-embed) .overlay {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body:not(.itch-embed) .panel,
  body:not(.itch-embed) .panel-menu {
    width: 100%;
    max-width: 100%;
    max-height: none;
    margin: 0;
    padding: 18px 16px 20px;
    overflow: visible;
  }

  body:not(.itch-embed) .menu-itch-main {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  body:not(.itch-embed) .btn-play-hero {
    margin-top: 4px;
  }

  body:not(.itch-embed) .itch-quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
  }

  body:not(.itch-embed) .itch-quick-actions #about-btn {
    grid-column: 1 / -1;
  }

  body:not(.itch-embed) .itch-only-back {
    display: block;
    margin: 0 0 12px;
    padding: 0;
    text-align: left;
  }

  body:not(.itch-embed) .panel-menu .player-card,
  body:not(.itch-embed) .panel-menu .leaderboard-card.menu-web-only,
  body:not(.itch-embed) .panel-menu .menu-secondary {
    display: none;
  }

  body:not(.itch-embed) .panel-menu.show-account .menu-itch-main,
  body:not(.itch-embed) .panel-menu.show-account .leaderboard-card,
  body:not(.itch-embed) .panel-menu.show-account .menu-secondary {
    display: none !important;
  }

  body:not(.itch-embed) .panel-menu.show-account .player-card {
    display: block;
  }

  body:not(.itch-embed) .btn,
  body:not(.itch-embed) .input {
    min-height: 44px;
  }

  body:not(.itch-embed) .btn-sm {
    min-height: 44px;
    padding: 12px 14px;
  }
}
