@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Syne:wght@400;600;700;800&display=swap');
@import url('./variables.css');

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

body {
  font-family: var(--font-mono);
  background: linear-gradient(135deg, #090e17 0%, #0d2746 50%, #06b6d4 150%);
  color: var(--color-ui-text);
  font-size: 13px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Layout */
.problem-banner {
  background: rgba(6, 182, 212, 0.15);
  border-bottom: 1px solid rgba(6, 182, 212, 0.3);
  padding: 8px 20px;
  text-align: center;
  font-family: var(--font-syne), sans-serif;
  font-size: 14px;
  color: #fff;
  z-index: 100;
}
.problem-banner strong {
  color: var(--color-source-a);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 14, 23, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease, visibility 0.3s;
}
.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 2.5rem;
  border-radius: 12px;
  max-width: 500px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}
.modal-title {
  font-family: var(--font-syne), sans-serif;
  color: #fff;
  margin-bottom: 1rem;
  font-size: 1.5rem;
  text-align: center;
}
.modal-body {
  color: var(--color-ui-text);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  text-align: justify;
}
.modal-features {
  list-style: none;
  margin-bottom: 1.5rem;
  text-align: justify;
}
.modal-features li {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: #ddd;
}
.modal-features li i {
  color: var(--color-source-a);
  width: 18px;
  height: 18px;
}
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--color-source-a);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--font-syne), sans-serif;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover {
  background: #2dd4bf;
}

.app-container {
  display: flex;
  flex: 1;
  width: 100vw;
  background: radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.05) 0%, transparent 70%);
  overflow: hidden;
}

/* Canvas Area */
.canvas-container {
  flex: 1;
  background-color: transparent;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: visible;
  padding-top: 180px;
  padding-bottom: 100px;
}

#canvas-main {
  /* The internal resolution is 400x400 as per soft constraints, but we scale it gracefully */
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

#canvas-main.ready {
  opacity: 1;
}

/* Source Draggable Indicators (HTML overlay for accessibility and ease of styling) */
.source-indicator {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: grab;
  box-shadow: 0 0 0 2px var(--color-void);
  z-index: 10;
}
.source-indicator:active {
  cursor: grabbing;
}
.source-indicator::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.5;
  animation: pulse 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}
#source-a-indicator { background-color: var(--color-source-a); color: var(--color-source-a); }
#source-b-indicator { background-color: var(--color-source-b); color: var(--color-source-b); }

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* Preset Overlays */
.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preset-overlay {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.5s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preset-overlay.active {
  opacity: 1;
}

.headphone-svg {
  width: 200px;
  height: 100px;
  transform: translateY(20px);
}

.blueprint-svg {
  width: 100%;
  height: 100%;
}

.slit-barrier {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 8px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
}

.barrier-segment {
  width: 100%;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.slit-barrier .top, .slit-barrier .bottom { flex: 1; }
.slit-barrier .middle { height: 40px; }
.slit-gap { height: 12px; background: transparent; }

/* Phone Receiver Icon */
.phone-indicator {
  position: absolute;
  width: 24px;
  height: 24px;
  color: #fff;
  transform: translate(-50%, -50%);
  cursor: grab;
  z-index: 12;
  display: none; /* hidden by default */
  flex-direction: column;
  align-items: center;
  opacity: 0.9;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}
.phone-indicator.visible {
  display: flex;
}
.phone-indicator:active {
  cursor: grabbing;
}

.signal-bar {
  margin-top: 4px;
  width: 20px;
  height: 4px;
  background: rgba(0,0,0,0.7);
  border-radius: 2px;
  overflow: hidden;
}
.signal-fill {
  height: 100%;
  width: 0%;
  background: var(--color-source-a);
  transition: width 0.1s linear, background-color 0.1s linear;
}

/* Intensity Readout Overlay */
.intensity-readout {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 25;
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.readout-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-ui-text);
}

.readout-bar {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  display: flex;
  position: relative;
  overflow: hidden;
}

.readout-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.3);
  z-index: 2;
}

.readout-destructive {
  background: var(--color-destructive);
  position: absolute;
  right: 50%;
  top: 0;
  bottom: 0;
  width: 0%;
  transition: width 0.1s ease;
}

.readout-constructive {
  background: var(--color-constructive);
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 0%;
  transition: width 0.1s ease;
}

/* Add HUD Top Bar */
.hud-top-bar {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 15px;
  pointer-events: none; /* Let canvas drag events pass through... */
  z-index: 20;
  max-width: calc(100% - 40px);
}

/* ...but make the inner panels clickable/interactable */
.hud-top-bar > * {
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* 1D Cross-Section Graph Overlay */
.graph-panel {
  position: relative; 
  flex: 1;
  min-width: 220px;
  max-width: 300px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.graph-title {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-ui-text);
  width: 100%;
  text-align: left;
}

#graph-canvas {
  width: 100%;
  height: 50px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  cursor: crosshair;
}

