/* ---------------------------------------------------------------------------
   Design tokens. Everything chrome-related pulls from these, so the museum's
   look can be retuned in one place instead of hunting hex values through the
   file. The palette is deliberately dark and low-chroma: the exhibits are the
   colourful thing on screen, the UI around them should recede.
   ------------------------------------------------------------------------ */
:root {
  --bg: #090b10;
  --panel: rgba(16, 19, 27, 0.82);
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text: #e8eaf1;
  --text-dim: #99a0b0;
  --text-faint: #6f7787;
  --accent: #4ade9b;
  --accent-deep: #1f6b47;
  --accent-glow: rgba(74, 222, 155, 0.16);
  --sidebar-w: 232px;
}

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
}

button {
  font-family: inherit;
}

/* --- Sidebar ------------------------------------------------------------ */

#sidebar {
  position: relative;
  z-index: 4;
  width: var(--sidebar-w);
  flex: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #12151d 0%, #0d1015 100%);
  border-right: 1px solid var(--line);
  box-sizing: border-box;
  transition: width 0.22s ease;
}

/* Collapsed: the rail keeps only the toggle, so the canvas gets the window.
   `width` animates and the contents are clipped rather than removed, so no
   nav state has to be torn down and rebuilt to show it again. */
body.sidebar-collapsed #sidebar {
  width: 46px;
}

body.sidebar-collapsed #scene-nav,
body.sidebar-collapsed #brand-text {
  opacity: 0;
  pointer-events: none;
}

#brand {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 12px 14px 16px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  white-space: nowrap;
}

#brand-mark {
  flex: none;
  color: var(--accent);
  font-size: 13px;
  line-height: 1;
  text-shadow: 0 0 12px var(--accent-glow);
}

#brand-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: opacity 0.15s;
}

#brand-text strong {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

#brand-text em {
  font-style: normal;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

#sidebar-toggle {
  display:none;
  flex: none;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

#scene-nav {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 12px 10px 16px;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  transition: opacity 0.15s;
}

#scene-nav::-webkit-scrollbar { width: 8px; }

#scene-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.09);
  border-radius: 4px;
}

#scene-nav::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.16); }

/* --- Top-level physics families ---------------------------------------- */

.nav-categories {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding-bottom: 14px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.nav-category {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 4px 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.nav-category .cat-icon {
  font-size: 14px;
  line-height: 1;
  opacity: 0.85;
}

.nav-category .cat-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-category:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.nav-category:active {
  transform: translateY(1px);
}

.nav-category.active {
  background: var(--accent-glow);
  border-color: rgba(74, 222, 155, 0.35);
  color: var(--accent);
}

/* --- Exhibit list ------------------------------------------------------- */

.nav-tab {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 9px 10px 9px 9px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
}

/* The id lives in its own fixed-width column so the titles line up as a
   readable list — the old flat "6.1 Real FEM Wood (experimental)" string
   made the numbers, not the names, the thing the eye landed on. */
.tab-badge {
  flex: none;
  min-width: 26px;
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  transition: color 0.13s;
}

.tab-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-tag {
  flex: none;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text-faint);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.nav-tab:hover .tab-badge {
  color: var(--text-dim);
}

.nav-tab.active {
  background: linear-gradient(90deg, var(--accent-glow), rgba(74, 222, 155, 0.03));
  color: var(--text);
  font-weight: 600;
}

/* A left rail rather than a filled block: the selection reads clearly
   without the button turning into a solid slab of colour. */
.nav-tab.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.nav-tab.active .tab-badge {
  color: var(--accent);
}

/* --- 6.x archive -------------------------------------------------------- */

.nav-archive {
  flex: none;
  margin: 6px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.015);
}

.nav-archive > summary {
  padding: 9px 11px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.nav-archive > summary::-webkit-details-marker { display: none; }

.nav-archive > summary::before {
  content: "\25B8  ";
  color: var(--text-faint);
}

.nav-archive[open] > summary::before {
  content: "\25BE  ";
}

.nav-archive > summary:hover {
  color: var(--text);
}

.nav-archive-items {
  padding: 0 5px 5px;
}

.nav-archive-items .nav-tab {
  padding: 7px 8px;
  font-size: 12px;
}

/* --- Viewport & variant bar -------------------------------------------- */

#viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
}

/* The variant bar floats over the canvas as a segmented control instead of
   spanning a full-width toolbar — with up to a dozen variants it scrolls
   horizontally rather than wrapping into a wall of buttons. */
#sub-nav {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 160px;
  z-index: 2;
  display: flex;
  gap: 3px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  overflow-x: auto;
  scrollbar-width: none;
}

#sub-nav::-webkit-scrollbar { display: none; }

#sub-nav:empty {
  display: none;
}

.sub-tab {
  flex: none;
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
}

.sub-tab:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.sub-tab.active {
  background: var(--accent-deep);
  color: #eafff2;
  font-weight: 600;
}

#reload-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 3;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#reload-btn:hover {
  background: var(--accent-glow);
  border-color: rgba(74, 222, 155, 0.4);
  color: var(--accent);
}

