:root {
  --accent: #0066ff; /* Stark Technical Cobalt Blue */
  --bg: #ffffff;
  --panel-bg: rgba(255, 255, 255, 0.85);
  --border: #e2e2e2;
  --border-focus: #888888;
  --text: #111111;
  --text-muted: #777777;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border-radius: 0 !important; /* Stark minimal design: absolutely no rounded corners */
  user-select: none;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Syne Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0.08em;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

/* WebGL Canvas */
#webgl-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

/* Dynamic Code Background Revealed on Tear */
#code-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000000; /* Pure black background */
  z-index: 0;
  overflow: hidden; /* Scroll columns independently */
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 60px 40px 20px 40px;
  box-sizing: border-box;
}

#code-background, #code-background * {
  user-select: text !important; /* Allow copying and selecting code */
}

.code-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #000000; /* Pure black column background */
  border: 1px solid #333;
}

.code-column-header {
  background-color: #111111; /* Very dark grey column header */
  color: #888;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid #333;
  user-select: none;
}

/* Force Prism theme container to match the pure black background */
.code-column pre,
.code-column pre[class*="language-"],
.code-column code[class*="language-"] {
  background: #000000 !important;
  margin: 0;
  border: none;
}

.code-column pre {
  margin: 0;
  flex-grow: 1;
  overflow: auto;
  padding: 12px;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
}

/* Absolute UI overlays */
#ui-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none; /* Let clicks pass through to Canvas */
  display: grid;
  grid-template-rows: 44px 1fr;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "header header"
    "center right";
}

#ui-container * {
  pointer-events: auto; /* Re-enable pointer events for UI widgets */
}

/* Thin Hairline Borders & Stark Elements */
.border-b { border-bottom: 1px solid var(--border); }
.border-r { border-right: 1px solid var(--border); }
.border-l { border-left: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }

/* Header Styling */
.sys-header {
  grid-area: header;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background-color: #ffffff;
  border-bottom: 1px solid #000000;
  height: 44px;
  font-size: 13px;
  color: #000000;
  z-index: 1000;
  box-sizing: border-box;
  letter-spacing: 0.05em;
}

.sys-title {
  font-weight: bold;
  font-size: 28px;
  display: flex;
  align-items: center;
  height: 100%;
}

.menu-item-container {
  position: relative;
  height: 100%;
  display: inline-flex;
  align-items: center;
}

.menu-item {
  padding: 0 12px;
  height: 100%;
  display: inline-flex;
  align-items: center;
  cursor: default;
  user-select: none;
  font-size: 13px;
  color: #000000;
  text-decoration: none;
}

.menu-item-container:hover .menu-item,
.menu-item-container.active .menu-item {
  background-color: #000000;
  color: #ffffff;
}

.menu-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #ffffff;
  border: 1px solid #000000;
  box-shadow: 2px 2px 0px #000000;
  z-index: 1100;
  display: none;
  flex-direction: column;
  padding: 10px 12px;
  min-width: 200px;
  cursor: default;
  color: #000000;
}

.menu-item-container.active .menu-dropdown {
  display: flex;
}

.dropdown-link {
  display: block;
  width: 100%;
  padding: 6px 10px;
  color: #000000;
  text-decoration: none;
  cursor: default;
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

.dropdown-link:hover {
  background-color: #000000;
  color: #ffffff;
}

.dropdown-link.disabled {
  color: #888888;
  cursor: not-allowed;
}

.dropdown-link.disabled:hover {
  background-color: transparent;
  color: #888888;
}

.dropdown-separator {
  height: 1px;
  background-color: #000000;
  margin: 5px 0;
}

.menu-dropdown .section-title {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 8px;
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.accent-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  background-color: var(--accent);
  margin-right: 8px;
}

.sys-status {
  display: flex;
  gap: 15px;
  align-items: center;
  height: 100%;
}

.status-item {
  color: #000000;
  font-size: 13px;
  white-space: nowrap;
  cursor: default;
  display: inline-flex;
  align-items: center;
}

.status-item span {
  color: #000000;
  font-weight: bold;
  margin-left: 4px;
}

.status-active {
  color: var(--accent) !important;
  font-weight: bold;
}

.status-inactive {
  color: #777777 !important;
}

.status-item:nth-of-type(1) { width: 75px; }
.status-item:nth-of-type(2) { width: 150px; }
.status-item:nth-of-type(3) { width: 120px; }
.status-item:nth-of-type(4) { width: 90px; justify-content: flex-end; }

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title span.jp {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 8px;
  font-weight: normal;
}

/* Slider / Parameter Inputs */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text);
  text-transform: uppercase;
  font-size: 12px;
  white-space: nowrap;
  height: 18px;
}

