:root {
  --primary: #ff5c8a;
  --primary-hover: #ff336e;
  --primary-glow: rgba(255, 92, 138, 0.45);
  --secondary: #4a90e2;
  --secondary-hover: #357abd;
  --bg-dark: #0f1117;
  --bg-card: rgba(26, 29, 39, 0.82);
  --bg-glass: rgba(255, 255, 255, 0.08);
  --border-glass: rgba(255, 255, 255, 0.16);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-gold: #f59e0b;
  --accent-green: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  touch-action: none;
  overscroll-behavior: none;
}

#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Glassmorphism utility */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

.hidden {
  display: none !important;
}

/* LOBBY OVERLAY */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none !important;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(15, 17, 23, 0.88) 0%, rgba(10, 11, 16, 0.98) 100%);
  padding: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.active {
  display: flex !important;
}

.overlay.hidden {
  display: none !important;
}

.lobby-card {
  width: 100%;
  max-width: 520px;
  max-height: 94vh;
  overflow-y: auto;
  border-radius: 24px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeInScale 0.35s ease-out;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.lobby-header {
  text-align: center;
}

.lobby-badge {
  display: inline-block;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(255, 92, 138, 0.15);
  border: 1px solid rgba(255, 92, 138, 0.3);
  border-radius: 999px;
  margin-bottom: 8px;
}

.lobby-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lobby-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.section-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Character Selector */
.character-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.char-option {
  cursor: pointer;
  position: relative;
}

.char-option input[type="radio"] {
  display: none;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 14px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.char-option input[type="radio"]:checked + .char-card {
  border-color: var(--primary);
  background: rgba(255, 92, 138, 0.12);
  box-shadow: 0 0 16px rgba(255, 92, 138, 0.25);
  transform: translateY(-2px);
}

.char-icon {
  font-size: 2.3rem;
  margin-bottom: 4px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
}

.char-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  margin-bottom: 2px;
}

.char-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}

.check-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.char-option input[type="radio"]:checked + .char-card .check-mark {
  display: flex;
}

/* Inputs - font-size 16px to prevent iOS zoom */
.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 480px) {
  .input-grid {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group input,
.room-input-row input,
.chat-input-row input,
.url-input-wrap input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: #fff;
  font-size: 16px; /* iOS Safari prevention of auto-zoom */
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  user-select: auto;
  -webkit-user-select: auto;
}

.form-group input:focus,
.room-input-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 92, 138, 0.25);
}

.room-input-row {
  display: flex;
  gap: 6px;
}

.room-input-row input {
  flex: 1;
}

#btn-random-room {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Share Box */
.share-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 92, 138, 0.08);
  border: 1px dashed rgba(255, 92, 138, 0.35);
  border-radius: 12px;
  font-size: 0.8rem;
}

.share-icon {
  font-size: 1rem;
}

.share-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #f1f5f9;
  font-family: monospace;
  font-size: 0.78rem;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
  background: var(--primary);
  border: none;
  color: white;
  cursor: pointer;
  white-space: nowrap;
}

.btn-sm:hover,
.btn-sm:active {
  background: var(--primary-hover);
}

/* Primary Button */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary) 0%, #e11d48 100%);
  border: none;
  border-radius: 14px;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(255, 92, 138, 0.35);
  transition: all 0.2s;
}

.btn-primary:active {
  transform: scale(0.98);
}

.lobby-footer-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.35;
}

/* IN-GAME HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.hud-top-bar {
  position: absolute;
  top: env(safe-area-inset-top, 10px);
  left: 10px;
  right: 10px;
  padding: 8px 12px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: auto;
  gap: 8px;
}

.hud-room-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.room-pill {
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-size: 0.78rem;
  color: #e2e8f0;
}

.room-pill b {
  color: var(--primary);
  font-weight: 700;
}

.players-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 8px;
  font-size: 0.75rem;
  color: #6ee7b7;
  font-weight: 600;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  70% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: white;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.hud-btn-icon {
  padding: 6px 10px;
}

@media (max-width: 600px) {
  .hud-btn .btn-label {
    display: none;
  }
}

/* Painting Interacting Prompt */
.interact-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(65px);
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(16px);
  border: 2px solid var(--accent-gold);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(245, 158, 11, 0.3);
  animation: promptBounce 2s infinite ease-in-out;
  z-index: 15;
}

@keyframes promptBounce {
  0%, 100% { transform: translate(-50%, -50%) translateY(65px); }
  50% { transform: translate(-50%, -50%) translateY(58px); }
}

.prompt-icon {
  font-size: 1.6rem;
}

.prompt-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
}

