:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1f2630;
  --line: #2a3340;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4cc2ff;
  --accent-2: #ffb74d;
  --good: #74e09f;
  --warn: #ff7b72;
  --pink: #ec5fff;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Beta banner - thin colored stripe at the very top */
.beta-banner {
  background: linear-gradient(90deg, #3b2e0e 0%, #4a3a14 50%, #3b2e0e 100%);
  color: #ffd97a;
  border-bottom: 1px solid #6a5520;
  font-size: 11px;
  letter-spacing: 0.3px;
  padding: 4px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 24px;
  flex-shrink: 0;
}
.beta-banner .beta-tag {
  background: #ffb74d;
  color: #1a1408;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 0.5px;
}
.beta-banner .sep { color: #6a5520; }
.beta-banner .beta-link {
  color: #ffd97a;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.beta-banner .beta-link:hover { color: #fff; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: linear-gradient(180deg, #1a212c, #131820);
  border-bottom: 1px solid var(--line);
  height: 48px;
  gap: 12px;
}
.brand {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.brand .tag {
  font-size: 9px;
  background: var(--accent);
  color: #001a2a;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 700;
}

/* Lens type tabs */
.lens-tabs {
  display: flex;
  gap: 2px;
  background: #0a0d12;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.tab {
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: #001a2a; font-weight: 600; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

/* Buttons */
button {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #2a3340; border-color: #3a4654; }
button:active { background: #232b35; }
button.primary {
  background: var(--accent);
  color: #001a2a;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { background: #6dd0ff; border-color: #6dd0ff; }
button.ghost {
  background: transparent;
  border-style: dashed;
  width: 100%;
  margin-top: 6px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
}
.panel.right { border-right: none; border-left: 1px solid var(--line); }

.card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
}
.card h2 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-tag {
  font-size: 9px;
  letter-spacing: 0.5px;
  font-weight: 600;
  text-transform: uppercase;
  margin-left: auto;
}
.card.hidden { display: none; }

label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}
label.check {
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
input[type="number"], input[type="file"], select {
  display: block;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 5px 7px;
  border-radius: 3px;
  margin-top: 3px;
  font: inherit;
}
input[type="number"]:focus, select:focus { outline: none; border-color: var(--accent); }
details { margin: 6px 0; color: var(--muted); }
details summary { cursor: pointer; font-size: 11px; padding: 4px 0; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

/* Viewport column */
.viewport-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewbar {
  display: flex;
  align-items: center;
  background: #0a0d12;
  border-bottom: 1px solid var(--line);
  padding: 4px 8px;
  gap: 12px;
  height: 36px;
}
.view-tabs { display: flex; gap: 2px; }
.vtab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 3px 10px;
  font-size: 11px;
  border-radius: 4px;
}
.vtab.active { background: var(--bg-3); color: var(--text); border-color: var(--line); }

.meridian-bar { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.m-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.meridian-buttons { display: flex; gap: 2px; }
.mer {
  background: var(--bg-3);
  border: 1px solid var(--line);
  padding: 2px 7px;
  font-size: 10px;
  color: var(--muted);
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.mer.active { background: var(--accent); color: #001a2a; font-weight: 600; border-color: var(--accent); }

/* Viewport */
.viewport {
  position: relative;
  background: radial-gradient(ellipse at center, #182230, #0a0d12);
  overflow: hidden;
  flex: 1;
  display: flex;
}
.viewport.hidden { display: none; }
#three-container {
  flex: 1;
  position: relative;
}
#three-container canvas { display: block; }

/* Quad view */
.quadview {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  padding: 10px;
}
.quadview.hidden { display: none !important; }
.quad-cell {
  background: #000;
  border: 1px solid var(--line);
  border-radius: 4px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.quad-cell h3 {
  position: absolute;
  top: 4px;
  left: 8px;
  margin: 0;
  font-size: 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 3px;
}
.quad-cell canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(15,20,28,0.85);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}
.hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hud-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  width: 70px;
}
.hud-val {
  min-width: 80px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.hud-hint { color: var(--muted); font-size: 11px; margin-left: 8px; }

button.step {
  padding: 3px 8px;
  font-size: 11px;
  background: var(--bg-3);
}

.readout {
  position: absolute;
  bottom: 10px;
  left: 12px;
  right: 12px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: rgba(15,20,28,0.7);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 10px;
  white-space: pre;
  z-index: 5;
}

/* Tear film panel */
.tearfilm-panel {
  background: #0a0d12;
  border-top: 1px solid var(--line);
  padding: 4px 8px 8px;
  flex-shrink: 0;
}
.tf-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 0;
  font-size: 11px;
  color: var(--muted);
}
.tf-title { font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 1px; font-size: 10px; }
.tf-toolbar select {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 2px 6px;
}
.tf-toolbar label { display: flex; align-items: center; gap: 6px; margin: 0; }
.legend-row { display: flex; align-items: center; gap: 12px; margin-left: auto; font-size: 11px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
#tearfilm {
  display: block;
  width: 100%;
  height: 220px;
  background: #0a0d12;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

/* AI / Candidacy output */
.ai-output {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
.ai-output .ai-line { display: flex; justify-content: space-between; padding: 2px 0; }
.ai-output .ai-line span:first-child { color: var(--muted); }
.ai-output .ai-rationale {
  color: var(--muted);
  margin-top: 8px;
  font-size: 11px;
  border-top: 1px dashed var(--line);
  padding-top: 6px;
}
.verdict { padding: 4px 8px; border-radius: 4px; font-weight: 600; display: inline-block; margin-bottom: 4px; }
.verdict.good { background: rgba(116, 224, 159, 0.15); color: var(--good); border: 1px solid var(--good); }
.verdict.ok { background: rgba(255, 183, 77, 0.15); color: var(--accent-2); border: 1px solid var(--accent-2); }
.verdict.poor { background: rgba(255, 123, 114, 0.15); color: var(--warn); border: 1px solid var(--warn); }

/* Topo */
#topo-canvas {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  background: #000;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
}
.legend .grad {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(to right, #1f4dff, #00e5ff, #00ff9c, #ffe900, #ff8e00, #ff0033);
}
.legend .spacer { flex: 1; }

/* Segmented control */
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 2px; background: #0a0d12; padding: 2px; border-radius: 5px; border: 1px solid var(--line); }
.seg-btn {
  background: transparent;
  border: none;
  padding: 5px;
  font-size: 11px;
  color: var(--muted);
  border-radius: 3px;
}
.seg-btn.active { background: var(--accent); color: #001a2a; font-weight: 600; }
.hint { font-size: 10px; color: var(--muted); margin-top: 6px; font-style: italic; }

/* Preset grid */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.preset {
  font-size: 11px;
  padding: 6px 4px;
  text-align: center;
  line-height: 1.2;
}
.preset.active {
  background: var(--accent);
  color: #001a2a;
  border-color: var(--accent);
  font-weight: 600;
}

/* Mod grid */
.mod-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 8px;
}
.mod {
  font-size: 11px;
  padding: 5px;
  text-align: center;
}
.mod.wide { grid-column: 1 / -1; background: var(--bg-2); }

/* Param rows */
.param {
  display: grid;
  grid-template-columns: 1fr auto 70px auto auto;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.param:last-child { border-bottom: none; }
.p-label { color: var(--text); font-size: 12px; }
.p-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}
.p-unit { font-size: 10px; color: var(--muted); width: 24px; }

/* Statusbar */
.statusbar {
  height: 24px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #0a0d12;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  gap: 12px;
}
.spacer-flex { flex: 1; }
.statusbar .patent-pending {
  color: #8b98a5;
  font-size: 10px;
  letter-spacing: 0.3px;
}
.statusbar .sep { color: #2a3340; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #2a3340; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4654; }

.quad-cell canvas { width: 100%; height: 100%; object-fit: contain; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 720px;
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 14px; flex: 1; }
.modal-x {
  background: transparent; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 0 8px;
}
.modal-x:hover { color: var(--text); }
.modal-body {
  padding: 12px 14px;
  overflow-y: auto;
  flex: 1;
}
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.pt-preview-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-top: 8px;
}
.pt-preview {
  background: #0a0d12;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: var(--text);
  white-space: pre;
  max-height: 280px;
  overflow: auto;
  margin: 8px 0 0;
}
