/* Panoveil — darkroom chrome, safelight amber */

:root {
  --void: #0b0b0e;          /* canvas bed */
  --chrome: #141419;        /* app chrome */
  --panel: #1a1a21;         /* raised surfaces */
  --line: #26262e;
  --line-strong: #34343e;
  --ink: #eae8e3;
  --ink-dim: #8d8b98;
  --ink-faint: #5a5864;
  --amber: #ffab2e;         /* safelight */
  --amber-btn: #ffab2e;     /* primary button bg — same in both themes */
  --amber-deep: #d98a12;
  --danger: #ff6b5c;
  --card-veil: rgba(20, 20, 25, 0.6);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.5);
  --font-ui: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --rad: 10px;
  --rad-s: 6px;
  --topbar-h: 52px;
  --statusbar-h: 42px;
}

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

[hidden] { display: none !important; }

/* light theme — same structure, paper chrome, amber deepened for contrast */
body.theme-light {
  --void: #dedcd6;
  --chrome: #f6f5f2;
  --panel: #ffffff;
  --line: #e4e2dc;
  --line-strong: #d1cfc8;
  --ink: #211f28;
  --ink-dim: #6c6a76;
  --ink-faint: #9d9ba6;
  --amber: #b57300;
  --danger: #d5473a;
  --card-veil: rgba(255, 255, 255, 0.72);
  --shadow-pop: 0 10px 30px rgba(30, 28, 24, 0.18);
}

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--chrome);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:disabled { opacity: 0.35; cursor: default; }

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 4px; }

svg { display: block; }
.icon-btn svg, .tool-btn svg, .primary-btn svg, .row-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- top bar ---------- */

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--chrome);
  z-index: 30;
}

.brand {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  user-select: none;
}
.brand b { color: var(--amber); font-weight: 700; }
.brand .ver {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-faint);
  margin-left: 8px;
  letter-spacing: 0.08em;
  vertical-align: 2px;
}

.top-actions { display: flex; align-items: center; gap: 8px; }

.file-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-dim);
  margin-right: 6px;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--rad-s);
  color: var(--ink-dim);
}
.icon-btn:hover:not(:disabled) { background: var(--panel); color: var(--ink); }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.small svg { width: 14px; height: 14px; }

.ghost-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--rad-s);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}
.ghost-btn:hover { border-color: var(--ink-faint); background: var(--panel); }

.primary-btn {
  height: 34px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--amber-btn);
  color: #17130a;
  border-radius: var(--rad-s);
  font-size: 13.5px;
  font-weight: 600;
}
.primary-btn svg { width: 16px; height: 16px; stroke-width: 2; }
.primary-btn:hover:not(:disabled) { background: #ffbc55; }

.export-wrap { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--rad-s);
  padding: 5px;
  box-shadow: var(--shadow-pop);
  z-index: 40;
}
.menu button {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  padding: 9px 11px;
  border-radius: 4px;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
}
.menu button span { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-dim); }
.menu button:hover { background: var(--line); }

.panel-toggle { display: none; }

/* ---------- workspace ---------- */

.workspace { flex: 1; display: flex; min-height: 0; }

.toolbar {
  flex: 0 0 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  border-right: 1px solid var(--line);
  background: var(--chrome);
  z-index: 20;
}

.tool-btn {
  position: relative;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--ink-dim);
}
.tool-btn:hover { background: var(--panel); color: var(--ink); }
.tool-btn.is-active { background: var(--line); color: var(--amber); }
.tool-btn.is-active::before {
  content: '';
  position: absolute;
  left: -6px; top: 10px; bottom: 10px;
  width: 2px;
  border-radius: 2px;
  background: var(--amber);
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  background: var(--void);
  overflow: hidden;
  touch-action: none;
}
.stage.is-panning { cursor: grab; }
.stage.is-panning:active { cursor: grabbing; }
.stage.is-cross { cursor: crosshair; }

#glCanvas, #previewCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#previewCanvas { pointer-events: none; }

/* ---------- empty state ---------- */

.dropzone {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 10;
}

.drop-card {
  max-width: 480px;
  text-align: center;
  padding: 52px 44px 40px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: var(--card-veil);
}

/* theme toggle shows the theme you'd switch TO */
.ico-moon { display: none; }
body.theme-light .ico-sun { display: none; }
body.theme-light .ico-moon { display: block; }

.drop-globe {
  width: 84px; height: 84px;
  margin: 0 auto 26px;
  fill: none;
  stroke: var(--ink-faint);
  stroke-width: 1.4;
}
.drop-globe .arc { stroke: var(--amber); stroke-width: 2.4; stroke-linecap: round; }

