:root {
  --navy: #031867;
  --navy-deep: #01072e;
  --navy-mid: #071f7d;
  --white: #f4f7ff;
  --cyan: #2ce8f5;
  --violet: #8a6bff;
  --pink: #ff3ea5;
  --glass: rgba(244, 247, 255, 0.05);
  --glass-border: rgba(44, 232, 245, 0.25);
  --font-display: "Orbitron", "Rajdhani", sans-serif;
  --font-body: "Rajdhani", "Segoe UI", sans-serif;
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--white);
  background: var(--navy-deep);
}

.scene {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(138, 107, 255, 0.18), transparent 60%),
    radial-gradient(ellipse 70% 60% at 50% 100%, rgba(3, 24, 103, 0.9), transparent 70%),
    linear-gradient(180deg, var(--navy-deep) 0%, var(--navy) 55%, var(--navy-deep) 100%);
  overflow: hidden;
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(44, 232, 245, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 232, 245, 0.07) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 30%, transparent 85%);
  animation: drift 30s linear infinite;
  pointer-events: none;
}

@keyframes drift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 42px 84px, 84px 42px; }
}

.bg-glow {
  position: absolute;
  top: -20%;
  left: 50%;
  width: 900px;
  height: 900px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(44, 232, 245, 0.14), transparent 65%);
  pointer-events: none;
  filter: blur(10px);
}

/* ---- Header ---- */

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px clamp(16px, 3vw, 48px) 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

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

.brand-logo {
  height: 40px;
  width: auto;
  border-radius: 8px;
  box-shadow: 0 0 18px rgba(44, 232, 245, 0.35);
}

.brand-title {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-game {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(18px, 2vw, 26px);
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--white), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tag {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(244, 247, 255, 0.5);
}

.stat-pills {
  display: flex;
  gap: 10px;
}

.pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 68px;
  padding: 6px 14px;
  border-radius: 10px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
}

.pill-label {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(244, 247, 255, 0.5);
}

.pill-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(44, 232, 245, 0.6);
}

/* ---- Stage ---- */

.stage {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr) minmax(140px, 220px);
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3vw, 56px);
  padding: 8px clamp(16px, 3vw, 48px);
  min-height: 0;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid rgba(244, 247, 255, 0.08);
  backdrop-filter: blur(6px);
}

.side-panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--cyan);
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  max-height: 100%;
  overflow-y: auto;
}

.lb-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  border-radius: 6px;
  color: rgba(244, 247, 255, 0.75);
}

.lb-row:nth-child(odd) {
  background: rgba(244, 247, 255, 0.03);
}

.lb-row.lb-you {
  background: rgba(44, 232, 245, 0.12);
  color: var(--white);
  box-shadow: inset 0 0 0 1px rgba(44, 232, 245, 0.35);
}

.lb-rank {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--cyan);
}

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

.lb-score {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--white);
}

.lb-empty {
  font-size: 12px;
  color: rgba(244, 247, 255, 0.45);
  padding: 4px 2px;
}

.sys-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: rgba(244, 247, 255, 0.6);
  border-top: 1px solid rgba(244, 247, 255, 0.08);
  padding-top: 10px;
}

.sys-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.sys-row span:last-child {
  color: var(--white);
  font-weight: 600;
}

/* ---- Board ---- */

.board-frame {
  position: relative;
  width: min(78vh, 100%, 760px);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  justify-self: center;
  padding: 10px;
}

.board-corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2px solid var(--cyan);
  opacity: 0.8;
  filter: drop-shadow(0 0 6px rgba(44, 232, 245, 0.7));
}

.board-corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.board-corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.board-corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.board-corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

.board-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: radial-gradient(ellipse at 50% 0%, rgba(138, 107, 255, 0.12), transparent 60%), #030a2e;
  border: 1px solid rgba(44, 232, 245, 0.3);
  box-shadow:
    0 0 0 1px rgba(3, 24, 103, 0.6),
    0 30px 80px rgba(0, 0, 0, 0.55),
    inset 0 0 60px rgba(44, 232, 245, 0.06);
  overflow: hidden;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  background: rgba(1, 7, 46, 0.82);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.overlay.demo-active {
  background: rgba(1, 7, 46, 0.45);
}

.demo-badge {
  display: none;
  align-items: center;
  gap: 7px;
  padding: 5px 14px;
  margin-bottom: 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 62, 165, 0.4);
  background: rgba(255, 62, 165, 0.1);
  color: var(--pink);
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(255, 62, 165, 0.6);
}

.overlay.demo-active .demo-badge {
  display: inline-flex;
}

.demo-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 8px rgba(255, 62, 165, 0.9);
  animation: demo-pulse 1.2s ease-in-out infinite;
}

@keyframes demo-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

.overlay-logo {
  height: 34px;
  width: auto;
  margin-bottom: 6px;
  border-radius: 6px;
  opacity: 0.9;
}

.overlay-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(30px, 5vw, 46px);
  letter-spacing: 8px;
  background: linear-gradient(90deg, var(--cyan), var(--white), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(44, 232, 245, 0.35);
}

.overlay-msg {
  font-size: 14px;
  color: rgba(244, 247, 255, 0.75);
  white-space: pre-line;
  max-width: 320px;
  line-height: 1.6;
}

.overlay-btn {
  margin-top: 4px;
  padding: 10px 28px;
  border-radius: 999px;
  border: 1px solid var(--cyan);
  background: linear-gradient(90deg, rgba(44, 232, 245, 0.15), rgba(138, 107, 255, 0.15));
  color: var(--white);
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(44, 232, 245, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.overlay-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 30px rgba(44, 232, 245, 0.45);
}

.name-field {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-top: 4px;
}

.name-label {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(244, 247, 255, 0.45);
  padding-left: 2px;
}

.name-input {
  width: 220px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(244, 247, 255, 0.06);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  cursor: text;
  user-select: text;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.name-input::placeholder {
  color: rgba(244, 247, 255, 0.35);
  font-weight: 500;
}

.name-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(44, 232, 245, 0.3);
}

.name-input.shake {
  animation: shake 0.35s ease;
  border-color: var(--pink);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.overlay-leaderboard {
  width: 100%;
  max-width: 260px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  max-height: 140px;
  overflow-y: auto;
}

/* ---- Footer ---- */

.footer {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 10px;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(244, 247, 255, 0.35);
}

.footer .dot {
  color: var(--cyan);
}

/* ---- D-pad (touch) ---- */

.dpad {
  display: none;
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 168px;
  height: 168px;
  z-index: 5;
}

.dpad-btn {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--cyan);
  font-size: 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.dpad-btn:active {
  background: rgba(44, 232, 245, 0.2);
  transform: translateY(1px);
}

.dpad-btn.up { top: 0; left: 57px; }
.dpad-btn.down { top: 114px; left: 57px; }
.dpad-btn.left { top: 57px; left: 0; }
.dpad-btn.right { top: 57px; left: 114px; }

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .side-panel { display: none; }
  .stage { grid-template-columns: 1fr; }
  .board-frame { width: min(88vw, 88dvh, 620px); }
}

@media (pointer: coarse) {
  .dpad { display: block; }
  .board-frame { width: min(92vw, 62dvh, 560px); }
  .scene { padding-bottom: 0; }
}

@media (max-width: 480px) {
  .brand-tag { display: none; }
  .stat-pills { gap: 6px; }
  .pill { min-width: 44px; padding: 4px 8px; }
  .pill-label { font-size: 9px; letter-spacing: 1px; }
  .pill-value { font-size: 15px; }
  .brand-logo { height: 32px; }
}
