:root {
  --blue: #00d4ff;
  --red: #ff2d55;
  --gold: #ffc940;
  --bg: #04060a;
  --panel: #080d14;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Orbitron", monospace;
  overflow: hidden;
  overscroll-behavior: none;
  cursor: none;
  user-select: none;
}

#game-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* 9:16 portrait outer container */
#outer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 390px;
  height: 844px;
  transform-origin: center center;
}

@media (max-height: 844px), (max-width: 390px) {
  #outer {
    transform: scale(min(calc(100vw / 390), calc(100dvh / 844)));
  }
}

/* Top scoreboard */
#stat-top {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px 16px 0 0;
  padding: 16px 20px 12px;
  border-bottom: none;
}

.stat-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 2px;
}

.stat-center .stat-label {
  line-height: 1.2;
}

.stat-divider-v {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.07);
}

.stat-name {
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 4px;
}

.stat-score {
  font-weight: 900;
  font-size: 52px;
  line-height: 1;
  letter-spacing: -2px;
}

/* ── Arena ── */
#arena {
  position: relative;
  flex: 1;
  touch-action: none;
  cursor: default;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  box-shadow: 0 0 0 2px rgba(0,212,255,0.2), 0 0 50px rgba(0,212,255,0.1);
}

/* Bottom stats */
#stat-bottom {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 0 0 16px 16px;
  border-top: none;
  padding: 10px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-spacer { flex: 1; }

.stat-label {
  font-family: "Rajdhani", sans-serif;
  font-weight: 500;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase;
}

.stat-val {
  font-family: "Orbitron", monospace;
  font-weight: 700;
  font-size: 12px;
}

/*  Overlay Screens */
#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  background: rgba(4,6,10,0.45);
  backdrop-filter: blur(8px);
}

.screen.on {
  opacity: 1;
  pointer-events: all;
}

/*  Ready screen */
.ready-inner { text-align: center; }

.ready-logo {
  font-weight: 900;
  font-size: 64px;
  line-height: 0.9;
  color: #fff;
}

.ready-logo span {
  display: block;
  color: var(--blue);
  text-shadow: 0 0 30px var(--blue), 0 0 70px rgba(0,212,255,0.35);
}

.ready-sub {
  font-family: "Rajdhani", sans-serif;
  font-weight: 300;
  font-size: 12px;
  letter-spacing: 10px;
  color: var(--gold);
  margin-top: 6px;
  margin-bottom: 28px;
}

.ready-prompt {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  color: rgba(255,255,255,0.7);
  animation: pulse 1.4s ease-in-out infinite;
}

.ready-profile {
  margin: 18px auto 0;
  padding: 12px 14px 14px;
  width: min(280px, 84vw);
  border: 1px solid rgba(0,212,255,0.22);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(8,13,20,0.85), rgba(4,6,10,0.92));
  box-shadow: 0 0 20px rgba(0,212,255,0.08);
}

.ready-profile-label {
  font-family: "Rajdhani", sans-serif;
  font-size: 10px;
  letter-spacing: 3px;
  color: rgba(255,255,255,0.35);
  margin-bottom: 8px;
}

.ready-profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ready-auth-row {
  margin-top: 8px;
}

#profile-name {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 12px rgba(255,255,255,0.2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#profile-btn {
  padding: 8px 14px;
  border-width: 1px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--gold);
  border-color: rgba(255,201,64,0.6);
  clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
}

#profile-btn:hover, #profile-btn:active {
  background: var(--gold);
  color: #000;
  box-shadow: 0 0 22px rgba(255,201,64,0.35);
}

#auth-state {
  font-family: "Rajdhani", sans-serif;
  font-size: 11px;
  letter-spacing: 1.6px;
  color: rgba(255,255,255,0.32);
}

#auth-btn {
  padding: 8px 14px;
  border-width: 1px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--blue);
  border-color: rgba(0,212,255,0.6);
  clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
}

#auth-btn:hover, #auth-btn:active {
  background: var(--blue);
  color: #000;
  box-shadow: 0 0 22px rgba(0,212,255,0.35);
}

#auth-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.ready-profile-state {
  margin-top: 8px;
  font-family: "Rajdhani", sans-serif;
  font-size: 11px;
  letter-spacing: 1.8px;
  color: rgba(255,255,255,0.28);
}

.ready-keys {
  margin-top: 18px;
  font-family: "Rajdhani", sans-serif;
  font-weight: 300;
  font-size: 11px;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.22);
}

.ready-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

#arch-btn {
  padding: 10px 16px;
  border-width: 1px;
  font-size: 10px;
  letter-spacing: 2px;
  color: #8ff3ff;
  border-color: rgba(143,243,255,0.6);
  background: rgba(9,20,28,0.7);
}

#arch-btn:hover, #arch-btn:active {
  background: rgba(143,243,255,0.18);
  color: #fff;
  box-shadow: 0 0 18px rgba(143,243,255,0.38);
}

#arch-screen {
  background: rgba(4,6,10,0.8);
}

.arch-inner {
  width: min(368px, 94vw);
  max-height: calc(100% - 32px);
  overflow: auto;
  border: 1px solid rgba(143,243,255,0.28);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(8,13,20,0.95), rgba(4,6,10,0.96));
  box-shadow: 0 0 28px rgba(0,212,255,0.15);
  padding: 18px 16px 20px;
}

