:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

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

/* ---- Header / phase tracker ---- */
header {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: 0 0 auto;
}
header h1 { font-size: 18px; margin: 0; white-space: nowrap; }

.phases { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.phase-step {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  padding: 4px 10px; border-radius: 20px; border: 1px solid transparent;
}
.phase-step span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--border); color: var(--text); font-size: 11px; font-weight: 700;
}
.phase-step.active { color: var(--text); border-color: var(--accent); }
.phase-step.active span { background: var(--accent); }
.phase-step.done span { background: #238636; }

/* ---- Tabs ---- */
.tabbar {
  display: flex; gap: 4px;
  padding: 6px 12px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.tab {
  font: inherit; font-size: 13px; cursor: pointer;
  padding: 8px 18px; border: 1px solid var(--border); border-bottom: none;
  border-radius: 8px 8px 0 0; background: transparent; color: var(--muted);
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--bg); color: var(--text);
  border-color: var(--border); border-bottom: 1px solid var(--bg);
}

/* ---- Stage: one full-width pane active at a time ---- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; background: var(--bg); }
.tabpane { position: absolute; inset: 0; display: none; }
.tabpane.active { display: block; }
.canvas-wrap { position: relative; width: 100%; height: 100%; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; }
#photoCanvas { cursor: crosshair; }

.empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); padding: 20px; line-height: 1.6;
}
.scene-label {
  position: absolute; bottom: 8px; left: 8px;
  font-size: 11px; color: var(--muted); background: rgba(0,0,0,0.4);
  padding: 3px 8px; border-radius: 6px; pointer-events: none;
}

/* ---- Floating draggable control panel ---- */
.controls {
  position: fixed; top: 120px; right: 20px;
  width: 320px; max-height: calc(100vh - 140px);
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  z-index: 50;
}
.drag-handle {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: grab;
  border-bottom: 1px solid var(--border);
  background: #1b2028; border-radius: 12px 12px 0 0;
  font-size: 13px; font-weight: 600; color: var(--muted);
  user-select: none; touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle .grip { color: #4b5563; letter-spacing: -2px; }
.panel-body { padding: 16px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.panel.hidden { display: none; }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.panel p { font-size: 13px; line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
ol.small li { margin-bottom: 3px; }

.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

button, .file-btn {
  font: inherit; font-size: 13px; cursor: pointer;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #21262d; color: var(--text);
}
button:hover, .file-btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.ghost { background: transparent; }
button.wide, .wide { width: 100%; margin-top: 12px; }

.file-btn { display: inline-block; text-align: center; }
.file-btn input { display: none; }

fieldset.tools {
  border: 1px solid var(--border); border-radius: 8px; margin: 14px 0; padding: 10px 12px;
}
fieldset.tools legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
fieldset.tools label { display: block; font-size: 13px; margin: 5px 0; cursor: pointer; }

/* ---- Calibration diagram ---- */
#calibDiagram .corner circle { fill: #30363d; stroke: #8b949e; stroke-width: 1; }
#calibDiagram .corner text {
  fill: #e6edf3; font-size: 9px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central;
}
#calibDiagram .corner.placed circle { fill: #238636; stroke: #2ea043; }
#calibDiagram .corner.next circle { fill: #00e5ff; stroke: #fff; stroke-width: 2; }
#calibDiagram .corner.next text { fill: #001018; }

/* ---- Offside report ---- */
.verdict { font-size: 15px; font-weight: 700; padding: 12px; border-radius: 8px; margin: 12px 0; }
.verdict.good { background: rgba(35,134,54,0.18); border: 1px solid #238636; }
.verdict.bad  { background: rgba(248,81,73,0.18); border: 1px solid #f85149; }
.detail { font-size: 13px; line-height: 1.6; color: var(--muted); }
.warn { font-size: 12px; color: #e3b341; background: rgba(227,179,65,0.1);
  border: 1px solid rgba(227,179,65,0.4); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }

@media (max-width: 640px) {
  .controls { left: 8px; right: 8px; width: auto; top: auto; bottom: 8px;
    max-height: 55vh; }
}
