:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --bg-input: #0d1117;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-subtle: rgba(56, 139, 253, 0.15);
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --danger-subtle: rgba(248, 81, 73, 0.15);
  --success: #3fb950;
  --border: #30363d;
  --border-light: #21262d;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 0 rgba(0,0,0,0.1);
  --shadow-md: 0 3px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* === GLOBAL HIDDEN FIX === */
[hidden] {
  display: none !important;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
}

/* ===================== HEADER ===================== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 4px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 10px;
  color: #2d4a7a;
  font-weight: 500;
}

.header-brand:hover .brand-sub {
  color: var(--accent);
}

/* ===================== BUTTONS ===================== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 5px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: background var(--transition);
  line-height: 20px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-large {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
}

.btn-small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 3px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition);
  line-height: 20px;
}

.btn-small:hover {
  background: var(--bg-hover);
  border-color: #8b949e;
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.4);
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 3px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition);
  line-height: 20px;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: #8b949e;
}

.btn-toggle {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 3px 12px;
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition);
  line-height: 20px;
}

.btn-toggle:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: none;
}

.btn-toggle:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.btn-toggle.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-toggle:first-child.active + .btn-toggle {
  border-left-color: var(--accent);
}

.toggle-group {
  display: inline-flex;
}

/* ===================== MAIN LAYOUT ===================== */
#app-main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* When panel is visible, switch to grid */
#app-main.has-model {
  display: grid;
  grid-template-columns: 1fr 380px;
}

/* ===================== VIEWPORT ===================== */
#viewport-container {
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

#viewport-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===================== DROP ZONE ===================== */
.drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: var(--bg-primary);
  transition: background var(--transition);
}

.drop-zone.dragging {
  background: var(--accent-subtle);
}

.drop-zone.dragging .drop-zone-border {
  border-color: var(--accent);
  background: rgba(56, 139, 253, 0.05);
}

.drop-zone.hidden {
  display: none;
}

.drop-zone-content {
  text-align: center;
  color: var(--text-secondary);
  max-width: 380px;
}

.drop-zone-border {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  transition: all 0.3s ease;
}

.drop-zone-content svg {
  margin-bottom: 20px;
  opacity: 0.4;
  color: var(--text-muted);
}

.drop-zone-content p {
  margin-bottom: 6px;
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 500;
}

.drop-zone-content #drop-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ===================== RENDER FRAME ===================== */
.render-frame {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.render-frame-border {
  width: min(90%, calc(100vh - 120px));
  aspect-ratio: 1;
  max-height: 90%;
  border: 2px dashed rgba(88, 166, 255, 0.35);
  border-radius: 2px;
  position: relative;
}

.render-frame-border::after {
  content: '';
  position: absolute;
  inset: -1px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
}

/* ===================== VIEWPORT COLUMN ===================== */
#viewport-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#viewport-column > #viewport-container {
  flex: 1;
  min-height: 0;
}

/* ===================== CAMERA PRESETS ===================== */
.camera-presets {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.preset-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}

.preset-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.preset-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: rgba(56, 139, 253, 0.3);
}

/* ===================== CONTROLS PANEL ===================== */
#controls-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ===================== PANEL SECTIONS ===================== */
.panel-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel-section > summary {
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: transparent;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color var(--transition);
}

.panel-section > summary:hover {
  color: var(--text-primary);
}

.panel-section > summary::before {
  content: '▸';
  transition: transform var(--transition);
  font-size: 10px;
  color: var(--text-muted);
}

.panel-section[open] > summary::before {
  transform: rotate(90deg);
}

.panel-section > summary::-webkit-details-marker {
  display: none;
}

.section-body {
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border-light);
}

/* ===================== FILE INFO ===================== */
.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 8px;
}

#file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* ===================== FORM ELEMENTS ===================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group > label:first-child {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

select,
.input-number {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: var(--radius);
  font-size: 13px;
  width: 100%;
  line-height: 20px;
  transition: border-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

select {
  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='%238b949e' d='M6 8.825L1.175 4h9.65L6 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

select:focus,
.input-number:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.input-number {
  width: 80px;
}

/* ===================== SLIDERS ===================== */
.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.slider-group label {
  color: var(--text-secondary);
  min-width: 56px;
  flex-shrink: 0;
  font-size: 12px;
}

.slider-group input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
  min-width: 0;
}

.slider-group span {
  min-width: 32px;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===================== CHECKBOXES ===================== */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 140px;
  overflow-y: auto;
  padding: 4px 0;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* ===================== FORM HINT ===================== */
.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: -4px;
}

/* ===================== ROW ===================== */
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===================== INFO READOUT ===================== */
.info-readout {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  text-align: center;
  border: 1px solid var(--border-light);
}

.info-readout strong {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ===================== LIGHT CONTROLS ===================== */
.light-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity var(--transition);
}

.light-controls.disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ===================== FIX BUTTONS ===================== */
.fix-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-fix {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
  line-height: 18px;
  white-space: nowrap;
}

.btn-fix:hover {
  background: var(--bg-hover);
  border-color: #8b949e;
}

.btn-fix.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

/* ===================== PROGRESS ===================== */
#progress-container {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  width: 0%;
  transition: width 0.15s ease;
  border-radius: 4px;
}

#progress-text {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===================== GENERATE SECTION ===================== */
.generate-section {
  padding: 12px;
  border: none;
  background: transparent;
  position: sticky;
  bottom: 0;
}

/* ===================== MODAL ===================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90vw;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-header .btn-icon {
  font-size: 18px;
  border: none;
  background: transparent;
  padding: 4px 8px;
  color: var(--text-muted);
}

.modal-header .btn-icon:hover {
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* ===================== RESULT ===================== */
.result-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.result-tab {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 4px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}

.result-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.result-tab.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.result-preview {
  background:
    repeating-conic-gradient(var(--bg-tertiary) 0% 25%, var(--bg-primary) 0% 50%)
    50% / 16px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.result-preview img {
  max-width: 100%;
  image-rendering: pixelated;
}

.result-info {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
  #app-main.has-model {
    grid-template-columns: 1fr;
    grid-template-rows: 50vh 1fr;
  }

  #controls-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
  border: 2px solid transparent;
  background-clip: padding-box;
}