.arch-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-align: center;
}

.arch-sub {
  margin-top: 4px;
  margin-bottom: 14px;
  text-align: center;
  font-family: "Rajdhani", sans-serif;
  font-size: 13px;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.6);
}

.arch-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.arch-card {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(10,16,24,0.75);
  padding: 12px;
}

.arch-card-title {
  font-size: 13px;
  letter-spacing: 1.5px;
  color: #8ff3ff;
  margin-bottom: 8px;
}

.arch-card p {
  margin: 0;
  font-family: "Rajdhani", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: rgba(255,255,255,0.78);
}

.arch-flow {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  align-items: center;
}

.arch-flow span {
  text-align: center;
  font-family: "Rajdhani", sans-serif;
  font-size: 12px;
  letter-spacing: 0.8px;
  color: rgba(255,255,255,0.82);
  border: 1px solid rgba(0,212,255,0.22);
  border-radius: 8px;
  padding: 8px 4px;
  background: rgba(0,212,255,0.08);
}

.arch-link-row {
  margin-top: 12px;
  display: flex;
  justify-content: center;
}

.arch-link-btn {
  display: inline-block;
  padding: 9px 14px;
  border: 1px solid rgba(143,243,255,0.5);
  border-radius: 8px;
  font-family: "Orbitron", monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: #8ff3ff;
  text-decoration: none;
  background: rgba(8,18,24,0.75);
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.arch-link-btn:hover, .arch-link-btn:active {
  background: rgba(143,243,255,0.2);
  color: #fff;
  box-shadow: 0 0 18px rgba(143,243,255,0.3);
}

.arch-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

#arch-close {
  padding: 10px 18px;
  border-width: 1px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--gold);
  border-color: rgba(255,201,64,0.6);
}

#arch-close:hover, #arch-close:active {
  background: var(--gold);
  color: #000;
  box-shadow: 0 0 22px rgba(255,201,64,0.35);
}

/*  Game Over screen */
.go-face {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid currentColor;
  position: relative;
  margin-bottom: 8px;
  display: inline-block;
  animation: facePop 0.5s cubic-bezier(0.36,0.07,0.19,0.97) both;
}

.go-face::before,
.go-face::after {
  content: "";
  position: absolute;
  border-radius: 2px;
}

.go-face.win {
  color: var(--blue);
  box-shadow: 0 0 22px rgba(0,212,255,0.35);
}

.go-face.win::before {
  left: 16px;
  top: 33px;
  width: 13px;
  height: 3px;
  background: currentColor;
  transform: rotate(42deg);
}

.go-face.win::after {
  left: 24px;
  top: 28px;
  width: 26px;
  height: 3px;
  background: currentColor;
  transform: rotate(-46deg);
}

.go-face.loss {
  color: var(--red);
  box-shadow: 0 0 22px rgba(255,45,85,0.35);
}

.go-face.loss::before {
  left: 17px;
  top: 31px;
  width: 34px;
  height: 3px;
  background: currentColor;
  transform: rotate(45deg);
}

.go-face.loss::after {
  left: 17px;
  top: 31px;
  width: 34px;
  height: 3px;
  background: currentColor;
  transform: rotate(-45deg);
}

@keyframes facePop {
  0% { transform: scale(0); opacity: 0; }
  65% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.go-inner { text-align: center; }

.go-who {
  font-size: clamp(32px,7vw,56px);
  font-weight: 900;
  line-height: 1;
}

.go-wins {
  font-family: "Rajdhani", sans-serif;
  font-weight: 300;
  font-size: 15px;
  letter-spacing: 10px;
  color: rgba(255,255,255,0.6);
  margin-top: 3px;
}

.go-final {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 20px var(--gold);
  margin: 12px 0 24px;
}

button {
  padding: 13px 44px;
  background: transparent;
  border: 2px solid var(--blue);
  color: var(--blue);
  font-family: "Orbitron", monospace;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 4px;
  cursor: pointer;
  clip-path: polygon(10px 0%, 100% 0%, calc(100% - 10px) 100%, 0% 100%);
  transition: background 0.2s, box-shadow 0.2s, color 0.2s;
}

button:hover, button:active {
  background: var(--blue);
  color: #000;
  box-shadow: 0 0 30px rgba(0,212,255,0.5);
}

#mute-btn {
  position: absolute;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  right: 12px;
  font-family: "Rajdhani", sans-serif;
  font-size: 9px;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.18);
  cursor: pointer;
  pointer-events: all;
}

#exit-link {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 20;
  padding: 5px 8px;
  border: 1px solid rgba(0,212,255,0.42);
  border-radius: 7px;
  color: rgba(143,243,255,0.9);
  background: rgba(6,14,22,0.62);
  text-decoration: none;
  font-family: "Rajdhani", sans-serif;
  font-size: 9px;
  letter-spacing: 1.5px;
  pointer-events: all;
}

#exit-link:hover, #exit-link:active {
  background: rgba(0,212,255,0.18);
  color: #fff;
  box-shadow: 0 0 14px rgba(0,212,255,0.25);
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

@keyframes emoji-bounce {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(8deg); opacity: 1; }
  80% { transform: scale(0.9) rotate(-4deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}