/* ============================================================
   Variables
   ============================================================ */
:root {
  --size: 3em;
  --marginTop: -1em;
  --leftText: 50%;

  /* UI tokens */
  --panel-radius: 14px;
  --rail-width: clamp(220px, 20vw, 300px);
  --glass-bg: rgba(17, 17, 24, 0.35);
  --glass-border: 1px solid rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 18px rgba(0, 0, 0, 0.3);
  --z-overlay: 10;
  --z-tooltip: 20;
}

/* ============================================================
   Base / Reset
   ============================================================ */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  /* prevent page scroll; canvas fills viewport */
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  color-scheme: dark;
  transform: none !important;
  /* keep fixed children pinned */
}

/* ============================================================
   Canvas (fills the viewport)
   ============================================================ */
#mainCanvas {
  outline: none !important;
  position: fixed;
  inset: 0;
  /* top/right/bottom/left: 0 */
  width: 100vw;
  height: 100svh;
  /* avoids URL bar jumps on mobile */
  overflow: hidden;
  z-index: 0;
  transform: none !important;
  /* ensure no accidental transforms cause jitter */
}

#display3DScene,
.content {
  transform: none !important;
  /* avoid creating a new containing block for fixed */
}

#display3DScene {
  width: 100%;
  height: 100%;
}

/* Optional overlay canvas (e.g., selection box) */
#overlay-canvas {
  position: fixed;
  top: 17%;
  left: 37%;
  transform: translate(-50%, -50%);
  background-color: rgba(1, 1, 1, 0.15);
  border: 2px solid black;
  pointer-events: none;
  border-radius: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  z-index: var(--z-overlay);
}

/* ============================================================
   Headline (if used)
   ============================================================ */
.headline {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  font-weight: bold;
  color: #eae6f2;
  z-index: var(--z-overlay);
}

/* ============================================================
   RIGHT HUD: carrot view + actions
   ============================================================ */
#displayHUDScene {
  position: fixed;
  top: 10px;
  right: 10px;
  width: clamp(240px, 26vw, 380px);
  max-height: 90vh;
  padding: 0;
  /* space children directly */
  background-color: transparent !important;
  /* no blue panel */
  box-shadow: none;
  border: none;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  /* prevent HUD itself from scrolling */
  transform: none !important;
}

/* Carrot (small vertical canvas) */
.carrot-view {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 3;
  /* tall rectangle */
  max-height: 60vh;
  /* never exceed 60% of screen height */
  display: block;
  border-radius: 12px;
  background-color: #0b1526;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

/* HUD Actions (Canvas | Validate | Exit) */
.hud-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 4px;
}

.hud-actions .toolBtn {
  background: transparent !important;
  color: black !important;
  border: 2px solid black !important;
  border-radius: 8px;
  width: 110px;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
  white-space: nowrap;
}

.hud-actions .toolBtn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
  border-color: #000;
}

/* Ensure Validate has no legacy background image */
#coreSampleViewExecButton {
  background: transparent !important;
  background-image: none !important;
  color: black !important;
}

/* Keep legacy tool button base for other places */
.toolBtn {
  background-color: rgb(14, 42, 69);
  border: none;
  color: rgb(239, 242, 245);
  border-radius: 8px;
  cursor: pointer;
  transition:
    filter 0.2s ease-in-out,
    transform 0.2s ease-in-out;
}

/* ============================================================
   LEFT RAIL: collapsible panels (Modeling / Deformation / Save & Load)
   ============================================================ */
#leftRail {
  position: fixed;
  top: 10px;
  left: 10px;
  width: var(--rail-width);
  max-height: 90vh;
  /* fit screen; rail scrolls if needed */
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: var(--z-overlay);
  overflow: hidden;
  /* no scrollbar visible per request */
  padding-right: 0;
  transform: none !important;
}

/* Each <details> as a modern glass card */
.panel {
  position: static;
  /* they stack and push each other */
  margin: 0;
  padding: 0;
  border: var(--glass-border);
  border-radius: var(--panel-radius);
  background: var(--glass-bg);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  /* hide internal scrollbars */
}

/* Summary header (clickable) with chip */
.panel > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #ffffff;
  cursor: pointer;
  user-select: none;
  outline: none;
}

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

/* Chip style */
.panel > summary .chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.panel > summary svg {
  width: 16px;
  height: 16px;
  opacity: 0.85;
}

/* Arrow indicator */
.panel > summary::after {
  content: '▸';
  font-size: 12px;
  opacity: 0.85;
  transition: transform 0.2s ease;
}

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

/* Panel body; shows only when open */
.panel .panel-body {
  display: none;
  padding: 12px;
}

.panel[open] .panel-body {
  display: block;
  max-height: none;
  /* no inner scrollbar */
  overflow: hidden;
  /* hide scrollbars inside */
}

