/* wray: sober dark "glass" theme with a muted violet accent.
 *
 * A near-black backdrop with two faint violet light pools; panels are
 * lightly frosted glass (translucent fill, backdrop blur, thin top rim).
 * Violet is used only as an accent (primary button, focus, selection).
 */

:root {
  color-scheme: dark;

  /* Backdrop */
  --bg: #0f0d16;
  --blob-1: #4a3580;
  --blob-2: #362a5c;
  --blob-3: #2b2550;

  /* Glass */
  --glass: rgb(255 255 255 / 0.045);
  --glass-strong: rgb(255 255 255 / 0.07);
  --glass-hover: rgb(255 255 255 / 0.11);
  --glass-border: rgb(255 255 255 / 0.1);
  --glass-rim: rgb(255 255 255 / 0.2);
  --glass-blur: blur(48px) saturate(160%) brightness(1.05);
  --shadow: 0 16px 40px -18px rgb(0 0 0 / 0.7);
  --inset:
    inset 0 1px 0 var(--glass-rim),
    inset 1px 0 0 rgb(255 255 255 / 0.05),
    inset 0 -1px 0 rgb(255 255 255 / 0.03);

  /* Text and accents */
  --text: #e9e6f0;
  --muted: #8f8a9e;
  --accent: #9b87d9;
  --accent-strong: #7c68c4;
  --border: rgb(255 255 255 / 0.08); /* kept for the editors' fields */
  --panel: rgb(10 9 16 / 0.38);
  --error-bg: rgb(244 63 94 / 0.16);
  --error-text: #fecdd3;

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* JSON syntax colors (tuned for a violet background) */
  --tok-key: #b8acd9;
  --tok-string: #a3c4a8;
  --tok-number: #d4b48c;
  --tok-literal: #8fb8c4;
  --tok-punct: #6b6678;
  --tok-shape: #15121e;
  --tok-shape-bg: #b8acd9;
  --tok-material: #d0a3bb;
  --tok-ref: #d0a3bb;
}

* { box-sizing: border-box; }

/* While the page loads (class removed by main.js): no transitions, and the
 * side panel is hidden until the saved tab / editing mode are restored. */
.loading *, .loading *::before, .loading *::after { transition: none !important; }
.loading .tabs, .loading .tab-panel { visibility: hidden; }
.tabs, .tab-panel { animation: appear 0.2s ease-out; }
.loading .tabs, .loading .tab-panel { animation: none; }
@keyframes appear { from { opacity: 0; } }

html, body { height: 100%; margin: 0; }

body {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 "SF Pro Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Two faint, static light pools behind the glass */
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.75;
  pointer-events: none;
}
body::before {
  width: 50vw;
  height: 50vw;
  left: -15vw;
  top: -20vw;
  background: radial-gradient(circle, var(--blob-1), transparent 70%);
}
body::after {
  width: 45vw;
  height: 45vw;
  right: -15vw;
  bottom: -22vw;
  background:
    radial-gradient(circle at 40% 40%, var(--blob-2), transparent 65%),
    radial-gradient(circle at 70% 70%, var(--blob-3), transparent 65%);
}

/* --- Glass surfaces ------------------------------------------------------ */

header,
.pane {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), var(--inset);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}

/* Specular sheen: light caught on the upper edge of the glass */
header::before,
.pane::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(165deg, rgb(255 255 255 / 0.07) 0%, rgb(255 255 255 / 0.015) 30%, transparent 55%),
    radial-gradient(120% 60% at 0% 0%, rgb(255 255 255 / 0.04), transparent 60%);
  pointer-events: none;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 8px 8px 16px;
  border-radius: var(--radius-lg);
}

h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.actions { display: flex; gap: 6px; }

/* --- Buttons: glass pills -------------------------------------------------- */

button {
  position: relative;
  font: inherit;
  font-weight: 500;
  padding: 5px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  background: var(--glass-strong);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s, border-color 0.15s;
}
button:hover:not(:disabled) {
  background: var(--glass-hover);
  border-color: rgb(255 255 255 / 0.16);
}
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Primary action: solid muted violet */
button#render {
  background: var(--accent-strong);
  border-color: transparent;
  color: #fff;
  box-shadow: none;
}
button#render:hover:not(:disabled) { background: #8a77cf; border-color: transparent; }

/* --- Layout ---------------------------------------------------------------- */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.4fr minmax(340px, 1fr);
  gap: 14px;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
  gap: 10px;
  border-radius: var(--radius-lg);
}
.pane > * { position: relative; } /* above the sheen */

/* --- Side pane with tabs: a pill nav ---------------------------------------- */

.side-pane { padding: 0; gap: 0; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 14px;
  border-bottom: 1px solid var(--glass-border);
}

.tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--muted);
  padding: 10px 8px 8px;
  margin-bottom: -1px;
}
.tabs button:hover:not(:disabled) { background: none; color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}
.tab-panel[hidden] { display: none; }

