/* Custom button color classes */

.btn-default {
  background-color: #fff;
  color: #222;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-yellow {
  background-color: #ffe066;
  color: #222;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-yellow:hover {
  background-color: #fff3b0;
}

.btn-red {
  background-color: #ff5c5c;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-red:hover {
  background-color: #ff8787;
}

.btn-blue {
  background-color: #4da3ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-blue:hover {
  background-color: #8cc8ff;
}
/* Global reset for predictable spacing and sizing */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base page styling */
body {
  font-family: system-ui, sans-serif;
  background: #111;
  color: #eee;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

html {
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

h1 {
  text-align: center;
  margin-bottom: 1rem;
}


/* Main layout: two containers side by side */
.container {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: visible;
}

/* Each container is a vertical stack of two panels */
.container-one, .container-two {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

/* Panel styling for all four panels */
.panel {
  background: #1a1a1a;
  padding: 1rem;
  border-radius: 6px;
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* height: 100%; removed to allow vertical growth */
}

.right-column {
  display: flex;
  min-width: 0;
  align-self: start;
}

video,
canvas {
  width: 100%;
  background: black;
  border: 1px solid #333;
  display: block;
}

.waveform-wrapper {
  position: relative;
  width: 100%;
}

.waveform-card {
  margin-top: 0.25rem;
  padding: 0.7rem;
  border: 1px solid #333;
  border-radius: 6px;
  background: #121212;
}

.waveform-card h3 {
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
  color: #ddd;
}

h3,
label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.camera-card {
  margin-top: 0.25rem;
}

.mobile-analysis-return {
  display: none;
  margin-top: 0.75rem;
  background-color: #ff5c5c;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.mobile-analysis-return:hover {
  background-color: #ff8787;
}

.mobile-analysis-button {
  display: none;
  background-color: #4da3ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.mobile-analysis-button:hover {
  background-color: #8cc8ff;
}

.info-row {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #cbd5e1;
  font-size: 0.9rem;
}

.info-label {
  font-weight: 600;
}

.info-inline {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.info-trigger {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border: 1px solid #475569;
  border-radius: 999px;
  background: #0f172a;
  color: #cbd5e1;
  font-size: 0.75rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.info-trigger:hover,
.info-trigger:focus-visible {
  background: #1e293b;
  border-color: #7dd3fc;
  color: #f8fafc;
  outline: none;
}

.info-box {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 50%;
  --info-box-shift: 0px;
  z-index: 10;
  width: min(18rem, calc(100vw - 2rem));
  padding: 0.6rem 0.7rem;
  border: 1px solid #334155;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.97);
  color: #e2e8f0;
  font-size: 0.8rem;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translate(calc(-50% + var(--info-box-shift)), -4px);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.info-inline:hover .info-box,
.info-inline:focus-within .info-box {
  opacity: 1;
  transform: translate(calc(-50% + var(--info-box-shift)), 0);
}

.spectrum-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.spectrum-title {
  margin: 0;
}

#waveformCanvas {
  display: block;
  position: relative;
  height: auto;
}

#spectrumCanvas {
  height: auto;
}

.waveform-period-note {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  font-size: 0.8rem;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 0.2rem 0.45rem;
  line-height: 1.2;
}

/* Video wrapper keeps the processing canvas aligned over the video element */
.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: var(--video-aspect-ratio, 4 / 3);
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

html[data-device-mode='mobile'] .video-wrapper {
  max-width: min(100%, 32rem);
  margin-inline: auto;
}

html[data-device-mode='mobile'] .controls {
  flex-wrap: wrap;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#processingCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Utility class used by JS to show/hide camera-only controls */
.hidden { display: none !important; }

.roi-controls {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.roi-hint {
  color: #94a3b8;
  font-size: 0.9rem;
  line-height: 1.35;
}

.roi-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.roi-controls label {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  color: #cbd5e1;
}

/* Control groups for ROI and camera actions */
.controls {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.camera-select-row {
  display: inline-flex;
  gap: 0.5rem;
}

button {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  cursor: pointer;
}

.audio-controls {
  margin-top: 0.75rem;
  align-items: flex-start;
  flex-direction: column;
  flex-wrap: wrap;
}

.audio-action-row {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.audio-action-row .mobile-analysis-return {
  margin-top: 0;
}

.audio-primary-controls {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.audio-primary-controls input {
  width: 96px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 0.3rem 0.4rem;
}

.audio-controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: #ddd;
}

.spectrum-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0;
}

.spectrum-controls label {
  color: #cbd5e1;
  font-size: 0.9rem;
}

.spectrum-controls select {
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
}

.test-signal-controls {
  display: grid;
  grid-template-columns: minmax(120px, 150px) minmax(90px, 120px) minmax(90px, 120px);
  justify-content: start;
  gap: 0.4rem;
  align-items: end;
}

.test-signal-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.test-signal-controls label {
  color: #cbd5e1;
  font-size: 0.9rem;
}

.test-signal-controls input,
.test-signal-controls select {
  width: 100%;
  max-width: 150px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 0.35rem 0.45rem;
}

.test-signal-controls button {
  grid-column: 1 / -1;
  justify-self: start;
  align-self: end;
  min-width: 0;
  margin-top: 0.15rem;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .test-signal-controls {
    grid-template-columns: 1fr;
  }

  .info-box {
    left: 50%;
    width: min(16rem, calc(100vw - 2rem));
  }
}

/* Stack panels vertically on smaller screens */
@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .right-column {
    display: block;
  }
}

html[data-device-mode='mobile'] .mobile-view-section {
  min-width: 0;
}

html[data-device-mode='mobile'][data-mobile-view='generation'] .mobile-analysis-view {
  display: none;
}

html[data-device-mode='mobile'][data-mobile-view='analysis'] .mobile-generation-view {
  display: none;
}

html[data-device-mode='mobile'] .mobile-analysis-return {
  display: inline-flex;
}

html[data-device-mode='mobile'] .mobile-analysis-button {
  display: inline-flex;
}
