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

    :root {
      --bg: #08090d;
      --surface: #0f1117;
      --surface2: #161820;
      --surface3: #1e2030;
      --border: rgba(255,255,255,0.07);
      --border-hover: rgba(255,255,255,0.14);
      --text: #e8eaf0;
      --text-muted: #7a7f96;
      --accent: #7cffa4;
      --accent2: #3de0ff;
      --accent-glow: rgba(124,255,164,0.18);
      --panel-w: 340px;
      --radius: 12px;
      --radius-sm: 8px;
      --transition: 0.18s cubic-bezier(.4,0,.2,1);
    }

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

    /* ── Layout ── */
    #app { display: flex; width: 100%; height: 100%; position: relative; }

    #preview-area {
      flex: 1;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
    }

    #canvas-wrapper {
      position: relative;
      border-radius: var(--radius);
      overflow: hidden;
      box-shadow: 0 0 80px rgba(0,0,0,0.8), 0 0 0 1px var(--border);
    }

    /* checkerboard for transparent */
    #canvas-wrapper.show-checker {
      background-image:
        linear-gradient(45deg, #1a1a2e 25%, transparent 25%),
        linear-gradient(-45deg, #1a1a2e 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #1a1a2e 75%),
        linear-gradient(-45deg, transparent 75%, #1a1a2e 75%);
      background-size: 20px 20px;
      background-position: 0 0, 0 10px, 10px -10px, -10px 0;
      background-color: #0d0d1a;
    }

    #main-canvas { display: block; }

    /* ── Panel ── */
    #panel {
      width: var(--panel-w);
      height: 100%;
      background: var(--surface);
      border-left: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      z-index: 10;
      position: relative;
    }

    #panel-header {
      padding: 20px 20px 16px;
      border-bottom: 1px solid var(--border);
      background: var(--surface2);
      flex-shrink: 0;
    }

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

    .logo-icon {
      width: 32px; height: 32px;
      border-radius: 8px;
      background: linear-gradient(135deg, #2aff80, #00e5ff);
      display: flex; align-items: center; justify-content: center;
      font-size: 16px;
      box-shadow: 0 0 20px rgba(42,255,128,0.4);
    }

    .logo h1 {
      font-size: 15px;
      font-weight: 700;
      letter-spacing: -0.02em;
      color: var(--text);
    }

    .logo p {
      font-size: 11px;
      color: var(--text-muted);
      font-weight: 400;
    }

    #panel-tabs {
      display: flex;
      gap: 2px;
      padding: 12px 16px 0;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
      background: var(--surface2);
    }

    .tab-btn {
      flex: 1;
      background: none;
      border: none;
      color: var(--text-muted);
      font-family: inherit;
      font-size: 12px;
      font-weight: 500;
      padding: 8px 4px 10px;
      cursor: pointer;
      border-bottom: 2px solid transparent;
      margin-bottom: -1px;
      transition: var(--transition);
      letter-spacing: 0.01em;
    }
    .tab-btn:hover { color: var(--text); }
    .tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

    #panel-body {
      flex: 1;
      overflow-y: auto;
      padding: 12px 16px 20px;
      scrollbar-width: thin;
      scrollbar-color: var(--surface3) transparent;
    }

    .tab-panel { display: none; }
    .tab-panel.active { display: block; }

    /* ── Section ── */
    .section {
      margin-bottom: 18px;
    }

    .section-label {
      font-size: 10px;
      font-weight: 600;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      color: var(--text-muted);
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .section-label::after {
      content: '';
      flex: 1;
      height: 1px;
      background: var(--border);
    }

    /* ── Controls ── */
    .control { margin-bottom: 12px; }

    .control-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 6px;
    }

    .control-label {
      font-size: 12px;
      font-weight: 500;
      color: var(--text);
    }

    .control-value {
      font-size: 11px;
      font-family: 'JetBrains Mono', monospace;
      color: var(--accent);
      background: rgba(124,255,164,0.08);
      padding: 2px 7px;
      border-radius: 4px;
      min-width: 44px;
      text-align: center;
    }

    .control-desc {
      font-size: 10.5px;
      color: var(--text-muted);
      margin-top: 2px;
      line-height: 1.45;
    }

    /* Slider */
    input[type="range"] {
      -webkit-appearance: none;
      width: 100%;
      height: 4px;
      border-radius: 99px;
      background: var(--surface3);
      outline: none;
      cursor: pointer;
    }
    input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 16px; height: 16px;
      border-radius: 50%;
      background: var(--accent);
      box-shadow: 0 0 10px var(--accent-glow);
      cursor: pointer;
      transition: transform 0.12s;
    }
    input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

    /* Color */
    .color-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .color-control {
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .color-control label {
      font-size: 11px;
      color: var(--text-muted);
      font-weight: 500;
    }

    .color-swatch-wrap {
      display: flex;
      align-items: center;
      gap: 6px;
      background: var(--surface3);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      padding: 5px 8px;
      cursor: pointer;
      transition: border-color var(--transition);
    }
    .color-swatch-wrap:hover { border-color: var(--border-hover); }

    .color-swatch {
      width: 18px; height: 18px;
      border-radius: 4px;
      border: 1px solid rgba(255,255,255,0.15);
      flex-shrink: 0;
    }

    .color-hex {
      font-size: 11px;
      font-family: 'JetBrains Mono', monospace;
      color: var(--text);
    }

    input[type="color"] {
      position: absolute;
      opacity: 0;
      width: 0; height: 0;
    }

    /* Checkbox toggle */
    .toggle-wrap {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 8px 10px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      cursor: pointer;
      transition: border-color var(--transition);
      margin-bottom: 10px;
    }
    .toggle-wrap:hover { border-color: var(--border-hover); }

    .toggle-label {
      font-size: 12px;
      font-weight: 500;
      color: var(--text);
    }

    .toggle-desc {
      font-size: 10.5px;
      color: var(--text-muted);
    }

    .toggle {
      width: 36px; height: 20px;
      border-radius: 99px;
      background: var(--surface3);
      border: 1px solid var(--border);
      position: relative;
      transition: background var(--transition), border-color var(--transition);
      flex-shrink: 0;
    }
    .toggle::after {
      content: '';
      position: absolute;
      left: 3px; top: 3px;
      width: 12px; height: 12px;
      border-radius: 50%;
      background: var(--text-muted);
      transition: transform var(--transition), background var(--transition);
    }
    .toggle.on { background: var(--accent); border-color: var(--accent); }
    .toggle.on::after { transform: translateX(16px); background: #fff; }

    /* Select */
    select {
      width: 100%;
      background: var(--surface3);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      color: var(--text);
      font-family: inherit;
      font-size: 12px;
      padding: 8px 10px;
      cursor: pointer;
      outline: none;
      transition: border-color var(--transition);
      appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7f96' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 10px center;
      padding-right: 28px;
    }
    select:hover, select:focus { border-color: var(--border-hover); }

    /* ── Bottom Actions ── */
    #panel-footer {
      padding: 12px 16px;
      border-top: 1px solid var(--border);
      background: var(--surface2);
      flex-shrink: 0;
    }

    .btn {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      width: 100%;
      padding: 10px 16px;
      border-radius: var(--radius-sm);
      font-family: inherit;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      border: none;
      transition: all var(--transition);
      letter-spacing: 0.01em;
    }

    .btn-primary {
      background: linear-gradient(135deg, #2aff80, #00d4ff);
      color: #080c14;
      box-shadow: 0 0 20px rgba(42,255,128,0.3);
    }
    .btn-primary:hover { box-shadow: 0 0 30px rgba(42,255,128,0.5); transform: translateY(-1px); }
    .btn-primary:active { transform: translateY(0); }
    .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

    .btn-secondary {
      background: var(--surface3);
      border: 1px solid var(--border);
      color: var(--text);
      margin-bottom: 8px;
    }
    .btn-secondary:hover { border-color: var(--border-hover); background: var(--surface2); }

    .btn-danger {
      background: rgba(255,80,80,0.12);
      border: 1px solid rgba(255,80,80,0.2);
      color: #ff8080;
      margin-bottom: 8px;
    }
    .btn-danger:hover { background: rgba(255,80,80,0.2); border-color: rgba(255,80,80,0.35); }

    .export-row {
      display: flex;
      gap: 8px;
      margin-bottom: 8px;
    }

    .export-row .btn { flex: 1; font-size: 12px; }

    /* Progress bar */
    #progress-wrap {
      display: none;
      margin-top: 10px;
    }

    #progress-wrap.visible { display: block; }

    #progress-bar-bg {
      height: 4px;
      background: var(--surface3);
      border-radius: 99px;
      overflow: hidden;
      margin-bottom: 6px;
    }

    #progress-bar-fill {
      height: 100%;
      background: linear-gradient(90deg, #2aff80, #00d4ff);
      border-radius: 99px;
      transition: width 0.1s;
    }

    #progress-text {
      font-size: 11px;
      color: var(--text-muted);
      text-align: center;
      font-family: 'JetBrains Mono', monospace;
    }

    /* ── Preview overlay ── */
    #preview-toolbar {
      position: absolute;
      top: 16px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      gap: 8px;
      z-index: 5;
      background: rgba(8,9,13,0.75);
      border: 1px solid var(--border);
      border-radius: 99px;
      padding: 6px 12px;
      backdrop-filter: blur(10px);
    }

    .toolbar-btn {
      background: none;
      border: none;
      color: var(--text-muted);
      cursor: pointer;
      font-size: 11px;
      font-family: inherit;
      font-weight: 500;
      padding: 4px 10px;
      border-radius: 99px;
      transition: var(--transition);
      display: flex;
      align-items: center;
      gap: 5px;
    }
    .toolbar-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
    .toolbar-btn.active-btn { color: var(--accent); background: rgba(124,255,164,0.1); }

    #res-label {
      font-size: 11px;
      color: var(--text-muted);
      display: flex;
      align-items: center;
      padding: 0 4px;
      font-family: 'JetBrains Mono', monospace;
    }

    /* ── Stat pills ── */
    #stats-bar {
      position: absolute;
      bottom: 16px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      gap: 8px;
      z-index: 5;
    }

    .stat-pill {
      background: rgba(8,9,13,0.75);
      border: 1px solid var(--border);
      border-radius: 99px;
      padding: 4px 12px;
      font-size: 10px;
      font-family: 'JetBrains Mono', monospace;
      color: var(--text-muted);
      backdrop-filter: blur(8px);
    }

    .stat-pill span { color: var(--accent); }

    /* ── Recording badge ── */
    #rec-badge {
      position: absolute;
      top: 16px;
      right: 20px;
      display: none;
      align-items: center;
      gap: 6px;
      background: rgba(255,60,60,0.15);
      border: 1px solid rgba(255,60,60,0.3);
      border-radius: 99px;
      padding: 5px 12px;
      font-size: 11px;
      font-weight: 600;
      color: #ff6060;
      z-index: 20;
      animation: recPulse 1.4s ease-in-out infinite;
    }
    #rec-badge.visible { display: flex; }

    .rec-dot {
      width: 7px; height: 7px;
      border-radius: 50%;
      background: #ff4444;
      animation: dotBlink 1.4s ease-in-out infinite;
    }

    @keyframes recPulse {
      0%, 100% { box-shadow: 0 0 12px rgba(255,60,60,0.2); }
      50%       { box-shadow: 0 0 24px rgba(255,60,60,0.5); }
    }
    @keyframes dotBlink {
      0%, 100% { opacity: 1; }
      50%       { opacity: 0.2; }
    }

    /* Tooltip */
    [data-tip] { position: relative; cursor: help; }
    [data-tip]:hover::after {
      content: attr(data-tip);
      position: absolute;
      bottom: calc(100% + 6px);
      left: 50%;
      transform: translateX(-50%);
      background: #1e2030;
      border: 1px solid var(--border-hover);
      color: var(--text);
      font-size: 11px;
      padding: 5px 9px;
      border-radius: 6px;
      white-space: nowrap;
      z-index: 50;
      pointer-events: none;
      box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    }

    /* Scrollbar */
    ::-webkit-scrollbar { width: 4px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 99px; }