#renderCanvas {
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

#hud {
  position: absolute;
  top: 66px;
  left: 16px;
  max-width: 340px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

#hud h1 {
  font-size: 15px;
  margin: 0 0 6px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#hud p {
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--accent);
}

#info-panel {
  pointer-events: auto;
  margin-top: 4px;
}

#info-panel summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}

#info-panel summary:hover {
  color: var(--text);
}

#info-content {
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.5;
  color: #d5d8e0;
}

#info-content h3, #info-content h4 {
  margin: 10px 0 4px;
  color: #eafaf0;
}

#info-content h3:first-child, #info-content h4:first-child {
  margin-top: 0;
}

#info-content p {
  margin: 0 0 8px;
  color: #d5d8e0;
}

#info-content ul {
  margin: 0 0 8px;
  padding-left: 18px;
}

#info-content strong {
  color: #eafaf0;
}

#projectile-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 18px;
  padding: 12px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

#projectile-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

#projectile-controls .value {
  color: var(--text);
  font-weight: 600;
}

#projectile-controls .value input {
  width: 72px;
  padding: 2px 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background: #171b24;
  color: #f3f5f8;
  font: inherit;
  font-weight: 600;
}

#projectile-controls input[type="range"] {
  width: 140px;
}

#projectile-controls .detail {
  padding-left: 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
}

#projectile-controls .detail[hidden] {
  display: none;
}

#projectile-controls .hint {
  font-size: 10.5px;
  color: #7e8595;
}

#fem-debug-panel {
  position: absolute;
  top: 66px;
  right: 16px;
  width: 310px;
  max-height: calc(100% - 136px);
  overflow-y: auto;
  padding: 10px 14px;
  background: rgba(10, 13, 20, 0.88);
  border: 1px solid rgba(91, 199, 255, 0.35);
  border-radius: 10px;
  color: var(--text);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  font-size: 12px;
}

#dmm7-tuning-panel {
  position: absolute;
  top: 66px;
  right: 16px;
  width: 370px;
  max-height: calc(100% - 136px);
  overflow-y: auto;
  padding: 10px 14px;
  background: rgba(10, 13, 20, 0.94);
  border: 1px solid rgba(99, 220, 153, 0.42);
  border-radius: 10px;
  color: var(--text);
  pointer-events: auto;
  font-size: 12px;
}

#dmm7-tuning-panel summary {
  cursor: pointer;
  color: #8ce3ad;
  font-weight: 650;
  user-select: none;
}

.dmm7-tuning-intro,
.dmm7-tuning-tip {
  color: #aeb7c7;
  line-height: 1.35;
}

.dmm7-tuning-section {
  margin: 12px 0 5px;
  color: #eef7f1;
  font-size: 12px;
}

.dmm7-tuning-field {
  display: grid;
  grid-template-columns: minmax(118px, 0.8fr) minmax(92px, 0.55fr) 1.4fr;
  gap: 7px;
  align-items: start;
  padding: 5px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
}

.dmm7-tuning-field input {
  width: 100%;
  box-sizing: border-box;
  padding: 3px 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background: #171b24;
  color: #f2f4f7;
}

.dmm7-tuning-field input[type="checkbox"] {
  width: auto;
  justify-self: start;
}

.dmm7-tuning-actions {
  position: sticky;
  bottom: -10px;
  display: flex;
  gap: 7px;
  padding: 10px 0 2px;
  background: rgba(10, 13, 20, 0.97);
}

.dmm7-tuning-actions button {
  flex: 1;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: #285f40;
  color: white;
  cursor: pointer;
}

.dmm7-tuning-actions button:last-child {
  background: #343a48;
}

#fem-debug-panel summary {
  cursor: pointer;
  color: #79d8ff;
  font-weight: 600;
  user-select: none;
}

.fem-debug-note {
  color: #b9c2d0;
  line-height: 1.35;
}

.fem-debug-toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
}

.fem-debug-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
}

.fem-debug-benchmarks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.fem-debug-benchmarks button {
  flex: 1 1 44%;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: rgba(41, 79, 101, 0.9);
  color: #eefaff;
  cursor: pointer;
  font-size: 11px;
}

.fem-debug-metrics {
  margin: 0;
  color: #bdeeff;
  font: 11px/1.4 Consolas, monospace;
  white-space: pre-wrap;
}

/* Range thumbs/tracks pick up the museum accent instead of the browser's
   default blue — one line, supported everywhere this runs. */
input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
}

#projectile-controls label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  font-weight: 600;
}

#projectile-controls .value {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11.5px;
}

#projectile-controls .value input:focus,
.dmm7-tuning-field input:focus {
  outline: none;
  border-color: rgba(74, 222, 155, 0.55);
}

#info-panel summary,
.nav-archive > summary,
#fem-debug-panel summary,
#dmm7-tuning-panel summary {
  outline-offset: 3px;
}

.nav-tab:focus-visible,
.nav-category:focus-visible,
.sub-tab:focus-visible,
#reload-btn:focus-visible,
#sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