.prompt-keys {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.key-badge {
  display: inline-block;
  padding: 2px 6px;
  background: #334155;
  border: 1px solid #64748b;
  border-radius: 6px;
  font-weight: 700;
  color: #fff;
  font-size: 0.72rem;
}

.click-badge {
  color: var(--accent-gold);
  font-weight: 600;
}

/* Proximity partner status */
.partner-status {
  position: absolute;
  top: 65px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: rgba(255, 92, 138, 0.22);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 92, 138, 0.4);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #ffe4e6;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 16px rgba(255, 92, 138, 0.25);
  z-index: 12;
}

/* Bottom Bar */
.hud-bottom-bar {
  position: absolute;
  bottom: env(safe-area-inset-bottom, 14px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
}

.emote-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 18px;
}

.emote-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: white;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  justify-content: center;
}

.emote-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.18);
}

.emote-icon {
  font-size: 1.25rem;
}

.emote-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Chat Widget */
.chat-widget {
  position: absolute;
  bottom: 74px;
  left: 12px;
  width: 300px;
  max-width: calc(100vw - 24px);
  border-radius: 18px;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 25;
}

.chat-widget.collapsed {
  display: none;
}

.chat-header {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  font-weight: 600;
}

.chat-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
}

.chat-messages {
  height: 140px;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  -webkit-overflow-scrolling: touch;
}

.chat-sys-msg {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.72rem;
  text-align: center;
}

.chat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(255, 255, 255, 0.05);
  padding: 5px 8px;
  border-radius: 8px;
}

.chat-item .chat-sender {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary);
}

.chat-item.self .chat-sender {
  color: var(--secondary);
}

.chat-item .chat-text {
  word-break: break-word;
  color: #fff;
  line-height: 1.25;
}

.chat-input-row {
  display: flex;
  padding: 6px;
  gap: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-input-row input {
  flex: 1;
  padding: 6px 10px;
}

.chat-input-row button {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* MOBILE CONTROLS & JOYSTICK */
.mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}

/* Virtual Joystick Zone */
.joystick-zone {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 70px);
  left: 20px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.03) 70%);
  border: 2px solid rgba(255, 255, 255, 0.22);
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.joystick-thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #e11d48 100%);
  box-shadow: 0 0 16px var(--primary-glow);
  pointer-events: none;
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.mobile-action-buttons {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 70px);
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

.mobile-action-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: white;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.mobile-action-btn:active {
  transform: scale(0.92);
}

.mobile-action-btn.primary {
  background: var(--accent-gold);
  border-color: #fef08a;
  color: #1e1b4b;
  animation: pulseGold 2s infinite;
}

@keyframes pulseGold {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
}

/* MODALS */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(10, 11, 16, 0.88);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  animation: fadeIn 0.2s ease-out;
  overflow-y: auto;
}

.modal-card {
  width: 100%;
  max-width: 740px;
  border-radius: 22px;
  padding: 22px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal-close-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.photo-modal-body {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 680px) {
  .photo-modal-body {
    grid-template-columns: 1fr;
  }
}

.photo-frame-display {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  border: 6px solid #27272a;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-frame-display img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.7);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.photo-details {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.photo-header-row h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.photo-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.customize-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.customize-box-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.upload-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-upload-file {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-upload-file:active {
  background: rgba(255, 255, 255, 0.18);
  border-color: var(--primary);
}

.url-input-wrap {
  display: flex;
  gap: 6px;
}

.preset-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.preset-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.preset-btn {
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  color: #e2e8f0;
  font-size: 0.72rem;
  cursor: pointer;
}

.preset-btn:active {
  background: rgba(255, 92, 138, 0.25);
  border-color: var(--primary);
}

.sync-note {
  font-size: 0.72rem;
  color: #94a3b8;
  line-height: 1.3;
}

/* Help Modal */
.help-card {
  max-width: 520px;
}

.help-card h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.controls-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.control-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 0.8rem;
}

.control-desc {
  color: var(--text-muted);
}

.help-info-box {
  padding: 10px 12px;
  background: rgba(74, 144, 226, 0.12);
  border: 1px solid rgba(74, 144, 226, 0.3);
  border-radius: 10px;
  font-size: 0.78rem;
  color: #bfdbfe;
  line-height: 1.4;
}

/* TOASTS */
.toast-container {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 20px) + 72px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 300;
  pointer-events: none;
  width: 90%;
  max-width: 360px;
}

.toast {
  padding: 8px 16px;
  background: rgba(15, 17, 23, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28), toastOut 0.25s ease-in forwards 2.75s;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-10px); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
