* {
  box-sizing: border-box;
}

/* the hidden attribute must always win over display:flex rules below */
[hidden] {
  display: none !important;
}

:root {
  /* Blue-in-blue main theme */
  --grad-main: linear-gradient(135deg, #38bdf8 0%, #2563eb 55%, #1e3a8a 100%);
  --grad-main-hover: linear-gradient(135deg, #22a8ee 0%, #1d4fd1 55%, #172f75 100%);
  --grad-accent: linear-gradient(135deg, #60a5fa 0%, #1d4ed8 100%);
  /* Purple gradient reserved for a few standout elements (title, primary CTA) */
  --grad-purple: linear-gradient(135deg, #7c3aed 0%, #c026d3 100%);
  --grad-purple-hover: linear-gradient(135deg, #6d28d9 0%, #a21caf 100%);
  --grad-text: var(--grad-purple);
  --glass-bg: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(255, 255, 255, 0.5);
  --ink: #1a1533;
  --muted: #6b6480;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #050b1a;
  color: var(--ink);
}

/* ---------- Home page ---------- */

body.home {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 20% 20%, #102a5c 0%, #0a1830 55%, #040a1a 100%);
}

.bg-blobs {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.55;
  animation: float 16s ease-in-out infinite;
}

.blob-1 {
  width: 480px;
  height: 480px;
  top: -120px;
  left: -100px;
  background: radial-gradient(circle, #38bdf8, transparent 70%);
  animation-delay: 0s;
}

.blob-2 {
  width: 420px;
  height: 420px;
  bottom: -140px;
  right: -100px;
  background: radial-gradient(circle, #2563eb, transparent 70%);
  animation-delay: -5s;
}

.blob-3 {
  width: 360px;
  height: 360px;
  bottom: 10%;
  left: 8%;
  background: radial-gradient(circle, #0ea5e9, transparent 70%);
  animation-delay: -10s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -30px) scale(1.08); }
  66% { transform: translate(-20px, 20px) scale(0.95); }
}

.home-card {
  position: relative;
  z-index: 1;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(20, 10, 60, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  text-align: center;
}

.home-logo {
  font-size: 2.6rem;
  margin-bottom: 4px;
  filter: drop-shadow(0 6px 16px rgba(124, 58, 237, 0.4));
}

.home-card h1 {
  margin: 0 0 8px;
  font-family: 'Poppins', sans-serif;
  font-size: 2.3rem;
  font-weight: 800;
  background: var(--grad-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 30px;
  font-size: 1rem;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 30px;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.join-form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
  padding: 12px 14px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  border: 2px solid rgba(37, 99, 235, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.join-row input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.error-text {
  color: #d33;
  font-size: 0.85rem;
  margin: 0;
}

.feature-list {
  text-align: left;
  list-style: none;
  padding: 18px 18px;
  margin: 0;
  color: #443f5c;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(37, 99, 235, 0.06);
  border-radius: 16px;
  border: 1px solid rgba(37, 99, 235, 0.1);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: 14px;
  border: none;
  background: rgba(59, 130, 246, 0.12);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--grad-purple);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(147, 51, 234, 0.45);
}

.btn-primary:hover {
  background: var(--grad-purple-hover);
  box-shadow: 0 14px 36px rgba(147, 51, 234, 0.55);
}

.btn-secondary {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 8px 22px rgba(102, 126, 234, 0.4);
}

.btn-secondary:hover {
  filter: brightness(1.08);
}

.btn-danger {
  background: linear-gradient(135deg, #ff8a8a, #ff5c5c);
  color: #fff;
  box-shadow: 0 8px 20px rgba(255, 92, 92, 0.35);
}

.btn-danger:hover {
  filter: brightness(1.05);
}

.btn-small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.tool-btn {
  background: rgba(37, 99, 235, 0.1);
}

.tool-btn.active {
  background: var(--grad-main);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}

/* ---------- Draw page ---------- */

body.draw-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at 10% 0%, #102a5c 0%, #0a1830 45%, #040a1a 100%);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 14px 20px;
  background: rgba(10, 22, 48, 0.65);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  z-index: 10;
  color: #f1eefc;
}

.toolbar .btn {
  color: #f1eefc;
  background: rgba(255, 255, 255, 0.08);
}

.toolbar .btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.toolbar .btn-primary,
.toolbar .btn-danger {
  color: #fff;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-info {
  gap: 12px;
}

.room-code {
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  letter-spacing: 3px;
  background: var(--grad-main);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4);
}

.user-count {
  font-size: 0.82rem;
  font-weight: 600;
  color: #baf7c9;
  background: rgba(52, 199, 89, 0.15);
  border: 1px solid rgba(52, 199, 89, 0.3);
  padding: 5px 12px;
  border-radius: 999px;
}

.color-swatches {
  display: flex;
  gap: 7px;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  outline: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.active {
  outline: 2px solid #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.35);
}

#colorPicker {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  background: none;
}

.size-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #cfc9e8;
}

.size-label input[type="range"] {
  accent-color: #2563eb;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
}

#board {
  background: #ffffff;
  box-shadow: 0 20px 60px rgba(10, 5, 40, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  max-width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

.place-hint {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--grad-main);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.5);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--grad-main);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.5);
  z-index: 100;
}

/* ---------- Modals (join / share) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 5, 30, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.modal {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(20, 10, 60, 0.45);
  text-align: center;
}

.modal h2 {
  margin: 0 0 20px;
  font-family: 'Poppins', sans-serif;
  font-size: 1.4rem;
  background: var(--grad-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(37, 99, 235, 0.12);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: rgba(37, 99, 235, 0.22);
}

.join-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: rgba(37, 99, 235, 0.08);
  border-radius: 14px;
  padding: 6px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.tab-btn.active {
  background: var(--grad-main);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.scan-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.scan-panel video {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 16px;
  background: #000;
  box-shadow: 0 10px 30px rgba(20, 10, 60, 0.3);
}

.scan-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.share-qr {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  padding: 16px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(20, 10, 60, 0.15);
}

.share-qr canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.share-code {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.share-code strong {
  color: var(--ink);
  letter-spacing: 2px;
  font-family: 'Poppins', sans-serif;
}

.modal .join-row input {
  font-size: 0.85rem;
  letter-spacing: 0;
  text-transform: none;
}

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

.toolbar-top-actions {
  margin-left: auto;
}

.toolbar-tools {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
}

@media (max-width: 720px) {
  .home-card {
    padding: 32px 22px;
  }

  .home-card h1 {
    font-size: 1.9rem;
  }

  .toolbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .toolbar-top {
    justify-content: space-between;
  }

  .toolbar-tools {
    justify-content: flex-start;
    gap: 12px;
  }

  .toolbar-tools .toolbar-group {
    flex-shrink: 0;
  }

  .room-code {
    padding: 6px 10px;
    font-size: 0.85rem;
    letter-spacing: 1.5px;
  }

  .user-count {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  .btn {
    padding: 10px 14px;
    font-size: 0.88rem;
  }

  .canvas-wrap {
    padding: 12px;
  }

  .size-label input[type="range"] {
    width: 90px;
  }

  .modal {
    padding: 26px 18px;
  }
}

@media (max-width: 420px) {
  .home-logo {
    font-size: 2.2rem;
  }

  .home-card h1 {
    font-size: 1.6rem;
  }

  .swatch {
    width: 22px;
    height: 22px;
  }

  .join-row input {
    font-size: 1rem;
    letter-spacing: 2px;
  }
}
