:root {
  --bg: #101418;
  --panel: #1b2129;
  --panel2: #232b36;
  --text: #e8edf2;
  --muted: #93a1b0;
  --accent: #2f81f7;
  --accent2: #3fb950;
  --danger: #f85149;
  --radius: 14px;
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }

body { user-select: none; -webkit-user-select: none; }
input, select { user-select: auto; -webkit-user-select: auto; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  position: fixed;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
  overscroll-behavior: none;
}

#canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ---------- readout ---------- */
.readout {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 50%; transform: translateX(-50%);
  background: rgba(20, 26, 33, 0.92);
  border: 1px solid #2c3946;
  border-radius: var(--radius);
  padding: 8px 16px;
  text-align: center;
  max-width: 92vw;
  pointer-events: none;
  backdrop-filter: blur(6px);
}
#readoutMain { font-size: 17px; font-weight: 600; white-space: nowrap; }
#readoutSub  { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- floating add-point button ---------- */
.fab {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: calc(88px + var(--sab));
  width: 66px; height: 66px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 36px;
  line-height: 1;
  z-index: 18;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45), 0 0 0 4px rgba(47,129,247,0.25);
  cursor: pointer;
}
.fab:active { transform: translateX(-50%) scale(0.92); }

/* ---------- banner ---------- */
.banner {
  position: absolute;
  bottom: calc(168px + var(--sab));
  left: 50%; transform: translateX(-50%);
  background: rgba(47, 129, 247, 0.95);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}

/* ---------- welcome ---------- */
.overlay {
  position: absolute; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  padding: 24px;
}
.welcome-card { max-width: 420px; text-align: center; }
.welcome-card h1 { margin: 0 0 8px; font-size: 28px; }
.welcome-card p { color: var(--muted); }
.welcome-card ol { text-align: left; color: var(--muted); line-height: 1.9; margin: 16px auto; display: inline-block; }

/* ---------- toolbar ---------- */
.toolbar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 6px 6px calc(6px + var(--sab));
  background: rgba(16, 20, 24, 0.94);
  border-top: 1px solid #2c3946;
  display: flex;
  justify-content: space-around;
  gap: 4px;
  z-index: 20;
  backdrop-filter: blur(8px);
}
.tb {
  flex: 1;
  min-width: 0;
  min-height: 54px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  cursor: pointer;
}
.tb span { font-size: 10.5px; color: var(--muted); }
.tb.active { background: var(--panel2); }
.tb.active span { color: var(--accent); }
.tb.accent { background: var(--accent); }
.tb.accent span { color: #dbe9ff; }
.tb:disabled { opacity: 0.35; }

/* ---------- zoom ---------- */
.zoomctl {
  position: absolute;
  right: 10px;
  bottom: calc(100px + var(--sab));
  display: flex; flex-direction: column;
  gap: 8px;
  z-index: 15;
}
.zoomctl button {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid #2c3946;
  background: rgba(27, 33, 41, 0.92);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

/* ---------- buttons / inputs ---------- */
.btn {
  border: 1px solid #2c3946;
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger  { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.big  { font-size: 17px; padding: 14px 22px; width: 100%; }
.btn.wide { width: 100%; }

input, select {
  background: var(--panel2);
  border: 1px solid #2c3946;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px; /* prevents iOS zoom-on-focus */
  width: 100%;
  min-width: 0;
}
label { font-size: 13px; color: var(--muted); flex: 1; display: flex; flex-direction: column; gap: 5px; }

.row { display: flex; gap: 10px; margin: 10px 0; align-items: center; }
.row .btn { flex-shrink: 0; }
.tiny { font-size: 12px; color: var(--muted); }
.center { text-align: center; }

/* ---------- popup (calibration) ---------- */
/* anchored near the top so the mobile keyboard never covers it */
.popup {
  position: absolute;
  left: 50%; top: calc(env(safe-area-inset-top, 0px) + 64px);
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid #2c3946;
  border-radius: var(--radius);
  padding: 18px;
  width: min(92vw, 360px);
  z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.popup h3 { margin: 0 0 4px; }
.popup .row .btn { flex: 1; }

/* ---------- settings sheet ---------- */
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 29;
}
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(24px + var(--sab));
  z-index: 30;
}
.sheet-handle {
  width: 42px; height: 4px;
  background: #3a4654;
  border-radius: 2px;
  margin: 6px auto 10px;
}
.sheet h2 { margin: 4px 0 10px; font-size: 19px; }
.sheet section {
  background: var(--bg);
  border: 1px solid #242e3a;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.sheet h3 { margin: 2px 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.sheet details { margin-top: 10px; }
.sheet summary { color: var(--accent); font-size: 13.5px; cursor: pointer; padding: 4px 0; }
.pill {
  font-size: 11px; font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: #3a2527; color: var(--danger);
}
.pill.ok { background: #1d3327; color: var(--accent2); }

/* ---------- shape list ---------- */
.shape-list { display: flex; flex-direction: column; gap: 8px; }
.shape-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  border-radius: 10px;
  padding: 9px 12px;
}
.shape-item .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.shape-item .info { flex: 1; min-width: 0; }
.shape-item .nm { font-size: 14px; font-weight: 600; }
.shape-item .ms { font-size: 12px; color: var(--muted); }
.shape-item button {
  background: none; border: none;
  color: var(--muted);
  font-size: 17px;
  padding: 6px;
  cursor: pointer;
}
.shape-empty { color: var(--muted); font-size: 13px; }
