html,
body {
  color-scheme: dark;
  --brand-color: #facc15;
  --bg-deep: #070b14;
  --panel-bg: rgba(11, 17, 32, 0.84);
  --panel-border: rgba(148, 163, 184, 0.22);
  --panel-highlight: rgba(250, 204, 21, 0.45);
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-dim: #94a3b8;
  --royal-blue: #1d4ed8;
  --royal-cyan: #38bdf8;
  --gold-soft: #fde047;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  accent-color: var(--brand-color);
  -webkit-font-smoothing: antialiased;
}

.visually-hidden-skip {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 1000;
  background: var(--brand-color);
  color: #0f172a;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
}

.visually-hidden-skip:focus {
  left: 12px;
}

/* Main Full-Viewport Shell */
.castle-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}

.sibling-bar {
  position: relative;
  z-index: 35;
  background: #0f172a;
  border-bottom: 1px solid #334155;
  padding: 7px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
}

.sibling-bar-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.sibling-bar a {
  color: #38bdf8;
  text-decoration: none;
  background: #1e293b;
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 4px 9px;
  border-radius: 6px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.sibling-bar a:hover {
  background: #334155;
  color: #fde047;
  border-color: rgba(250, 204, 21, 0.55);
}

.sibling-bar a.brand {
  color: #fde047;
  background: transparent;
  border-color: transparent;
  font-weight: 800;
  font-size: 13px;
  padding-left: 0;
}

.search-box-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-input:focus-visible {
  outline: 2px solid var(--brand-color);
  outline-offset: 1px;
  border-color: var(--brand-color);
}

.citation-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid rgba(250, 204, 21, 0.42);
  color: #fde047;
  font-size: 11px;
  font-weight: 600;
}

.provenance-pill {
  font-size: 11px;
  color: #94a3b8;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  padding-top: 6px;
  margin-top: 4px;
}

/* Top Bar */
.top-bar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(8, 13, 25, 0.9);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  flex-wrap: wrap;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.crest-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 6px;
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8);
  border: 1px solid rgba(250, 204, 21, 0.55);
  color: var(--gold-soft);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.brand-titles h1 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-group-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 8px;
}

.control-group-inline label,
.inline-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.1s ease;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: rgba(250, 204, 21, 0.55);
}

.btn:focus-visible {
  outline: 2px solid var(--brand-color);
  outline-offset: 2px;
}

.btn.active,
.btn[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.24), rgba(234, 179, 8, 0.16));
  border-color: var(--brand-color);
  color: var(--gold-soft);
}

.btn-gold {
  background: linear-gradient(135deg, #ca8a04, #eab308);
  border-color: #fde047;
  color: #0f172a;
  font-weight: 700;
}

.btn-gold:hover {
  background: linear-gradient(135deg, #eab308, #fde047);
  color: #0f172a;
}

.btn-mini {
  padding: 4px 8px;
  font-size: 12px;
}

/* Center Stage & WebGL Viewport */
.workspace-middle {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.viewport-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  content-visibility: auto;
  contain-intrinsic-size: auto none auto 640px;
}

#webgl-canvas-container {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#webgl-canvas-container:active {
  cursor: grabbing;
}

/* Floating Sidebars inside Workspace */
.hud-sidebar-left {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: 318px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.hud-sidebar-right {
  position: absolute;
  top: 12px;
  right: 12px;
  max-height: calc(100% - 24px);
  width: 312px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.castle-shell.zen-mode .hud-sidebar-left {
  transform: translateX(-345px);
  opacity: 0;
  pointer-events: none;
}

.castle-shell.zen-mode .hud-sidebar-right {
  transform: translateX(345px);
  opacity: 0;
  pointer-events: none;
}

.section-heading {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gold-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.window-list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-right: 4px;
}

.window-card {
  text-align: left;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: var(--text-main);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.window-card:hover {
  background: rgba(30, 41, 59, 0.92);
  border-color: rgba(250, 204, 21, 0.55);
}

.window-card.active {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.18), rgba(30, 58, 138, 0.45));
  border-color: var(--brand-color);
}

.window-card-wing {
  font-size: 12px;
  font-weight: 700;
  color: var(--royal-cyan);
}

.window-card-title {
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
  color: var(--text-main);
}

.window-card-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 3px;
}

/* Right Sidebar Inspector Card */
.inspector-card {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 9px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.inspector-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: var(--royal-cyan);
}

.inspector-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--gold-soft);
  line-height: 1.3;
}

