:root {
  --ink: #fff8ff;
  --deep: #16062f;
  --violet: #3a1472;
  --pink: #ff62bc;
  --gold: #ffd36b;
  --blue: #65d7ff;
  --panel: rgba(36, 16, 82, 0.74);
  --panel-strong: rgba(24, 9, 56, 0.9);
  --shadow: 0 22px 70px rgba(13, 5, 38, 0.55);
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 14%, rgba(255, 211, 107, 0.24), transparent 28%),
    linear-gradient(155deg, #16062f 0%, #2c0b58 46%, #071b3c 100%);
  font-family: Arial, Helvetica, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

#app {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(100vw, 480px);
  height: min(100dvh, 854px);
  min-height: 520px;
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: var(--deep);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), var(--shadow);
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  opacity: 0;
  pointer-events: none;
  transform: scale(1.015);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.branded-screen {
  background:
    linear-gradient(180deg, rgba(17, 5, 45, 0.18), rgba(15, 4, 36, 0.74)),
    url("assets/background_stage.png") center / cover no-repeat;
}

.branded-screen::before,
.branded-screen::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.branded-screen::before {
  inset: 0;
  background:
    linear-gradient(105deg, transparent 0 23%, rgba(101, 215, 255, 0.17) 28%, transparent 42%),
    linear-gradient(252deg, transparent 0 25%, rgba(255, 98, 188, 0.16) 31%, transparent 45%);
  mix-blend-mode: screen;
}

.branded-screen::after {
  left: 0;
  right: 0;
  bottom: 0;
  height: 22%;
  background: linear-gradient(180deg, transparent, rgba(10, 2, 25, 0.74));
}

.screen-panel,
.leaderboard-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 380px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.screen-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  padding: 22px;
}

.compact-panel {
  align-items: center;
  text-align: center;
}

.game-logo {
  align-self: center;
  width: min(76vw, 286px);
  height: auto;
  filter: drop-shadow(0 10px 24px rgba(14, 4, 40, 0.42));
}

.menu-logo {
  width: min(74vw, 310px);
  margin-bottom: 4px;
}

.small-logo {
  align-self: center;
  width: min(58vw, 210px);
  height: auto;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  color: #ffffff;
  text-align: center;
  font-weight: 900;
  line-height: 1.05;
  text-shadow: 0 4px 12px rgba(11, 4, 35, 0.55);
}

h1 {
  font-size: clamp(28px, 8vw, 38px);
}

h2 {
  font-size: clamp(25px, 7vw, 34px);
}

.loading-copy {
  color: var(--gold);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.loading-bar {
  width: min(72vw, 260px);
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.loading-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--pink), var(--blue));
  transition: width 160ms ease;
}

.field-label,
.player-chip,
.best-card span,
.result-grid span,
.submit-status,
#leaderboardStatus {
  color: rgba(255, 248, 255, 0.88);
  font-weight: 800;
}

.field-label {
  font-size: 15px;
}

.name-input {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border: 2px solid rgba(255, 211, 107, 0.7);
  border-radius: 8px;
  outline: none;
  color: #25104d;
  background: rgba(255, 255, 255, 0.96);
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.name-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(101, 215, 255, 0.22);
}

.form-error {
  min-height: 22px;
  color: #ffd6e9;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.button-stack {
  display: grid;
  gap: 12px;
  width: 100%;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 54px;
  padding: 12px 16px;
  border-radius: 8px;
  color: #211039;
  font-size: 19px;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 10px 22px rgba(9, 3, 32, 0.26);
}

.primary-button {
  background: linear-gradient(180deg, #ffe48c, #ffbd35);
}

.secondary-button {
  color: #ffffff;
  background: linear-gradient(180deg, rgba(255, 98, 188, 0.95), rgba(94, 66, 220, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.menu-panel {
  gap: 13px;
}

.player-chip {
  align-self: center;
  max-width: 100%;
  padding: 8px 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(12, 4, 33, 0.28);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.best-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.13);
}

.best-card strong {
  color: var(--gold);
  font-size: 32px;
  line-height: 1;
}

.game-screen {
  display: block;
  padding: 0;
  background: #14072d;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.game-hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.hud-pill {
  min-width: 118px;
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: #ffffff;
  background: rgba(16, 5, 45, 0.62);
  box-shadow: 0 8px 22px rgba(11, 3, 32, 0.28);
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  backdrop-filter: blur(8px);
}

.hud-pill strong {
  color: var(--gold);
}

.game-over-panel {
  gap: 15px;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 14px;
  padding: 15px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.result-grid strong {
  max-width: 170px;
  overflow: hidden;
  color: var(--gold);
  font-size: 20px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.submit-status {
  min-height: 24px;
  color: #d9f6ff;
  text-align: center;
}

.leaderboard-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  width: min(100%, 430px);
  height: min(100%, 720px);
  max-height: calc(100dvh - 36px);
  padding: 16px;
  background: var(--panel-strong);
}

.leaderboard-head {
  display: grid;
  gap: 4px;
  text-align: center;
}

#leaderboardStatus {
  min-height: 20px;
  font-size: 14px;
}

.leaderboard-table-wrap {
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  color: #ffffff;
  font-size: 13px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
  vertical-align: top;
}

.leaderboard-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--gold);
  background: rgba(23, 8, 59, 0.96);
  font-size: 12px;
}

.leaderboard-table td:nth-child(1),
.leaderboard-table td:nth-child(3),
.leaderboard-table th:nth-child(1),
.leaderboard-table th:nth-child(3) {
  text-align: center;
}

.leaderboard-table td:nth-child(2) {
  max-width: 120px;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.leaderboard-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.leaderboard-actions .primary-button,
.leaderboard-actions .secondary-button {
  min-height: 50px;
  font-size: 16px;
}

#orientationMessage {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 28px;
  color: #ffffff;
  background: linear-gradient(145deg, #120729, #321165 55%, #062146);
  text-align: center;
}

#orientationMessage div {
  max-width: 320px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--gold);
  font-size: 24px;
  font-weight: 900;
  line-height: 1.2;
}

@media (max-width: 600px) and (orientation: portrait) {
  #app {
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    transform: none;
    box-shadow: none;
  }
}

@media (orientation: landscape) and (pointer: coarse) {
  #app {
    visibility: hidden;
  }

  #orientationMessage {
    display: grid;
  }
}

@supports not (height: 100dvh) {
  #app {
    height: min(100vh, 854px);
  }

  .leaderboard-panel {
    max-height: calc(100vh - 36px);
  }
}
