:root {
  color-scheme: dark;
  --bg: #07030d;
  --panel: #160d26;
  --panel-solid: #0d0716;
  --line: rgba(243, 238, 255, 0.14);
  --line-strong: rgba(243, 238, 255, 0.26);
  --text: #f3eeff;
  --muted: #9b91ad;
  --purple: #874ffe;
  --purple-bright: #b79cff;
  --pink: #ff7e96;
  --deep: #282b4c;
  --error: #ff6b82;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  color: var(--text);
  font-family: Roboto, Arial, ui-sans-serif, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--purple-bright);
  outline-offset: 2px;
}

.game-shell {
  width: min(100%, 760px);
  height: 100dvh;
  min-height: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: 74px minmax(0, 1fr) 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

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

.brand-logo {
  display: block;
  width: auto;
  height: 42px;
}

.brand-name {
  color: #c9bddb;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
}

.stats {
  display: flex;
  gap: 26px;
}

.stat {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 8px;
}

.stat-label,
.footer,
.eyebrow,
.drag-hint,
.speed,
.attempts,
.field > span,
th,
.attempt-message,
.privacy-note,
.save-status {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.stat-label {
  color: #887e99;
}

.stat strong {
  min-width: 2ch;
  color: var(--text);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.game-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  overflow: clip;
  background:
    radial-gradient(circle at 50% 46%, rgba(135, 79, 254, 0.14), transparent 34%),
    linear-gradient(145deg, rgba(255, 126, 150, 0.045), transparent 40%),
    #09050f;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  touch-action: none;
}

.ambient-orb {
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 50%;
  width: min(90vw, 460px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 126, 150, 0.34) 40%,
    rgba(255, 126, 150, 0.14) 80%,
    rgba(255, 126, 150, 0)
  );
  opacity: 0.62;
  filter: blur(16px);
  transform: translate(-50%, -60%) scale(1);
  animation: orb-breathe 6s ease-in-out infinite;
  pointer-events: none;
  will-change: transform, filter;
}

@keyframes orb-breathe {
  0%,
  100% {
    filter: blur(16px);
    transform: translate(-50%, -60%) scale(1);
  }

  50% {
    filter: blur(8px);
    transform: translate(-50%, -50%) scale(1.5);
  }
}

.grid {
  position: absolute;
  inset: 0;
  opacity: 0.17;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, transparent, #000 28%, #000 72%, transparent);
  pointer-events: none;
}

.watermark {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: min(52%, 300px);
  max-height: 28%;
  transform: translate(-50%, -50%);
  opacity: 0.065;
  filter: brightness(0) invert(1);
  pointer-events: none;
}

#gameCanvas {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.speed,
.attempts {
  position: absolute;
  z-index: 3;
  top: 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  pointer-events: none;
}

.speed {
  left: 18px;
}

.attempts {
  right: 18px;
}

.speed strong,
.attempts strong {
  color: #d8cfea;
  font-variant-numeric: tabular-nums;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 12px rgba(255, 126, 150, 0.9);
}

.screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(7, 3, 13, 0.6);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(1.025);
  transition: opacity 220ms ease, transform 220ms ease, visibility 220ms;
}

.screen.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

.screen-content {
  width: min(100%, 460px);
}

.form-screen {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 20px 24px;
  background:
    radial-gradient(circle at 50% 28%, rgba(135, 79, 254, 0.13), transparent 32%),
    rgba(7, 3, 13, 0.88);
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.form-content {
  margin: auto;
  padding: 16px 0;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--purple-bright);
}

h1,
h2 {
  margin: 0;
  color: #fff;
  font-weight: 850;
  line-height: 0.95;
  letter-spacing: -0.055em;
}

h1 {
  font-size: clamp(40px, 9vw, 58px);
}

h2 {
  font-size: clamp(42px, 9vw, 60px);
}

.form-lead {
  width: min(100%, 390px);
  margin: 14px auto 20px;
  color: #a79caf;
  font-size: 13px;
  line-height: 1.5;
}

.form-fields {
  display: grid;
  gap: 11px;
  text-align: left;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: #a096ae;
  letter-spacing: 0.13em;
}

.field b {
  color: var(--pink);
}

.field em {
  float: right;
  color: #71667f;
  font-size: 8px;
  font-style: normal;
}

.field input {
  width: 100%;
  height: 43px;
  padding: 0 13px;
  border: 1px solid rgba(243, 238, 255, 0.16);
  border-radius: 4px;
  color: var(--text);
  background: rgba(243, 238, 255, 0.045);
  font-size: 14px;
  user-select: text;
  -webkit-user-select: text;
  transition: border-color 160ms ease, background 160ms ease;
}

.field input::placeholder {
  color: #655b72;
}

.field input:focus {
  border-color: rgba(135, 79, 254, 0.85);
  background: rgba(135, 79, 254, 0.08);
}

.field input[aria-invalid="true"] {
  border-color: rgba(255, 113, 133, 0.75);
}