.probe-value {
  font-size: 12px;
  color: var(--color-constructive);
  font-variant-numeric: tabular-nums;
  width: 100%;
  text-align: right;
  height: 14px;
}

/* Analytical Validation Panel */
.analytics-panel {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 280px; 
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-mono);
}
.analytics-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--color-source-b);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-weight: bold;
}
.analytics-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}
.stat-val {
  color: #fff;
  font-weight: 500;
}

/* Control Panel */
.control-panel {
  width: var(--panel-width);
  background: var(--color-panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--color-border);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  z-index: 20;
}

.panel-header {
  padding: var(--spacing-lg);
  background-color: var(--color-panel-header);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h1 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-ui-text-bright);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-ui-text);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-ui-text-bright);
}

.section {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--color-border);
  position: relative;
}

.section-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--color-ui-text-bright);
  margin-bottom: var(--spacing-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.title-dot.a { background-color: var(--color-source-a); }
.title-dot.b { background-color: var(--color-source-b); }

/* Controls */
.control-group {
  margin-bottom: var(--spacing-lg);
}
.control-group:last-child {
  margin-bottom: 0;
}

.control-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--spacing-sm);
  font-size: 11px;
}

.val-display {
  color: var(--color-ui-text-bright);
  font-weight: 500;
}

/* Custom Sliders */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  accent-color: var(--color-source-a);
  transition: all 0.3s ease;
}

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

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: var(--color-ui-text-bright);
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -5px;
}

input[type=range].source-a::-webkit-slider-thumb { background: var(--color-source-a); }
input[type=range].source-b::-webkit-slider-thumb { background: var(--color-source-b); }

/* Buttons */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--color-ui-text-bright);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.3);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Equation Overlay */
.equation-panel {
  padding: var(--spacing-md);
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  font-size: 12px;
  margin-top: var(--spacing-md);
  display: none;
}

.equation-panel.visible {
  display: block;
}

.equation-line {
  margin-bottom: 4px;
  color: var(--color-ui-text-bright);
}
.equation-var-a { color: var(--color-source-a); }
.equation-var-b { color: var(--color-source-b); }

/* Mobile fallback */
@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app-container {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  
  .canvas-container {
    flex: 0 0 auto;
    min-height: 50vh;
    height: auto;
    padding-top: 12px;
    padding-bottom: 12px;
    justify-content: flex-start;
    padding-left: 10px;
    padding-right: 10px;
    overflow: visible;
  }
  
  .control-panel {
    width: 100%;
    flex: none;
    border-left: none;
    border-top: 1px solid var(--color-border);
    max-height: none;
    overflow: visible;
  }
  
  .hud-top-bar {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    z-index: 20;
    max-width: 100%;
    margin: 10px 0 0;
  }
  
  .graph-panel, .analytics-panel {
    width: 100%;
    max-width: none;
    min-width: unset;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(6, 182, 212, 0.4);
  }
  
  #graph-canvas {
    width: 100%;
    height: 56px;
  }

  .intensity-readout {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    width: 100%;
    transform: none;
    margin: 10px 0 0;
    z-index: 25;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(6, 182, 212, 0.4);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
  
  .readout-bar {
    width: 100%;
    min-width: 0;
  }
  
  #interactive-bounds {
    width: 100%;
    flex: none;
    height: auto;
    aspect-ratio: 1 / 1;
    min-height: 280px;
  }
}

/* Ultra-mobile (small phones) */
@media (max-width: 480px) {
  .canvas-container {
    min-height: 42vh;
    padding-top: 10px;
    padding-bottom: 10px;
    padding-left: 5px;
    padding-right: 5px;
  }
  
  .hud-top-bar {
    gap: 8px;
  }
  
  .graph-panel, .analytics-panel {
    padding: 10px;
    border-radius: 6px;
  }
  
  .graph-title, .analytics-title {
    font-size: 9px;
  }
  
  #graph-canvas {
    height: 44px;
  }
  
  .intensity-readout {
    padding: 8px 12px;
    min-width: unset;
    width: 100%;
  }
  
  .readout-label {
    font-size: 9px;
  }
}

/* Tablet/Medium screens */
@media (min-width: 769px) and (max-width: 1024px) {
  .canvas-container {
    padding-top: 160px;
    padding-bottom: 90px;
  }
  
  .hud-top-bar {
    top: 15px;
    left: 15px;
    right: 15px;
    gap: 12px;
  }
  
  .graph-panel, .analytics-panel {
    min-width: 180px;
    max-width: 270px;
  }
}

/* Large desktop */
@media (min-width: 1920px) {
  .canvas-container {
    padding-top: 200px;
    padding-bottom: 120px;
  }
  
  .hud-top-bar {
    top: 25px;
    left: 30px;
    right: 30px;
    gap: 20px;
  }
  
  .graph-panel, .analytics-panel {
    min-width: 280px;
    max-width: 350px;
  }
}
