/* Layout */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: #111;
  background: #fff;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Viewer */
.viewer {
  flex: 1;
  position: relative;
  background: #0f1115;
}

.canvas-host {
  position: absolute;
  inset: 0;
}

.viewer-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  font-size: 12px;
  color: rgba(255,255,255,0.72);
  background: rgba(0,0,0,0.35);
  padding: 8px 10px;
  border-radius: 10px;
  backdrop-filter: blur(6px);
}

/* Overlay */
.viewer-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 17, 21, 0.55);
  backdrop-filter: blur(4px);
}

.viewer-overlay.hidden { display: none; }

.overlay-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(20, 24, 31, 0.92);
  color: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
  max-width: 420px;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 3px solid rgba(255,255,255,0.22);
  border-top-color: rgba(255,255,255,0.9);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.overlay-title { font-weight: 650; }
.overlay-subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }

/* Panel */
.panel {
  width: 25vw;
  max-width: 440px;
  min-width: 320px;
  border-left: 1px solid #e7e7e7;
  background: #fafafa;
  overflow: auto;
}

.panel-header {
  padding: 16px 16px 10px 16px;
  border-bottom: 1px solid #e7e7e7;
  background: #fff;
}

.panel-header h1 {
  font-size: 18px;
  margin: 0 0 6px 0;
}

.panel-subtitle {
  margin: 0;
  color: #444;
  font-size: 13px;
}

.params { padding: 16px; }

.section { margin-bottom: 16px; }
.section h2 {
  font-size: 14px;
  margin: 0 0 10px 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #333;
}

.subsection h3 {
  font-size: 13px;
  margin: 14px 0 8px 0;
  color: #222;
}

.field { margin-bottom: 12px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="number"] {
  width: 100%;
  border: 1px solid #d8d8d8;
  border-radius: 10px;
  padding: 10px 10px;
  background: #fff;
  font-size: 14px;
  outline: none;
}

input[type="color"]{
  width: 100%;
  height: 42px;
  border: 1px solid #d8d8d8;
  border-radius: 10px;
  padding: 4px;
  background: #fff;
}

select {
  width: 100%;
  border: 1px solid #d8d8d8;
  border-radius: 10px;
  padding: 10px 10px;
  background: #fff;
  font-size: 14px;
  outline: none;
}

.hidden { display: none !important; }

.preset-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}
.preset-preview .swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #444;
}
.preset-preview .swatch-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid #d0d0d0;
  background: transparent;
}

input:disabled, select:disabled, textarea:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.help { font-size: 12px; color: #555; margin-top: 5px; line-height: 1.35; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.checkbox { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.checkbox input { transform: scale(1.05); }

details#advanced {
  border: 1px solid #e2e2e2;
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
}

details#advanced summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.summary-hint { font-weight: 500; font-size: 12px; color: #555; }
.details-body { padding-top: 10px; }

.computed {
  border: 1px dashed #d7d7d7;
  border-radius: 12px;
  padding: 10px 10px;
  background: #fbfbfb;
  margin-top: 10px;
}
.computed-title { font-size: 12px; font-weight: 700; color: #333; margin-bottom: 6px; }
.computed-body { font-size: 12px; color: #333; display: grid; gap: 4px; }

.status {
  font-size: 13px;
  color: #222;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 12px;
  padding: 10px 12px;
}

.panel-footer {
  position: sticky;
  bottom: 0;
  background: #fafafa;
  padding: 12px 0 4px 0;
  border-top: 1px solid #e7e7e7;
}

.panel-footer .btn + .btn { margin-top: 8px; }

.btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 12px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.btn.primary { background: #111; color: #fff; }
.btn.danger { background: #b42318; color: #fff; }

.btn.secondary { background: #fff; color: #111; border: 1px solid #d0d0d0; }

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

.footer-note {
  margin-top: 8px;
  font-size: 12px;
  color: #555;
  line-height: 1.35;
}

.panel-footer-small {
  padding: 0 16px 16px 16px;
  color: #444;
}

.panel-footer-small summary { cursor: pointer; font-weight: 650; }
.small { font-size: 12px; line-height: 1.4; }

/* Responsive */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .panel {
    width: 100%;
    max-width: none;
    min-width: 0;
    border-left: 0;
    border-top: 1px solid #e7e7e7;
    height: 45vh;
  }
  .viewer { height: 55vh; }
  .grid-2 { grid-template-columns: 1fr; }
}