.form-error,
.screen-error {
  min-height: 18px;
  margin: 8px 0 2px;
  color: var(--error);
  font-size: 11px;
  line-height: 1.4;
}

.primary-button {
  min-width: 154px;
  padding: 15px 25px;
  border: 1px solid rgba(243, 238, 255, 0.28);
  border-radius: 22px;
  color: #fff;
  background: linear-gradient(100deg, var(--pink), var(--purple));
  box-shadow: 0 12px 38px rgba(135, 79, 254, 0.28);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.primary-button:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
}

.primary-button:disabled {
  color: #665d72;
  border-color: #2c2338;
  background: #1a1223;
  box-shadow: none;
  cursor: wait;
}

.form-submit {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.privacy-note {
  margin: 12px 0 0;
  color: #71667f;
  line-height: 1.5;
  letter-spacing: 0.06em;
}

.instruction {
  width: min(100%, 390px);
  margin: 24px auto 18px;
  color: #a79caf;
  font-size: 14px;
  line-height: 1.55;
}

.attempt-message {
  margin: 0 0 22px;
  color: #887e99;
}

.screen-error {
  margin: 10px auto 0;
}

.drag-hint {
  position: absolute;
  right: 0;
  bottom: -118px;
  left: 0;
  margin: 0;
  color: #71667f;
}

.drag-hint span {
  margin-right: 8px;
  color: var(--pink);
  font-size: 18px;
  vertical-align: -2px;
}

.result-message {
  margin-bottom: 8px;
}

.save-status {
  min-height: 16px;
  margin: 0 0 18px;
  color: #887e99;
  letter-spacing: 0.08em;
}

.save-status.error {
  color: var(--error);
}

.screen-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.text-button {
  padding: 6px;
  border: 0;
  color: #9b91ad;
  background: transparent;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.text-button:hover {
  color: var(--purple-bright);
}

.leaderboard-panel {
  position: absolute;
  z-index: 10;
  inset: 0;
  padding: 28px;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(135, 79, 254, 0.22), transparent 38%),
    linear-gradient(145deg, rgba(255, 126, 150, 0.035), transparent 45%),
    var(--panel-solid);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 190ms ease, transform 190ms ease, visibility 190ms;
  touch-action: pan-y;
}

.leaderboard-panel.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.leaderboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.leaderboard-header h2 {
  font-size: clamp(40px, 9vw, 56px);
}

.close-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #cfc4df;
  background: rgba(243, 238, 255, 0.04);
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
}

.leaderboard-table-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th {
  position: sticky;
  z-index: 1;
  top: 0;
  padding: 16px 9px 12px;
  color: #776d85;
  background: var(--panel-solid);
  text-align: left;
}

th:first-child {
  width: 44px;
}

th:last-child {
  width: 72px;
  text-align: right;
}

td {
  padding: 14px 9px;
  overflow: hidden;
  border-top: 1px solid rgba(243, 238, 255, 0.08);
  color: #a99fb6;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td:first-child {
  color: var(--purple-bright);
  font-size: 12px;
  font-weight: 800;
}

td:nth-child(2) {
  color: #f3eeff;
  font-weight: 750;
}

td:last-child {
  color: var(--pink);
  font-size: 17px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.leaderboard-state {
  padding: 42px 16px;
  color: #887e99;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.leaderboard-state:empty {
  display: none;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #655b72;
  border-top: 1px solid var(--line);
}

.player-label {
  min-width: 0;
  overflow: hidden;
  color: #84798f;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-link {
  padding: 8px 0 8px 10px;
  border: 0;
  color: #a096ae;
  background: transparent;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
}

.ranking-link span {
  margin-left: 4px;
  color: var(--pink);
}

.ranking-link:disabled {
  color: #4a4055;
  cursor: default;
}

@media (min-width: 560px) {
  .form-fields {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 440px) {
  .stats {
    gap: 15px;
  }

  .stat {
    grid-template-columns: 1fr;
    gap: 1px;
  }

  .stat-label {
    font-size: 7px;
  }

  .leaderboard-panel {
    padding: 22px 15px;
  }

  th:nth-child(3),
  td:nth-child(3) {
    width: 29%;
  }
}

@media (max-height: 650px) {
  .game-shell {
    grid-template-rows: 56px minmax(0, 1fr) 30px;
  }

  .screen:not(.form-screen) {
    padding-top: 48px;
  }

  .instruction {
    margin: 16px auto 12px;
  }

  .drag-hint {
    display: none;
  }

  .form-content {
    margin-top: 0;
  }
}

@media (min-width: 761px) {
  body {
    background:
      linear-gradient(45deg, rgba(135, 79, 254, 0.58), #000 52%),
      var(--bg);
  }

  .game-shell {
    padding-right: 0;
    padding-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .leaderboard-panel {
    transition: none;
  }

  .ambient-orb {
    animation: none;
    filter: blur(12px);
    transform: translate(-50%, -54%) scale(1.18);
  }
}
