/* ============================================================
   COSMIC DESIGN SUITE PRO — style.css
   Sections:
     1. CSS Variables (Tokens)
     2. Reset & Base
     3. Header
     4. Layout
     5. Sidebar & Cards
     6. Tab Navigation
     7. Control Groups (Sliders, Colors, Toggles, Select)
     8. Buttons
     9. Preview Stage
    10. Code Output
    11. Shape Quick-Add
    12. Tips Panel
    13. Footer
    14. Animations
    15. Responsive (Mobile)
   ============================================================ */


/* ─────────────────────────────────────────────
   1. CSS VARIABLES (TOKENS)
   ───────────────────────────────────────────── */
:root {
  /* Colors — Dark Theme (default) */
  --bg:        #05070f;
  --surface:   #0d1117;
  --surface2:  #141920;
  --border:    #1e2a38;
  --border2:   #263445;
  --text:      #e2eaf5;
  --muted:     #7a8fa8;
  --primary:   #6366f1;
  --primary-g: #818cf8;
  --accent:    #f472b6;
  --green:     #34d399;
  --yellow:    #fbbf24;
  --red:       #f87171;

  /* Typography */
  --font-head: 'Unbounded', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;

  /* Spacing / Shape */
  --radius:    14px;
  --radius-sm: 9px;

  /* Effects */
  --shadow:    0 8px 32px rgba(0,0,0,0.45);
  --glow:      0 0 20px rgba(99,102,241,0.25);
  --trans:     0.22s cubic-bezier(0.4,0,0.2,1);
}

/* Light Theme Overrides */
[data-theme="light"] {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface2:  #eef1f8;
  --border:    #dce3ef;
  --border2:   #c8d3e6;
  --text:      #1a2035;
  --muted:     #5a6a84;
  --primary:   #4f46e5;
  --primary-g: #6366f1;
  --accent:    #ec4899;
  --shadow:    0 8px 32px rgba(0,0,0,0.10);
  --glow:      0 0 20px rgba(99,102,241,0.12);
}


/* ─────────────────────────────────────────────
   2. RESET & BASE
   ───────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 10px; }


/* ─────────────────────────────────────────────
   3. HEADER
   ───────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Logo — gradient text */
.logo {
  font-family: var(--font-head);
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--primary-g) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Theme toggle button */
.theme-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 30px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--trans);
  white-space: nowrap;
}
.theme-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}


/* ─────────────────────────────────────────────
   4. LAYOUT
   ───────────────────────────────────────────── */
.app {
  flex: 1;
  display: flex;
  max-width: 1380px;
  margin: 0 auto;
  width: 100%;
  padding: 20px;
  gap: 20px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Thin horizontal separator */
hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}


/* ─────────────────────────────────────────────
   5. SIDEBAR & CARDS
   ───────────────────────────────────────────── */
.sidebar {
  width: 310px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Generic surface card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}

/* Control panel sections — hidden by default */
.ctrl-section { display: none; }
.ctrl-section.active {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeUp 0.25s ease forwards;
}


/* ─────────────────────────────────────────────
   6. TAB NAVIGATION
   ───────────────────────────────────────────── */
.tab-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  display: flex;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  transition: var(--trans);
  white-space: nowrap;
}
.tab-btn .icon { font-size: 1rem; }
.tab-btn:hover {
  color: var(--text);
  background: var(--surface2);
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 0 0 1px var(--primary), var(--glow);
}


/* ─────────────────────────────────────────────
   7. CONTROL GROUPS
   ───────────────────────────────────────────── */

/* Horizontal row (label + toggle or label + value) */
.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Vertical stacked control */
.ctrl-col {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Label text */
.ctrl-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

/* Live value badge next to label */
.ctrl-val {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary-g);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 5px;
  min-width: 36px;
  text-align: center;
}

/* ── Range Slider ── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border2);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 2px var(--primary);
  cursor: pointer;
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  cursor: pointer;
}

/* ── Color Picker ── */
.color-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.color-wrap input[type="color"] {
  -webkit-appearance: none;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  padding: 0;
  flex-shrink: 0;
}
.color-wrap input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 6px;
}
.color-wrap input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}
.color-hex {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1;
}

/* ── Toggle Switch ── */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.slider-track {
  width: 44px;
  height: 24px;
  background: var(--border2);
  border-radius: 12px;
  transition: var(--trans);
  position: relative;
}
.slider-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: var(--trans);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.switch input:checked + .slider-track { background: var(--primary); }
.switch input:checked + .slider-track::after { left: 23px; }

