/* ==========================================
   Matrix LiveDraw — Dark Premium Aesthetic
   ========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #0a0a0f;
  --bg-card: #141420;
  --bg-card-hover: #1a1a2e;
  --surface: #1e1e30;
  --border: #2a2a40;
  --border-glow: rgba(187, 134, 252, 0.3);
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --text-muted: #555570;
  --primary: #bb86fc;
  --primary-glow: rgba(187, 134, 252, 0.15);
  --primary-dark: #9966dd;
  --accent: #03dac6;
  --accent-glow: rgba(3, 218, 198, 0.15);
  --danger: #ff3b5c;
  --success: #00e676;
  --warning: #ffab40;
  --canvas-border: rgba(187, 134, 252, 0.5);
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 30px rgba(187, 134, 252, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(187, 134, 252, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(3, 218, 198, 0.04) 0%, transparent 60%);
}

/* ---- HEADER ---- */
.header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 20px rgba(187, 134, 252, 0.2);
}

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--text), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.status-badges {
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.3s;
}

.badge.live {
  border-color: var(--success);
  color: var(--success);
  animation: pulse-border 2s infinite;
}

.badge.queue {
  border-color: var(--warning);
  color: var(--warning);
}

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 230, 118, 0.2); }
  50% { box-shadow: 0 0 0 4px rgba(0, 230, 118, 0.05); }
}

/* ---- MAIN CONTENT ---- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  gap: 20px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

/* ---- CANVAS CARD ---- */
.canvas-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.canvas-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--primary-glow), transparent 40%, transparent 60%, var(--accent-glow));
  pointer-events: none;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  margin-bottom: 16px;
}

#draw-canvas {
  width: 280px;
  height: 280px;
  background: #000;
  border: 2px solid var(--canvas-border);
  border-radius: 6px;
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: none;
  box-shadow:
    0 0 30px rgba(187, 134, 252, 0.08),
    inset 0 0 60px rgba(0,0,0,0.5);
  transition: border-color 0.3s;
}

#draw-canvas:hover {
  border-color: var(--primary);
}

#draw-canvas.disabled {
  cursor: not-allowed;
  opacity: 0.4;
  filter: grayscale(0.5);
}

.canvas-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 8px;
}

/* ---- TOOLBAR ---- */
.toolbar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  box-shadow: var(--shadow);
}

.tool-section {
  margin-bottom: 14px;
}

.tool-section:last-child {
  margin-bottom: 0;
}

.tool-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.tool-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.tool-btn {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

.tool-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #000;
  box-shadow: 0 0 15px rgba(187, 134, 252, 0.3);
}

.tool-btn.danger {
  color: var(--danger);
  border-color: rgba(255, 59, 92, 0.3);
}

.tool-btn.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ---- COLOR + SIZE ROW ---- */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="color"] {
  width: 40px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

input[type="color"]:hover {
  border-color: var(--primary);
}

.size-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.size-slider-wrap label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}

input[type="range"] {
  flex: 1;
  height: 6px;
  accent-color: var(--primary);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px rgba(187, 134, 252, 0.3);
}

.size-val {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  min-width: 20px;
  text-align: right;
}

select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

select:hover,
select:focus {
  border-color: var(--primary);
}

/* ---- STATUS PANEL ---- */
.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 20px;
  width: 100%;
  box-shadow: var(--shadow);
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.status-item {
  text-align: center;
  padding: 12px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.status-item .value {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.status-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ---- QUEUE OVERLAY ---- */
.queue-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.queue-overlay.visible {
  display: flex;
}

.queue-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow-glow);
}

.queue-box .queue-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.queue-box h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.queue-box .queue-pos {
  font-size: 56px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--warning), #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 12px 0;
}

.queue-box p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
}

.queue-box .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 16px auto 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- CONNECTING OVERLAY ---- */
.connect-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.5s;
}

.connect-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.connect-overlay h2 {
  font-size: 20px;
  font-weight: 600;
}

.connect-overlay p {
  color: var(--text-dim);
  font-size: 14px;
}

.connect-overlay .spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ---- FOOTER ---- */
.footer {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover {
  text-decoration: underline;
}

/* ---- CURSOR INDICATORS ---- */
.cursor-indicator {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 10;
  box-shadow: 0 0 8px currentColor;
  transition: left 0.1s, top 0.1s;
}

/* ---- SWATCHES ---- */
.swatch-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.swatch:hover {
  transform: scale(1.15);
  border-color: var(--text);
}

.swatch.active {
  border-color: #fff;
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(255,255,255,0.3);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 420px) {
  #draw-canvas {
    width: 240px;
    height: 240px;
  }

  .badge {
    padding: 4px 8px;
    font-size: 11px;
  }

  .status-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .tool-btn {
    padding: 7px 10px;
    font-size: 12px;
  }
}

@media (min-width: 600px) {
  #draw-canvas {
    width: 320px;
    height: 320px;
  }
}

/* ---- NOTIFY TOAST ---- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: var(--shadow);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.info { border-color: var(--primary); color: var(--primary); }