.val-display {
  color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  background: #e2e2e2;
  height: 2px;
  outline: none;
  margin: 8px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 8px;
  height: 8px;
  background: var(--accent);
  cursor: pointer;
  border: 1px solid #ffffff;
  transition: background 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #111111;
}

/* Checkbox list */
.check-group {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 2px 0;
}

.check-group input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
}

.check-group input[type="checkbox"]:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.check-group input[type="checkbox"]:checked::after {
  content: '';
  width: 4px;
  height: 4px;
  background: #ffffff;
}

.check-group label {
  font-size: 12px;
  cursor: pointer;
}

/* UI Button Layout */
.grid-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.1em;
  text-align: center;
}

button:hover {
  border-color: var(--accent);
  background-color: rgba(0, 102, 255, 0.05);
  color: var(--accent);
}

button.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: bold;
}

.accent-btn {
  border-color: var(--accent);
  color: var(--accent);
  width: 100%;
  padding: 8px;
  font-weight: bold;
}

.accent-btn:hover {
  background-color: var(--accent);
  color: #ffffff;
}

/* Technical Readouts Panel (Right) */
.readout-panel {
  grid-area: right;
  background-color: var(--panel-bg);
  border-left: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(10px);
  width: 280px;
  box-sizing: border-box;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), padding 0.25s ease;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: bold;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.panel-header span {
  display: flex;
  align-items: center;
}

.panel-header .toggle-btn {
  font-size: 10px;
  color: var(--accent);
  transition: transform 0.25s ease;
}

.panel-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-grow: 1;
  margin-top: 15px;
  transition: opacity 0.15s ease;
}

/* Collapsed state overrides */
.readout-panel.collapsed {
  width: 50px !important;
  padding: 20px 10px !important;
  cursor: pointer;
  overflow: hidden;
  background-color: rgba(255, 255, 255, 0.95);
}

.readout-panel.collapsed:hover {
  background-color: rgba(0, 102, 255, 0.05);
}

.readout-panel.collapsed .panel-content {
  display: none !important;
}

.readout-panel.collapsed .panel-header {
  border-bottom: none;
  padding-bottom: 0;
  justify-content: center;
  width: 100%;
}

.readout-panel.collapsed .panel-header span:not(.toggle-btn) {
  display: none;
}

.readout-panel.collapsed .panel-header .toggle-btn {
  transform: rotate(180deg);
  font-size: 14px;
}

.readout-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eeeeee;
  padding: 6px 0;
  font-size: 12px;
  white-space: nowrap;
}

.readout-row .label {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 10px;
}

.readout-row .value {
  color: var(--text);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Bottom-Right PIP Webcam Video Dock */
#pip-container {
  position: absolute;
  bottom: 20px;
  right: 300px;
  width: 200px;
  background-color: var(--panel-bg);
  border: 1px solid var(--border);
  z-index: 12;
  backdrop-filter: blur(10px);
  display: none;
}

.pip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.rec-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent);
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0% { opacity: 0.2; }
  50% { opacity: 1; }
  100% { opacity: 0.2; }
}

.pip-body {
  width: 100%;
  background: #000;
  position: relative;
}

#pip-canvas {
  width: 100%;
  height: 150px;
  display: block;
}

/* Interactive hand cursor */
.hand-landmark {
  position: absolute;
  width: 20px;
  height: 20px;
  background-color: #ffffff;
  border: 1px solid #000000;
  pointer-events: none;
  display: none;
  transform: translate(-50%, -50%);
  z-index: 999;
}

.hand-landmark.pinching {
  background-color: var(--accent);
  border-color: var(--accent);
}

/* Calibration overlay */
#calibration-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.95); /* Light theme overlay */
  z-index: 2000; /* Set above everything including the header */
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-content {
  border: 1px solid var(--border);
  background: #ffffff;
  padding: 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.overlay-content h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #111111;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.overlay-content p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

.overlay-content button {
  margin-top: 10px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: #fafafa;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Mobile / Narrow Screen Responsiveness */
@media (max-width: 768px) {
  #ui-container {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "center";
  }
  .readout-panel {
    display: none !important;
  }
  #pip-container {
    right: 20px !important;
  }
}

@media (max-width: 600px) {
  .sys-title span[style*="font-weight: bold"] {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .sys-status {
    display: none !important;
  }
}