/* Inside the body: compact grid of icons (your existing markup) */
.panel .panel-body > div {
  display: grid !important;
  grid-template-columns: repeat(5, 40px);
  /* dense 5-column grid */
  gap: 10px;
  align-items: center;
  justify-content: start;
}

/* Tooltip wrappers shouldn’t break the grid */
.panel .pgtooltip {
  display: inline-block !important;
  /* ensure proper box */
  position: relative !important;
}

/* Icon buttons in panels: clean/modern + SVG */
.panel .toolBtn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  /* finger friendly */
  min-height: 40px;
  /* finger friendly */
  background: none !important;
  /* remove png backgrounds */
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  color: #fff;
  filter: saturate(0.95) contrast(0.98);
  display: grid;
  place-items: center;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    filter 0.15s ease,
    opacity 0.15s ease;
}

.panel .toolBtn svg {
  width: 22px;
  height: 22px;
  opacity: 0.9;
  stroke: currentColor;
  fill: none;
  transition: opacity 0.15s ease;
}

.panel .toolBtn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  border-color: rgba(255, 255, 255, 0.32);
  filter: none;
}

.panel .toolBtn:hover svg {
  opacity: 1;
}

/* ============================================================
   Validation Panel & Icons (inline SVG version)
   ============================================================ */
#validationPanel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  /* visible by default */
  grid-auto-flow: column;
  /* always side-by-side */
  grid-auto-columns: min-content;
  align-items: center;
  column-gap: 12px;
  z-index: 2147483647;
  /* absolutely top layer */
  background: transparent;
  /* no box */
  pointer-events: none;
  /* panel ignores drags; buttons re-enable */
  backface-visibility: hidden;
}

#validateBtn,
#cancelBtn {
  pointer-events: auto;
  width: 56px;
  height: 56px;
  position: static !important;
  left: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  border: none;
  border-radius: 12px;
  background-color: rgba(20, 20, 30, 0.35);
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  color: #fff;
  cursor: pointer;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    filter 0.15s ease,
    opacity 0.15s ease;
  flex: 0 0 auto;
  transform: none !important;
}

#validateBtn svg,
#cancelBtn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  pointer-events: none;
  opacity: 0.9;
  display: block;
}

#validateBtn:hover,
#cancelBtn:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

#validateBtn:hover svg,
#cancelBtn:hover svg {
  opacity: 1;
}

/* ============================================================
   Tooltip helper (aligned beside each icon) — “chip” style
   ============================================================ */
.pgtooltip {
  position: relative;
  display: inline-block;
}

.pgtooltip .pgtooltiptext {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  z-index: var(--z-tooltip);
  left: 100%;
  top: 50%;
  transform: translate(10px, -50%);
  width: max-content;
  max-width: 220px;

  background: #0b0b12;
  color: #fff;
  text-align: left;
  border-radius: 8px;
  padding: 6px 10px;
  line-height: 1.2;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  transition: opacity 0.15s ease;
}

.pgtooltip:hover .pgtooltiptext {
  visibility: visible;
  opacity: 1;
}

/* ============================================================
   Range Inputs
   ============================================================ */
input[type='range'] {
  -webkit-appearance: none;
  width: 90%;
  background: transparent;
}

input[type='range']:focus {
  outline: none;
}

input[type='range']::-webkit-slider-runnable-track {
  width: 60%;
  height: 0.2em;
  cursor: pointer;
  background: #fff;
  border-radius: 20px;
  border: 0;
  box-sizing: border-box;
}

input[type='range']::-webkit-slider-thumb {
  height: 0.8em;
  width: 0.8em;
  border-radius: 60px;
  background: #ffffff;
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -0.3em;
}

/* ============================================================
   Non-blocking Toasts (11)
   ============================================================ */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  background: #0b0b12;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  animation: slideup 0.25s ease;
}

@keyframes slideup {
  from {
    transform: translateY(8px);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

/* ============================================================
   Accessibility & Motion Prefs (12)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Finger-friendly hit targets */
.panel .toolBtn {
  min-width: 40px;
  min-height: 40px;
}

/* Optional higher contrast if user prefers */
@media (prefers-contrast: more) {
  .panel,
  .panel .toolBtn,
  .pgtooltip .pgtooltiptext,
  .toast {
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.15),
      var(--shadow-md);
  }
}

/* ============================================================
   Responsive Tweaks
   ============================================================ */
@media (max-width: 900px) {
  :root {
    --rail-width: min(90vw, 420px);
  }

  #leftRail {
    left: 50%;
    transform: translateX(-50%);
    top: 10px;
    max-height: 54vh;
    /* leave room for right HUD */
  }

  #displayHUDScene {
    right: 10px;
    top: auto;
    bottom: 10px;
  }
}

/* --- Hide FPS (stats.js) --- */
[id*='stats'],
[class*='stats'] {
  display: none !important;
}