.inspector-body {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.inspector-note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  padding-top: 6px;
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}

/* Floating Center-Top Hint & Window Peering HUD */
.floating-center-pill {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(8, 13, 25, 0.84);
  border: 1px solid rgba(250, 204, 21, 0.4);
  backdrop-filter: blur(10px);
  font-size: 12px;
  color: var(--text-muted);
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Bottom 3-Axis Rotation & Zoom Control Deck */
.bottom-deck {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, minmax(190px, 1fr)) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 18px;
  background: rgba(8, 13, 25, 0.92);
  border-top: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
}

.axis-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 9px;
  padding: 7px 10px;
}

.axis-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
}

.axis-val {
  color: var(--gold-soft);
  font-variant-numeric: tabular-nums;
}

.axis-slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.axis-slider-row input[type="range"] {
  flex: 1;
  min-width: 70px;
  cursor: pointer;
}

.deck-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* Hover 3D Window Tooltip */
.hover-window-tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  padding: 7px 11px;
  border-radius: 8px;
  background: rgba(8, 13, 25, 0.94);
  border: 1px solid var(--brand-color);
  color: var(--text-main);
  font-size: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  max-width: 260px;
}

.hover-window-tooltip strong {
  display: block;
  color: var(--gold-soft);
  margin-bottom: 2px;
}

/* Progressive Enhancement Fallback for Browsers without accent-color */
@supports not (accent-color: var(--brand-color)) {
  .checkbox-label input[type="checkbox"].fallback-check {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .checkbox-label {
    position: relative;
    padding-left: 1.75rem;
  }

  .checkbox-label input[type="checkbox"] + span::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid #94a3b8;
    background: #0f172a;
    border-radius: 4px;
    box-sizing: border-box;
  }

  .checkbox-label input[type="checkbox"]:focus-visible + span::before {
    outline: 2px solid var(--brand-color);
    outline-offset: 2px;
  }

  .checkbox-label input[type="checkbox"]:checked + span::before {
    background-color: var(--brand-color, #facc15);
    border-color: var(--brand-color, #facc15);
  }

  .checkbox-label input[type="checkbox"]:checked + span::after {
    content: "✓";
    position: absolute;
    left: 0.22rem;
    top: 50%;
    transform: translateY(-50%);
    color: #0f172a;
    font-weight: 800;
    font-size: 0.85rem;
  }

  input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 7px;
    background: linear-gradient(to right, var(--brand-color, #facc15) var(--progress, 50%), #334155 var(--progress, 50%));
    border-radius: 4px;
  }

  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 15px;
    width: 15px;
    border-radius: 50%;
    background: var(--brand-color, #facc15);
    cursor: pointer;
    margin-top: -4px;
  }

  input[type="range"]::-moz-range-track {
    width: 100%;
    height: 7px;
    background: #334155;
    border-radius: 4px;
  }

  input[type="range"]::-moz-range-thumb {
    height: 15px;
    width: 15px;
    border-radius: 50%;
    background: var(--brand-color, #facc15);
    cursor: pointer;
  }

  input[type="range"]::-moz-range-progress {
    background-color: var(--brand-color, #facc15);
    height: 7px;
    border-radius: 4px;
  }
}

@media (max-width: 1180px) {
  .bottom-deck {
    grid-template-columns: repeat(2, 1fr);
  }
  .hud-sidebar-left {
    width: 265px;
  }
  .hud-sidebar-right {
    width: 265px;
  }
}
