  @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;600;700&family=Syne:wght@400;700;800&display=swap');

  :root {
    --bg: #0a0a0f;
    --surface: #111118;
    --surface2: #1a1a24;
    --border: #2a2a3a;
    --accent: #901d97;
    --accent2: #ff6b35;
    --accent3: #a855f7;
    --text: #e8e8f0;
    --muted: #6b6b8a;
    --green: #00ff88;
  }

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

  body {
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
  }

  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(rgba(144,29,151,0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(144,29,151,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
  }

  .app {
    --right-panel-width: 50vw;
    --splitter-width: 2px;
    display: grid;
    grid-template-columns: minmax(420px, 1fr) var(--splitter-width) minmax(360px, var(--right-panel-width));
    grid-template-rows: 60px 1fr;
    height: 100vh;
    position: relative;
    z-index: 1;
  }

  .splitter {
    grid-column: 2;
    grid-row: 2;
    cursor: col-resize;
    position: relative;
    background: transparent;
    user-select: none;
    touch-action: none;
  }

  .splitter::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    height: 100%;
    background: var(--border);
    transition: background 0.15s;
  }

  .splitter:hover::before,
  .splitter.dragging::before {
    background: var(--accent);
  }

  /* HEADER */
  header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(10,10,15,0.8);
    backdrop-filter: blur(12px);
    gap: 16px;
  }

  .logo-link {
    display: inline-flex;
    align-items: center;
  }

  .logo {
    display: block;
    width: auto;
    height: 34px;
    filter: none;
  }

  .header-right {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .scene-select {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 3px;
    padding: 6px 8px;
    min-width: 180px;
    outline: none;
  }

  .scene-select:focus {
    border-color: var(--accent);
  }

  .wasm-status {
    font-size: 10px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
  .wasm-status .dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--muted);
  }
  .wasm-status.ready .dot { background: var(--green); }
  .wasm-status.error .dot { background: #ff4444; }

  .btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    padding: 6px 14px;
    border-radius: 3px;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
  }

  .btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
  }
  .btn-ghost:hover { color: var(--text); border-color: var(--accent); }

  .btn-primary {
    background: var(--accent);
    color: #000;
  }
  .btn-primary:hover { background: #a739ad; box-shadow: 0 0 20px rgba(144,29,151,0.4); }
  .btn-primary:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; box-shadow: none; }

  .btn-render {
    background: var(--green);
    color: #000;
    font-weight: 700;
  }
  .btn-render:hover { box-shadow: 0 0 20px rgba(0,255,136,0.4); }
  .btn-render:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; box-shadow: none; }

  /* SCENE PANEL (left) */
  .scene-panel {
    grid-column: 1;
    grid-row: 2;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .scene-panel::-webkit-scrollbar { width: 4px; }
  .scene-panel::-webkit-scrollbar-track { background: transparent; }
  .scene-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  .section-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--muted);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }

  .essentials-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  /* OBJECT CARDS */
  .object-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.2s;
  }
  .object-card:not(.ambient-card):not(.camera-card):not(.light-card):hover { border-color: rgba(144,29,151,0.3); }
  .object-card.camera-card { border-left: 3px solid #888888; }
  .object-card.light-card { border-left: 3px solid #ffcc00; }
  .object-card.sphere-card { border-left: 3px solid #22d3ee; }
  .object-card.plane-card { border-left: 3px solid #3b82f6; }
  .object-card.cylinder-card { border-left: 3px solid var(--accent2); }

  .card-header {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    gap: 10px;
    user-select: none;
  }

  .card-icon { font-size: 14px; width: 24px; text-align: center; }
  .card-title { font-size: 12px; font-weight: 600; flex: 1; }
  .card-type { font-size: 10px; color: var(--muted); }

  .card-delete {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 2px;
    transition: all 0.15s;
    line-height: 1;
  }
  .card-delete:hover { color: #ff4444; background: rgba(255,68,68,0.1); }

  .card-body {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    display: grid;
    gap: 10px;
  }

  .field-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    align-items: center;
    gap: 8px;
  }

  .field-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .field-inputs { display: flex; gap: 4px; }

  input[type="number"], input[type="text"], input[type="range"] {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 2px;
    padding: 4px 6px;
    width: 100%;
    transition: border-color 0.15s;
    outline: none;
  }
  input[type="number"]:focus, input[type="text"]:focus { border-color: var(--accent); }

  input[type="range"] {
    padding: 0; height: 4px; cursor: pointer; accent-color: var(--accent);
  }

  .xyz-group { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }

  .xyz-input { position: relative; }
  .xyz-input::before {
    content: attr(data-axis);
    position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
    font-size: 9px; font-weight: 700; color: var(--muted);
    pointer-events: none; z-index: 1;
  }
  .xyz-input[data-axis="x"]::before { color: #ff6b6b; }
  .xyz-input[data-axis="y"]::before { color: #6bff88; }
  .xyz-input[data-axis="z"]::before { color: #b86bcf; }
  .xyz-input input { padding-left: 14px; }

  .color-row { display: flex; gap: 6px; align-items: center; }
  input[type="color"] {
    width: 32px; height: 26px; border: 1px solid var(--border);
    border-radius: 2px; cursor: pointer; background: none; padding: 1px;
  }
  .color-rgb { flex: 1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }

  .add-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

  .btn-add {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; padding: 8px 10px; border-radius: 3px;
    cursor: pointer; border: 1px solid var(--border);
    background: rgba(255,255,255,0.03); color: var(--text); transition: all 0.2s;
    text-align: left; display: flex; align-items: center; gap: 6px;
  }
  .btn-add.sphere { border-color: rgba(34,211,238,0.4); color: #22d3ee; background: rgba(34,211,238,0.08); }
  .btn-add.sphere:hover { border-color: #22d3ee; background: rgba(34,211,238,0.15); box-shadow: 0 0 12px rgba(34,211,238,0.2); }
  .btn-add.plane { border-color: rgba(59,130,246,0.4); color: #3b82f6; background: rgba(59,130,246,0.08); }
  .btn-add.plane:hover { border-color: #3b82f6; background: rgba(59,130,246,0.15); box-shadow: 0 0 12px rgba(59,130,246,0.2); }
  .btn-add.cylinder { border-color: rgba(255,107,53,0.4); color: var(--accent2); background: rgba(255,107,53,0.08); }
  .btn-add.cylinder:hover { border-color: var(--accent2); background: rgba(255,107,53,0.15); box-shadow: 0 0 12px rgba(255,107,53,0.2); }
  .btn-add.light { border-color: rgba(255,204,0,0.4); color: #ffcc00; background: rgba(255,204,0,0.08); }
  .btn-add.light:hover { border-color: #ffcc00; background: rgba(255,204,0,0.15); box-shadow: 0 0 12px rgba(255,204,0,0.2); }

  /* OUTPUT PANEL (right) */
  .output-panel {
    grid-column: 3;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    background: var(--surface);
  }

  .output-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
  }

  .output-tab {
    flex: 1;
    padding: 10px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
  }
  .output-tab:hover { color: var(--text); }
  .output-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

  .tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; }
  .tab-content.active { display: flex; }

  /* RT CODE TAB */
  .output-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
  }

  .output-title {
    font-size: 11px; text-transform: uppercase;
    letter-spacing: 1px; color: var(--muted); flex: 1;
  }

  .live-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--green); animation: pulse 2s infinite;
  }
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

  .output-code {
    flex: 1; overflow-y: auto; padding: 16px;
    font-size: 11px; line-height: 1.7; white-space: pre; color: #c6a8ca;
    width: 100%; margin: 0; border: none; resize: none; outline: none;
    background: #121218; font-family: var(--mono);
  }
  .output-code::-webkit-scrollbar { width: 4px; }
  .output-code::-webkit-scrollbar-thumb { background: var(--border); }

  .rt-comment { color: var(--muted); }
  .rt-keyword { color: var(--accent); font-weight: 600; }
  .rt-number { color: #ffcc00; }
  .rt-color { color: var(--accent2); }

  .output-actions {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
  }

  /* RENDER TAB */
  .render-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    gap: 16px;
    overflow: auto;
  }

  .render-canvas-wrapper {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
  }

  #renderCanvas {
    display: block;
    max-width: 100%;
    height: auto;
    image-rendering: auto;
  }

  .render-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10;
  }
  .render-overlay.hidden { display: none; }

  .render-spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .render-overlay-text {
    font-size: 12px; color: var(--accent);
  }

  .render-info {
    font-size: 10px;
    color: var(--muted);
    text-align: center;
  }

  .render-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
  }
  .render-empty .icon { font-size: 36px; }

  /* Notification */
  .toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--surface2); border: 1px solid var(--accent);
    color: var(--accent); padding: 10px 16px; border-radius: 4px;
    font-size: 11px; opacity: 0; transform: translateY(8px);
    transition: all 0.3s; z-index: 100;
  }
  .toast.show { opacity: 1; transform: translateY(0); }

  .empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 32px; color: var(--muted);
    font-size: 11px; text-align: center; gap: 8px;
    border: 1px dashed var(--border); border-radius: 4px;
  }
  .empty-state .icon { font-size: 28px; margin-bottom: 4px; }

  .range-row { display: flex; align-items: center; gap: 8px; }
  .range-val { font-size: 11px; color: var(--accent); min-width: 36px; text-align: right; }

  .resolution-card {
    background: var(--panel-bg, var(--surface));
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
  }

  .resolution-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }

  .resolution-row .field-row {
    grid-template-columns: auto 1fr;
  }

  .resolution-input {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--input-bg, var(--surface2));
    color: var(--text);
  }

  .ambient-card { border-left: 3px solid #ffffff; }

  .object-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .empty-state-subtext { color: #444; }
  .btn-copy-compact { padding: 4px 10px; font-size: 10px; }
  .hidden-file-input { display: none; }
  .flex-fill { flex: 1; }
  .render-dimensions { font-size: 10px; color: #444; }
  .render-area { display: none; width: 100%; text-align: center; }
  .render-canvas-inline { display: inline-block; }

  kbd {
    background-color: #333; border-radius: 3px; border: 1px solid #666;
    box-shadow: 0 1px 0 #666, 0 1px 0 1px rgba(255,255,255,0.1);
    color: #fff; display: inline-block; font-size: 1em;
    line-height: 1.4; padding: 2px 6px; margin: 0 2px; white-space: nowrap;
  }

  /* TUTORIAL */
  .tutorial-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
  }
  .tutorial-overlay.active { display: block; }

  .tutorial-mode .scene-panel,
  .tutorial-mode .output-panel,
  .tutorial-mode .tab-content {
    overflow: visible !important;
  }

  .tutorial-backdrop {
    position: fixed;
    z-index: 1000;
    border-radius: 8px;
    outline: 3px solid var(--accent);
    box-shadow:
      0 0 0 4px rgba(144,29,151,0.45),
      0 0 0 9999px rgba(0,0,0,0.75),
      0 0 24px rgba(144,29,151,0.32),
      0 12px 28px rgba(0,0,0,0.35);
    pointer-events: none;
    transition: left 0.15s ease-out, top 0.15s ease-out, width 0.15s ease-out, height 0.15s ease-out;
    will-change: left, top, width, height;
    display: none;
  }

  .tutorial-highlight {
    position: relative;
    z-index: 1001;
    border-radius: 6px;
    filter: saturate(1.08) brightness(1.05);
    transform: translateZ(0);
    transition: filter 0.2s ease;
    pointer-events: auto;
  }

  .tutorial-tooltip {
    position: fixed;
    z-index: 1002;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 20px;
    max-width: 340px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 20px rgba(144,29,151,0.2);
    pointer-events: auto;
    transition: left 0.15s ease-out, top 0.15s ease-out;
    will-change: left, top, transform, opacity;
  }

  .tutorial-step-indicator {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
  }

  .tutorial-step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s;
  }
  .tutorial-step-dot.active { background: var(--accent); }
  .tutorial-step-dot.done { background: var(--muted); }

  .tutorial-title {
    font-family: 'Syne', sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
  }

  .tutorial-text {
    font-size: 12px;
    line-height: 1.6;
    color: var(--muted);
    margin-bottom: 16px;
  }

  .tutorial-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .tutorial-nav {
    display: flex;
    gap: 8px;
  }

  .tutorial-skip {
    font-size: 10px;
    padding: 4px 10px;
  }

  .tutorial-next {
    font-size: 11px;
    padding: 6px 18px;
  }

  @media (max-width: 1100px) {
    .app {
      grid-template-columns: 1fr;
      grid-template-rows: 60px auto auto;
      height: auto;
      min-height: 100vh;
    }

    .splitter {
      display: none;
    }

    .scene-panel,
    .output-panel {
      min-height: 50vh;
    }
  }