/* Inner wells (editor, lists): darker, sunken glass */
.code-editor,
.bvh-tree,
.ui-section {
  border: 1px solid rgb(255 255 255 / 0.09);
  border-radius: var(--radius);
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: none;
}

/* --- Code editor: transparent textarea over a highlighted <pre> --- */

.code-editor {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.code-editor:focus-within {
  border-color: rgb(155 135 217 / 0.5);
}

.code-editor pre,
.code-editor textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 14px;
  border: none;
  font: 13px/1.5 var(--mono);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  overflow-wrap: normal;
}

.code-editor pre { pointer-events: none; color: var(--text); overflow: hidden; }

.code-editor textarea {
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  outline: none;
}
.code-editor textarea::selection { background: rgb(155 135 217 / 0.3); color: transparent; }

.tok-key { color: var(--tok-key); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-literal { color: var(--tok-literal); }
.tok-punct { color: var(--tok-punct); }
.tok-material { color: var(--tok-material); font-weight: 600; }
.tok-ref { color: var(--tok-ref); }
.tok-label { color: var(--text); font-style: italic; }
/* Shapes stand out as a pill (background and shadow do not change the layout) */
.tok-shape {
  color: var(--tok-shape);
  background: var(--tok-shape-bg);
  border-radius: 3px;
  box-shadow: 0 0 0 2px var(--tok-shape-bg);
  font-weight: 600;
}
/* Albedo arrays: tinted with their own color, plus a solid bar on the left */
.tok-color {
  background: color-mix(in srgb, var(--c) 28%, transparent);
  box-shadow: inset 4px 0 0 var(--c);
  border-radius: 2px;
}

/* --- Visual editor --- */

/* Toolbar: editing mode + search */
.scene-toolbar { display: flex; align-items: center; gap: 8px; }

.search { position: relative; flex: 1; min-width: 0; }
.search input {
  width: 100%;
  font: inherit;
  padding: 4px 64px 4px 28px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%238f8a9e' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='4.5'/%3E%3Cpath d='M9.5 9.5 13 13'/%3E%3C/svg%3E")
      no-repeat 9px 50%,
    rgb(0 0 0 / 0.2);
  color: var(--text);
}
.search input::placeholder { color: rgb(143 138 158 / 0.8); }
.search input:focus { outline: none; border-color: rgb(155 135 217 / 0.6); }
.search input.no-match { border-color: rgb(244 114 140 / 0.5); }
.search input::-webkit-search-cancel-button { filter: grayscale(1) opacity(0.6); }
.search-count {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font: 11px var(--mono);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* Search hits in the JSON view (no padding: the overlay must stay aligned) */
mark.search-hit {
  background: rgb(155 135 217 / 0.28);
  color: inherit;
  border-radius: 2px;
}
mark.search-hit.current {
  background: rgb(155 135 217 / 0.65);
  box-shadow: 0 0 0 1px rgb(205 192 240 / 0.8);
}

.ui-empty { margin: 12px 4px; color: var(--muted); }
.code-editor[hidden], .visual-editor[hidden] { display: none; }

.visual-editor {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}

.ui-card {
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: var(--radius-sm);
  background: rgb(255 255 255 / 0.025);
  box-shadow: none;
  transition: background 0.15s;
}
.ui-card:hover { background: rgb(255 255 255 / 0.04); }

.ui-section > summary, .ui-card > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.ui-section > summary::-webkit-details-marker, .ui-card > summary::-webkit-details-marker { display: none; }
.ui-section > summary::before, .ui-card > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}
.ui-section[open] > summary::before, .ui-card[open] > summary::before { transform: rotate(90deg); }
.ui-section > summary { font-weight: 600; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.ui-card > summary { font-size: 13px; padding: 6px 10px; }

.ui-summary-text { flex: 1; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.ui-actions { display: inline-flex; gap: 4px; }

.ui-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 12px 12px;
}
.ui-section > .ui-body > .ui-card { margin: 0; }

.ui-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.ui-row > :nth-child(n + 3) { grid-column: 2; }
.ui-label { color: var(--muted); }
.ui-muted { color: var(--muted); font-weight: 400; }
.ui-auto { color: var(--muted); font-style: italic; }

.ui-number, .ui-text, .ui-select {
  font: 12px var(--mono);
  padding: 4px 8px;
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: 6px;
  background: rgb(0 0 0 / 0.2);
  color: var(--text);
  min-width: 0;
}
.ui-text, .ui-select { font-family: inherit; font-size: 13px; }
.ui-text::placeholder { color: rgb(182 169 214 / 0.6); }
.ui-select option { background: #1a1036; color: var(--text); }
.ui-number:focus, .ui-text:focus, .ui-select:focus {
  outline: none;
  border-color: rgb(155 135 217 / 0.6);
}

.ui-slider { display: grid; grid-template-columns: 1fr 72px; gap: 8px; align-items: center; }

.ui-vec3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ui-axis { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px; }
.ui-axis > span, .ui-channel > span { color: var(--muted); font: 11px var(--mono); }

.ui-color { display: grid; grid-template-columns: 30px 1fr; gap: 8px; align-items: start; }
.ui-swatch {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid rgb(255 255 255 / 0.15);
}
/* Clickable swatch: an invisible color input covers it */
.ui-swatch { position: relative; cursor: pointer; transition: transform 0.1s, border-color 0.15s; }
.ui-swatch:hover { border-color: rgb(255 255 255 / 0.4); transform: scale(1.06); }
.ui-swatch:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.ui-color-picker {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}
.ui-channels { display: flex; flex-direction: column; gap: 2px; }
.ui-channel { display: grid; grid-template-columns: 12px 1fr; align-items: center; gap: 4px; }

.ui-inline { display: inline-flex; align-items: center; gap: 6px; }
.ui-nested {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--glass-border);
}

.ui-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgb(255 255 255 / 0.2);
  flex: none;
}

.icon-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
}
.icon-btn.danger:hover:not(:disabled) {
  border-color: rgb(251 113 133 / 0.6);
  background: rgb(244 63 94 / 0.2);
  color: #fecdd3;
}