.drop-card h1 {
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.drop-card p {
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-dim);
  margin-bottom: 26px;
}
.drop-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.drop-card .primary-btn { height: 40px; padding: 0 22px; font-size: 14px; }
.drop-card .ghost-btn { height: 40px; padding: 0 18px; font-size: 14px; }
.drop-hint {
  font-family: var(--font-mono);
  font-size: 10.5px !important;
  letter-spacing: 0.06em;
  color: var(--ink-faint) !important;
  margin: 22px 0 0 !important;
}

.drag-glow {
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--amber);
  border-radius: 12px;
  background: rgba(255, 171, 46, 0.06);
  pointer-events: none;
  z-index: 15;
}

/* ---------- right panel ---------- */

.panel {
  flex: 0 0 288px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--chrome);
  z-index: 20;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.props {
  flex: 0 0 auto;
  padding: 16px 16px 18px;
  border-bottom: 1px solid var(--line);
}
.props-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  min-height: 26px;
}

.hint-text {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-dim);
}
.hint-text b { color: var(--ink); font-weight: 500; }

.field { margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
.field-label output {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
}

input[type="range"] { width: 100%; accent-color: var(--amber); height: 22px; }
input[type="checkbox"] { accent-color: var(--amber); width: 15px; height: 15px; }

input[type="text"].text-field {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--rad-s);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13.5px;
}
input[type="text"].text-field:focus { outline: none; border-color: var(--amber); }

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.color-row { display: flex; align-items: center; gap: 10px; }
input[type="color"] {
  width: 34px; height: 28px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--rad-s);
  background: var(--panel);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }
.color-val { font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); }

.seg {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--rad-s);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  height: 26px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-dim);
}
.seg button.is-on { background: var(--line-strong); color: var(--amber); }

.danger-btn {
  width: 100%;
  height: 32px;
  margin-top: 4px;
  border: 1px solid rgba(255, 107, 92, 0.35);
  border-radius: var(--rad-s);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}
.danger-btn:hover { background: rgba(255, 107, 92, 0.1); }

/* objects list */

.objects {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 10px 10px 16px;
}
.objects .eyebrow { margin-bottom: 10px; }

#objList {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding-right: 6px;
}
#objList:empty { flex: 0 0 0; }
#objList::-webkit-scrollbar { width: 8px; }
#objList::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

.obj-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 10px;
  border-radius: var(--rad-s);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.obj-row:hover { background: var(--panel); }
.obj-row.is-selected { background: var(--panel); border-left-color: var(--amber); }

.obj-idx {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  width: 18px;
  flex: 0 0 auto;
}
.obj-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.obj-swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  flex: 0 0 auto;
}

.row-btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 4px;
  color: var(--ink-faint);
  flex: 0 0 auto;
}
.row-btn svg { width: 14px; height: 14px; }
.row-btn:hover { color: var(--ink); background: var(--line); }
.row-btn.del:hover { color: var(--danger); }

.obj-empty {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-faint);
  padding-right: 8px;
}

/* ---------- status bar ---------- */

.statusbar {
  height: var(--statusbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  background: var(--chrome);
  z-index: 30;
}

.readouts {
  display: flex;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  white-space: nowrap;
}
.readouts b { font-weight: 500; color: var(--ink); min-width: 52px; display: inline-block; }

#compass { flex: 1; height: 30px; min-width: 0; }

.status-right { flex: 0 0 auto; display: flex; gap: 8px; }

a.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  line-height: 24px;
}
.mini-btn.about svg {
  width: 13px; height: 13px;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.mini-btn.about:hover { color: var(--amber); border-color: var(--amber); }

.mini-btn {
  height: 26px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
}
.mini-btn:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  left: 66px;
  bottom: calc(var(--statusbar-h) + 12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}
.toast {
  max-width: 340px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--amber);
  border-radius: var(--rad-s);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast.is-in { opacity: 1; transform: none; }
.toast.is-error { border-left-color: var(--danger); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .panel {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: var(--statusbar-h);
    width: 288px;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    box-shadow: -12px 0 32px rgba(0,0,0,0.4);
  }
  body.panel-open .panel { transform: none; }
  .panel-toggle { display: grid; }
  .file-meta { display: none; }
}

@media (max-width: 640px) {
  #compass { display: none; }
  .readouts span:nth-child(3) { display: none; }
  .ghost-btn { padding: 0 10px; font-size: 12.5px; }
  .drop-card { padding: 36px 22px 30px; }
  .drop-card h1 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .panel { transition: none; }
}
