:root {
  --bg: #030712;
  --panel: #0b1120;
  --panel-border: #1f2937;
  --editor-bg: #0d1117;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --accent: #6366f1;
  --error-bg: #2a0f12;
  --error-border: #7f1d1d;
  --error-text: #fca5a5;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Adapts properly to mobile browser viewports */
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
  flex-shrink: 0;
  gap: 12px;
}
#header .title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
#header .title .name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#header .title .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  box-shadow: 0 0 6px #22c55e;
  flex-shrink: 0;
}
#header .title .dot.dirty {
  background: #f59e0b;
  box-shadow: 0 0 6px #f59e0b;
}
#header .status {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
#header .status.error { color: var(--error-text); }
#header .actions { 
  display: flex; 
  gap: 8px; 
  flex-shrink: 0; 
}
#header button {
  background: var(--editor-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
#header button:hover { background: #161b22; border-color: #374151; }
#header button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
#header button.primary:hover { background: #4f46e5; }

/* Main split */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#editor-pane {
  width: 42%;
  min-width: 260px;
  max-width: 75%;
  display: flex;
  flex-direction: column;
  background: var(--editor-bg);
  border-right: 1px solid var(--panel-border);
}
#editor-pane .pane-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 8px 14px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}
#codeWrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#lineNumbers {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 42px;
  background: #090d13;
  color: #4b5563;
  font: 12.5px/1.55 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  text-align: right;
  padding: 12px 8px 12px 0;
  overflow: hidden;
  user-select: none;
  white-space: pre;
}
#code {
  position: absolute;
  left: 42px;
  right: 0;
  top: 0;
  bottom: 0;
  background: transparent;
  color: #d1d5db;
  border: none;
  outline: none;
  resize: none;
  font: 12.5px/1.55 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  padding: 12px 14px;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

#resizer {
  width: 5px;
  cursor: col-resize;
  background: var(--panel-border);
  flex-shrink: 0;
  touch-action: none;
}
#resizer:hover, #resizer.active { background: var(--accent); }

/* Preview */
#preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
#preview-pane .pane-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 8px 14px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
#zoomControls { display: flex; gap: 6px; }
#zoomControls button {
  background: var(--editor-bg);
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  width: 22px;
  height: 22px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
#zoomControls button:hover { color: var(--text); border-color: #374151; }

#canvas {
  flex: 1;
  overflow: hidden;
  cursor: grab;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#canvas.grabbing { cursor: grabbing; }
#stage { transform-origin: center center; }

#errorBox {
  display: none;
  margin: 14px;
  padding: 12px 14px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 8px;
  color: var(--error-text);
  font: 12.5px/1.5 'SFMono-Regular', Consolas, monospace;
  white-space: pre-wrap;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
}

/* Responsive Media Queries */
@media (max-width: 768px) {
  #header {
    flex-direction: column;
    align-items: stretch;
    padding: 8px 12px;
  }
  
  #header .actions {
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  #main {
    flex-direction: column;
  }

  #editor-pane {
    width: 100% !important;
    height: 45%;
    min-width: 0;
    max-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }

  #resizer {
    width: 100%;
    height: 8px;
    cursor: row-resize;
  }

  #preview-pane {
    height: 55%;
  }
}
