:root {
  --bg: #060a16;
  --panel: #141b33;
  --accent: #4fd1c5;
  --accent-2: #f6ad55;
  --text: #e6edf3;
  --muted: #8b98b8;
  --danger: #f56565;
}

* {
  box-sizing: border-box;
}

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

/* Centered portrait "phone" frame. On wide screens it stays a tall column; on a
   phone it fills the viewport. */
#frame {
  position: relative;
  height: 100%;
  width: 100%;
  max-width: min(100vw, calc(100vh * 9 / 18));
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.hidden {
  display: none !important;
}

/* --- Panels (lobby + waiting room) --- */

.panel {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid #24304f;
  border-radius: 16px;
  padding: 26px 26px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.panel h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 2px;
  color: var(--accent);
}

.panel h2 {
  margin: 0;
  font-size: 24px;
  color: var(--accent);
}

.tagline {
  margin: 4px 0 20px;
  color: var(--muted);
  font-size: 14px;
}

label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

input {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid #2a3763;
  background: #0e1428;
  color: var(--text);
  font-size: 16px; /* 16px avoids iOS focus-zoom */
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

#code-input {
  text-transform: uppercase;
  letter-spacing: 4px;
  font-weight: 700;
}

button {
  width: 100%;
  margin-top: 6px;
  padding: 13px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: #06231f;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid #2a3763;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 16px 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid #24304f;
}

.divider span {
  padding: 0 12px;
}

.status {
  min-height: 18px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--accent-2);
}

/* --- Waiting room --- */

.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0e1428;
  border: 1px dashed #2a3763;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 18px;
}

#room-code {
  flex: 1;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 8px;
  color: var(--accent-2);
}

button.copy {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  font-size: 13px;
}

.roster {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.roster-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0e1428;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 15px;
}

.roster-row .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.roster-row .tag {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* --- Game --- */

#game {
  padding: 0;
  background: #03050c;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* the whole surface is the joystick */
}

.drag-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(40px + env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  animation: hintpulse 1.8s ease-in-out infinite;
}

.icon-btn {
  position: absolute;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(10, 16, 32, 0.7);
  color: var(--text);
  border: 1px solid #24304f;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

@keyframes hintpulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.85; }
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

#stats {
  display: flex;
  gap: 10px;
}

.stat {
  display: grid;
  gap: 2px;
  background: rgba(10, 16, 32, 0.7);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.stat-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-right {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.lives {
  font-size: 18px;
  letter-spacing: 2px;
  background: rgba(10, 16, 32, 0.7);
  padding: 6px 12px;
  border-radius: 10px;
  min-height: 30px;
}

.net-status {
  font-size: 12px;
  color: var(--muted);
  background: rgba(10, 16, 32, 0.7);
  padding: 6px 12px;
  border-radius: 10px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 22, 0.7);
  text-align: center;
}

.overlay h2 {
  color: var(--danger);
  margin: 0 0 8px;
  font-size: 28px;
}

.overlay h2.danger {
  color: var(--danger);
}

.overlay p {
  color: var(--muted);
  margin: 0;
}

#gameover-overlay > div {
  background: rgba(20, 27, 51, 0.92);
  border: 1px solid #24304f;
  border-radius: 14px;
  padding: 26px 28px;
  width: min(80vw, 320px);
}

#gameover-stats {
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
}

#gameover-overlay button {
  pointer-events: auto;
}