.ui-flash {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgb(251 113 133 / 0.35);
  background: rgb(76 5 25 / 0.75);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--error-text);
  font-size: 13px;
}

/* --- Sliders, checkboxes, progress: violet glass -------------------------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: none;
  cursor: pointer;
}
.ui-range { width: 100%; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.12);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.12);
}
input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--accent-strong);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  border: none;
  background: #d9d4e6;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: #d9d4e6;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.5);
}

input[type="checkbox"] { accent-color: var(--accent-strong); }

progress {
  -webkit-appearance: none;
  appearance: none;
  width: 160px;
  height: 4px;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: rgb(255 255 255 / 0.1);
}
progress::-webkit-progress-bar { background: transparent; }
progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.2s;
}
progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--accent);
}

/* --- Segmented controls ----------------------------------------------------- */

.bvh-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.bvh-toolbar > button { padding: 3px 10px; }

.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgb(0 0 0 / 0.2);
}
.segmented button {
  padding: 2px 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: none;
  box-shadow: none;
  color: var(--muted);
}
.segmented button:hover:not(:disabled) { background: rgb(255 255 255 / 0.06); border-color: transparent; color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: rgb(255 255 255 / 0.1);
  border-color: transparent;
  color: var(--text);
}

/* --- BVH view --- */

/* Both visualizations fill the same area; only one is visible */
.bvh-viz {
  flex: 0 0 45%;
  min-height: 160px;
  border-radius: var(--radius);
  border: 1px solid rgb(255 255 255 / 0.09);
  overflow: hidden;
}
.bvh-viz canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
}
.bvh-viz canvas[hidden] { display: none; }
#bvh-diagram { cursor: grab; touch-action: none; }

.bvh-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  font-size: 13px;
  color: var(--muted);
}
.bvh-controls label { display: inline-flex; align-items: center; gap: 6px; }
.bvh-controls label[hidden] { display: none; }
.bvh-controls output { font-variant-numeric: tabular-nums; min-width: 1.5ch; color: var(--text); }

.bvh-stats { margin: 0; color: var(--muted); font-size: 12px; }

.bvh-tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px;
  font: 12px/1.6 var(--mono);
}
.bvh-tree details > :not(summary) { margin-left: 16px; }
.bvh-tree summary { cursor: pointer; }
.bvh-tree .bvh-leaf { margin-left: 16px; }
.bvh-label { border-radius: 5px; padding: 0 4px; cursor: pointer; }
.bvh-label:hover { background: rgb(155 135 217 / 0.14); }
.bvh-label.selected { background: rgb(155 135 217 / 0.28); }
.bvh-label .muted { color: var(--muted); }
.swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: 1px;
}

#error,
#bvh-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgb(251 113 133 / 0.3);
  background: var(--error-bg);
  color: var(--error-text);
  font: 12px/1.4 var(--mono);
  white-space: pre-wrap;
}

/* --- Rendered image --- */

.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  width: 100%;
  height: 100%;
  object-fit: contain; /* scale the image up or down, keeping its ratio */
}
#canvas { border-radius: 6px; }

.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.status-bar span { font-variant-numeric: tabular-nums; }

/* Scrollbars that blend into the glass */
* { scrollbar-width: thin; scrollbar-color: rgb(255 255 255 / 0.15) transparent; }

@media (max-width: 800px) {
  body { overflow: auto; }
  main { grid-template-columns: 1fr; grid-template-rows: minmax(300px, 1fr) minmax(400px, 1fr); }
}