/* ── Dropdown Select ── */
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  /* Custom dropdown arrow */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a8fa8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}


/* ─────────────────────────────────────────────
   8. BUTTONS
   ───────────────────────────────────────────── */
.btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--trans);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.97) !important; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover {
  background: var(--primary-g);
  transform: translateY(-1px);
  box-shadow: var(--glow);
}

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { opacity: 0.88; transform: translateY(-1px); }

.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.88; }

.btn-ghost {
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { color: var(--text); border-color: var(--primary); }


/* ─────────────────────────────────────────────
   9. PREVIEW STAGE
   ───────────────────────────────────────────── */
.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.preview-title {
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* "● Live" indicator */
.live-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--green);
}
.live-dot {
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

/* Canvas area */
.preview-stage {
  position: relative;
  width: 100%;
  height: 360px;
  background: var(--bg);
  /* Subtle dot grid + ambient glow */
  background-image:
    radial-gradient(circle at 20% 80%, rgba(99,102,241,0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(244,114,182,0.06) 0%, transparent 50%),
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 24px 24px, 24px 24px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#preview-svg {
  width: 100%;
  height: 100%;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

/* Dimension display shown at top-center while drawing */
.dim-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  white-space: nowrap;
}
.dim-badge.visible { opacity: 1; }

/* Hint shown in the top-right corner in Shapes mode */
.tap-indicator {
  position: absolute;
  top: 12px;
  right: 16px;
  background: rgba(244,114,182,0.12);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
}


/* ─────────────────────────────────────────────
   10. CODE OUTPUT
   ───────────────────────────────────────────── */
.code-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

.code-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* "SVG" language badge */
.code-lang {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--green);
  background: rgba(52,211,153,0.1);
  padding: 3px 8px;
  border-radius: 4px;
}

.code-title {
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.code-actions { display: flex; gap: 8px; }

.code-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text);
  transition: var(--trans);
  display: flex;
  align-items: center;
  gap: 5px;
}
.code-btn:hover { border-color: var(--primary); color: var(--primary); }
.code-btn.copied { background: var(--green); color: #000; border-color: var(--green); }

/* The SVG code textarea */
textarea#code-output {
  width: 100%;
  height: 160px;
  padding: 16px 20px;
  background: #020408;
  color: #a7f3d0;
  border: none;
  border-radius: 0;
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  white-space: pre;
  overflow: auto;
}
[data-theme="light"] textarea#code-output { background: #0d1117; }


/* ─────────────────────────────────────────────
   11. SHAPE QUICK-ADD (Mobile friendly presets)
   ───────────────────────────────────────────── */
.quick-shapes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.shape-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--trans);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.shape-preset:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99,102,241,0.08);
}
.shape-preset svg { flex-shrink: 0; }


/* ─────────────────────────────────────────────
   12. TIPS / KNOWLEDGE PANEL
   ───────────────────────────────────────────── */
.tips-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
}

.tips-panel .tip-title {
  font-family: var(--font-head);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--primary-g);
  margin-bottom: 10px;
}

.tips-panel p,
.tips-panel li {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
}

.tips-panel ul {
  padding-left: 14px;
  margin-top: 6px;
}
.tips-panel li + li { margin-top: 4px; }


/* ─────────────────────────────────────────────
   13. FOOTER
   ───────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface);
}

footer strong {
  color: var(--primary-g);
}


/* ─────────────────────────────────────────────
   14. ANIMATIONS
   ───────────────────────────────────────────── */

/* Tab panel fade + slide up */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Live dot pulse */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.3); }
}


/* ─────────────────────────────────────────────
   15. RESPONSIVE — MOBILE
   ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
    padding: 12px;
    gap: 12px;
  }

  .sidebar { width: 100%; }

  .preview-stage { height: 260px; }

  textarea#code-output {
    height: 120px;
    font-size: 0.72rem;
  }

  .code-actions { gap: 5px; }
  .code-btn { padding: 5px 10px; font-size: 0.72rem; }

  /* Hide text labels on tabs, show only icons */
  .tab-btn .label { display: none; }

  /* Hide tips on small screens to save space */
  .tips-panel { display: none; }

  /* Shorten theme button */
  .theme-btn .long { display: none; }
}

@media (max-width: 480px) {
  header { padding: 0 14px; }
  .logo  { font-size: 0.72rem; }
  .preview-stage { height: 220px; }
}