/* ── Diffraction module layout ── */
html, body {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── View Mode Bar ── */
.view-mode-bar {
  height: 34px;
  background: var(--bg-primary);
  border-bottom: 1px solid rgba(108,99,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex-shrink: 0;
}

.view-tab {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 5px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.view-tab:hover {
  color: var(--text-secondary);
  background: rgba(108,99,255,0.08);
}

.view-tab.active {
  color: var(--text-primary);
  background: rgba(108,99,255,0.2);
}

/* ── App container ── */
.app {
  display: flex;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

/* ── Left: Display ── */
.display-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 32px;
  position: relative;
}
.display-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(108,99,255,0.08) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(233,69,96,0.06) 0%, transparent 60%);
  pointer-events: none;
}

h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  position: relative;
  z-index: 1;
}

.canvas-wrap {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid rgba(108,99,255,0.15);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.canvas-wrap canvas { display: block; border-radius: var(--radius-sm); }
#detectorCanvas { image-rendering: pixelated; cursor: pointer; }
.canvas-label {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.hkl-labels {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin-top: 6px;
  font-family: 'Fira Code', monospace;
  font-size: 0.7rem;
  color: var(--accent-4);
  position: relative;
  z-index: 1;
}
.hkl-labels span { text-align: center; flex: 1; }

.hkl-top-labels {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin-bottom: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.55rem;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}
.hkl-top-labels span { text-align: center; flex: 1; white-space: nowrap; overflow: hidden; }

.rules-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.72rem; color: var(--accent-4); cursor: help;
  padding: 3px 8px; border-radius: 4px;
  background: rgba(245,166,35,0.1); border: 1px solid rgba(245,166,35,0.25);
  position: relative; margin-top: 6px;
}
.rules-badge:hover .rules-tooltip { display: block; }
.rules-tooltip {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 0;
  min-width: 260px; padding: 10px 12px;
  background: var(--bg-card); border: 1px solid rgba(108,99,255,0.25);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  font-size: 0.72rem; color: var(--text-secondary); line-height: 1.55;
  z-index: 50; white-space: pre-line;
}
.rules-tooltip strong { color: var(--accent-3); }

.status-bar {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: 'Fira Code', monospace;
  position: relative;
  z-index: 1;
}

/* ── 3D container ── */
#threeContainer {
  position: relative;
  width: 720px;
  height: 540px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
#threeContainer canvas { display: block; border-radius: var(--radius-sm); }

/* ── 2D detector wrapper ── */
.detector-wrap {
  position: relative;
  display: inline-block;
}
.detector-wrap:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Right: Control panel ── */
.control-panel {
  width: 310px;
  background: var(--bg-slide);
  border-left: 1px solid rgba(108,99,255,0.12);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-1);
  text-align: center;
  padding-bottom: 10px;
  border-bottom: 2px solid rgba(108,99,255,0.2);
}

.section {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid rgba(108,99,255,0.1);
}
.section h3 {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent-3);
  margin-bottom: 10px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.slider-group:last-child { margin-bottom: 0; }
.slider-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.slider-group label .param-name { font-weight: 500; }
.slider-group label .val {
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  color: var(--accent-4);
}
.slider-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(108,99,255,0.15);
  outline: none;
}
.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent-1);
  cursor: pointer;
  transition: transform 0.1s;
}
.slider-group input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-group input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent-1);
  cursor: pointer;
  border: none;
}

.select-group { margin-bottom: 10px; }
.select-group:last-child { margin-bottom: 0; }
.select-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}
.select-group select {
  width: 100%;
  padding: 6px 10px;
  background: rgba(108,99,255,0.1);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.select-group select:focus { border-color: var(--accent-1); }
.select-group select option { background: var(--bg-card); }

.colorbar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  position: relative;
  z-index: 1;
}
.colorbar-canvas { border-radius: 4px; }
.colorbar-label {
  font-size: 0.7rem;
  font-family: 'Fira Code', monospace;
  color: var(--text-muted);
}

.control-panel::-webkit-scrollbar { width: 6px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb { background: rgba(108,99,255,0.3); border-radius: 3px; }

.loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,15,26,0.85);
  z-index: 200;
  font-size: 1.1rem;
  color: var(--accent-1);
}
.loading.hidden { display: none; }

.toggle-group {
  display: flex; align-items: center;
  gap: 8px; margin-bottom: 10px;
}
.toggle-group label { font-size: 0.8rem; color: var(--text-secondary); cursor: pointer; }
.toggle-group input[type="checkbox"] { accent-color: var(--accent-1); width: 16px; height: 16px; cursor: pointer; }

.update-btn {
  width: 100%;
  padding: 10px 0;
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.03em;
}
.update-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.update-btn:active { transform: scale(0.98); }

.theme-btn {
  width: 100%;
  padding: 10px 0;
  margin-top: 8px;
  background: linear-gradient(135deg, rgba(108,99,255,0.25), rgba(233,69,96,0.18));
  border: 1px solid rgba(108,99,255,0.35);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  letter-spacing: 0.02em;
}
.theme-btn:hover {
  background: linear-gradient(135deg, rgba(108,99,255,0.4), rgba(233,69,96,0.3));
  border-color: rgba(108,99,255,0.5);
  transform: translateY(-1px);
}

/* light-bg handled by common.css */

.cmap-select {
  padding: 2px 6px;
  background: var(--bg-card);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  outline: none;
  cursor: pointer;
}
.cmap-select option { background: var(--bg-card); }

.fs-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  cursor: grab; overflow: hidden;
}
.fs-overlay canvas {
  image-rendering: pixelated;
  max-width: none; max-height: none;
  transform-origin: center center;
}
.fs-hint {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  font-size: 0.8rem; color: rgba(255,255,255,0.5);
  font-family: 'Inter', sans-serif;
  pointer-events: none;
}
