@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap');

:root {
  --phos: #ffb85c; /* Amber phosphor */
  --screen-bg: #120e0a;
  --border-color: rgba(255, 184, 92, 0.25);
  --panel-bg: rgba(18, 14, 10, 0.85);
  --accent: rgb(56, 182, 255); /* Electric light blue */
  --accent-border: rgba(56, 182, 255, 0.35);
}

/* Theme overrides mapped to user's skin preferences */
body[data-theme="vintage"] {
  --phos: #ffb85c; /* Amber phosphor */
  --screen-bg: #120e0a;
  --border-color: rgba(255, 184, 92, 0.25);
  --panel-bg: rgba(18, 14, 10, 0.85);
}
body[data-theme="alpine"] {
  --phos: #5cb2ff; /* Ice blue phosphor */
  --screen-bg: #070912;
  --border-color: rgba(92, 178, 255, 0.25);
  --panel-bg: rgba(7, 9, 18, 0.85);
}
body[data-theme="winamp"] {
  --phos: #ea5cff; /* Cyber magenta */
  --screen-bg: #0d0712;
  --border-color: rgba(234, 92, 255, 0.25);
  --panel-bg: rgba(13, 7, 18, 0.85);
}
body[data-theme="data"] {
  --phos: #7dffa0; /* Matrix green */
  --screen-bg: #070d08;
  --border-color: rgba(125, 255, 160, 0.25);
  --panel-bg: rgba(7, 13, 8, 0.85);
}
body[data-theme="operator"] {
  --phos: #9fe870; /* Pocket Operator yellow-green */
  --screen-bg: #0c0f0a;
  --border-color: rgba(159, 232, 112, 0.25);
  --panel-bg: rgba(12, 15, 10, 0.85);
}

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

body {
  background-color: var(--screen-bg);
  color: var(--phos);
  font-family: 'Space Mono', monospace;
  overflow: hidden;
  width: 100vw;
  /* dvh tracks the mobile browser toolbar; without it the video box is 100vh
     tall while the canvas is only window.innerHeight, and the two disagree
     about where the webcam frame is cropped. */
  height: 100vh;
  height: 100dvh;
  position: relative;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* Classic HTML top-left link */
#code-demos-link,
#code-demos-link:visited {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10000;
  color: #0000ee;
  text-decoration: underline;
  font-family: inherit;
  font-size: 14px;
  font-weight: normal;
}

@media (max-width: 768px) {
  #code-demos-link {
    display: none;
  }
}

/* 1080p cover fit mirrored webcam feed */
#webcam {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  filter: grayscale(100%) contrast(125%) brightness(90%);
  opacity: 0.6;
  z-index: 0;
  pointer-events: none;
}

/* Fullscreen AR Canvas */
#harpCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* Oscilloscope — bottom-left readout */
#scope {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 190px;
  height: 68px;
  z-index: 1000;
  pointer-events: none;
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.6s ease;
}

#scope.live {
  opacity: 1;
}

#scopeCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scope-label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-family: 'Space Mono', monospace;
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--phos);
  opacity: 0.45;
}

@media (max-width: 600px) {
  #scope {
    width: 130px;
    height: 52px;
  }
}

/* Brutalist HUD Overlay */
#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px;
}

/* Controls Panel — flush into the top-right corner */
#controls-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 290px;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-top: none;
  border-right: none;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  font-family: 'Space Mono', monospace;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
  user-select: none;
}

.panel-header:hover {
  background: rgba(255, 184, 92, 0.1);
}

.panel-tag {
  font-weight: bold;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--phos);
  text-shadow: 0 0 5px rgba(255, 184, 92, 0.3);
}

.toggle-icon {
  font-size: 11px;
  color: var(--phos);
}

.panel-content {
  /* Fill the viewport minus the header strip; the header is ~35px tall */
  max-height: calc(100vh - 35px);
  max-height: calc(100dvh - 35px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: max-height 0.3s ease, padding 0.3s ease;
  /* Minimal scrollbar (Firefox) */
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

/* Minimal scrollbar (WebKit) */
.panel-content::-webkit-scrollbar {
  width: 4px;
}

.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 0;
}

.panel-content::-webkit-scrollbar-thumb:hover {
  background: var(--phos);
}

.panel-content.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  border-top-color: transparent;
}

.panel-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px dashed rgba(255, 184, 92, 0.15);
  padding-bottom: 14px;
}

.panel-group:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

/* Runtime readout pinned to the end of the panel */
.panel-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.panel-footer .val {
  font-variant-numeric: tabular-nums;
}

.group-title {
  font-size: 9px;
  color: var(--accent);
  text-shadow: 0 0 5px var(--accent-border);
  letter-spacing: 1px;
  font-weight: bold;
  margin-bottom: 2px;
  text-transform: uppercase;
}

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

.control-box.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
}

.control-box label {
  font-size: 9px;
  color: var(--phos);
  opacity: 0.7;
  letter-spacing: 1px;
  margin-bottom: 0;
  text-transform: uppercase;
}

.control-box select {
  width: 100%;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-color);
  color: var(--phos);
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 0;
  outline: none;
  cursor: pointer;
}

.control-box select:hover {
  border-color: var(--phos);
}

.control-box select option {
  background: #000;
  color: var(--phos);
}

.control-box input[type="range"] {
  width: 100%;
}

.control-box.color-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-box.color-row label {
  cursor: pointer;
}

.control-box input[type="color"] {
  width: 44px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 0;
  cursor: pointer;
}

.control-box input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.control-box input[type="color"]::-webkit-color-swatch {
  border: none;
}

.control-box input[type="color"]::-moz-color-swatch {
  border: none;
}

.finger-checkboxes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 12px;
}

.hud-btn {
  background: transparent;
  color: var(--phos);
  border: 1px solid var(--phos);
  padding: 8px 18px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  border-radius: 0;
  box-shadow: 0 0 10px rgba(255, 184, 92, 0.15);
  transition: all 0.2s ease;
  text-transform: uppercase;
}

.hud-btn:hover {
  background: var(--phos);
  color: var(--screen-bg);
  box-shadow: 0 0 15px var(--phos);
}

.hud-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hud-footer {
  display: flex;
  gap: 30px;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  padding: 10px 24px;
  align-self: flex-start;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.hud-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 1.5px;
}

.info-label {
  color: var(--phos);
  opacity: 0.5;
}

.val {
  font-weight: 700;
}

.val.active {
  color: var(--phos);
  text-shadow: 0 0 8px var(--phos);
}

.val.inactive {
  color: #ff5555;
}

/* Hide SVG defs */
svg {
  display: none;
}

/* Brutalist Range Inputs */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  height: 20px;
}

input[type="range"]::-webkit-slider-runnable-track {
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--border-color);
  height: 6px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--phos);
  height: 14px;
  width: 8px;
  margin-top: -5px; /* webkit centering offset */
  border-radius: 0; /* sharp brutalist thumb */
  box-shadow: 0 0 5px var(--phos);
  border: none;
}

input[type="range"]::-moz-range-track {
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--border-color);
  height: 6px;
}

input[type="range"]::-moz-range-thumb {
  background-color: var(--phos);
  height: 14px;
  width: 8px;
  border-radius: 0;
  box-shadow: 0 0 5px var(--phos);
  border: none;
}

/* Blue Accent Styling */
.accent-blue {
  color: var(--accent) !important;
  text-shadow: 0 0 8px var(--accent) !important;
}

.hud-btn.accent-blue-btn {
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: 0 0 10px rgba(56, 182, 255, 0.2);
}

.hud-btn.accent-blue-btn:hover {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 0 15px var(--accent);
}

/* Splash screen entrance overlay */
#splash-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background-color: var(--screen-bg);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#splash-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.splash-btn {
  background: transparent;
  color: var(--phos);
  border: 2px solid var(--phos);
  padding: 20px 40px;
  font-family: 'Space Mono', monospace;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  cursor: pointer;
  border-radius: 0;
  box-shadow: 0 0 25px rgba(255, 184, 92, 0.2);
  transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
  text-transform: uppercase;
}

.splash-btn:hover {
  background: var(--phos);
  color: var(--screen-bg);
  box-shadow: 0 0 40px var(--phos);
}

.splash-sub {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  color: var(--phos);
  opacity: 0.5;
  letter-spacing: 2px;
}

/* Boot loader — replaces the START button while systems come online */
.splash-loader {
  display: none;
  flex-direction: column;
  gap: 14px;
  width: 260px;
}

.splash-content.loading .splash-btn,
.splash-content.loading .splash-sub {
  display: none;
}

.splash-content.loading .splash-loader {
  display: flex;
}

.loader-bar {
  height: 2px;
  width: 100%;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.loader-fill {
  height: 100%;
  width: 0%;
  background: var(--phos);
  box-shadow: 0 0 10px var(--phos);
  transition: width 0.35s ease;
}

/* Indeterminate sweep on top of the discrete step progress */
.loader-bar::after {
  content: '';
  display: block;
  position: relative;
  top: -2px;
  height: 2px;
  width: 30%;
  background: linear-gradient(90deg, transparent, var(--phos), transparent);
  opacity: 0.55;
  animation: loader-sweep 1.4s linear infinite;
}

@keyframes loader-sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(340%); }
}

.loader-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loader-step {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--phos);
  opacity: 0.35;
  transition: opacity 0.25s ease;
}

.loader-step.active {
  opacity: 0.85;
}

.loader-step.active .step-state {
  animation: loader-blink 0.9s steps(2, end) infinite;
}

.loader-step.done {
  opacity: 1;
}

.loader-step.error {
  opacity: 1;
  color: #ff5c5c;
}

@keyframes loader-blink {
  50% { opacity: 0.25; }
}

/* Brutalist Custom Checkbox */
input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer;
  position: relative;
  margin-right: 4px;
}

input[type="checkbox"]:checked {
  background: var(--phos);
  box-shadow: 0 0 5px var(--phos);
}

input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--screen-bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Responsive mobile styles */
@media (max-width: 600px) {
  #controls-panel {
    top: 0;
    right: 0;
    left: 0;
    width: auto;
    max-width: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  }
  
  .panel-content {
    max-height: 45vh; /* Keep it compact so user can still see the canvas grid/feed when editing */
    padding: 10px;
    gap: 12px;
  }
  
  .panel-group {
    padding-bottom: 10px;
    gap: 8px;
  }
  
  .finger-checkboxes {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 10px;
  }
  
  .splash-btn {
    font-size: 16px;
    padding: 15px 30px;
    letter-spacing: 3px;
  }
  
  .splash-sub {
    font-size: 8px;
    letter-spacing: 1px;
    text-align: center;
    max-width: 80%;
  }
}
