/* PanHandler for the web.
   Look and feel ported from the iOS app: black camera, tinted reticle, translucent mode
   pill with icon-over-label, spring transitions. */

:root {
  color-scheme: dark;
  --bg: #000;
  --surface: #141416;
  --surface-2: #1f1f22;
  --border: #2c2c31;
  --fg: #fff;
  --muted: #8e8e93;
  --accent: #4c9dff;
  --ok: #34c759;
  --warn: #ff9f0a;

  /* Session theme, overwritten per session from theme.rs */
  --crosshair: #3b82f6;
  --crosshair-glow: #60a5fa;
  --bubble: #f59e0b;
  --bubble-glow: #fbbf24;
  --shutter: #ec4899;
  --shutter-glow: #f472b6;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  height: 100%; margin: 0; overflow: hidden;
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.screen {
  position: fixed; inset: 0;
  display: none; flex-direction: column;
  padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
}
.screen.active { display: flex; animation: screen-in 0.42s var(--spring) both; }

@keyframes screen-in {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------------------------------------------------------------- intro */

#screen-quote { justify-content: center; align-items: center; padding: 32px; }
.quote-inner { max-width: 30ch; text-align: center; animation: fade-up 0.8s var(--spring) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

#quote-text {
  margin: 0;
  font-size: clamp(21px, 5.4vw, 29px);
  font-weight: 500; line-height: 1.38; letter-spacing: -0.015em;
}
.quote-author { margin: 16px 0 0; color: var(--muted); font-size: 14px; }
.tap-hint {
  position: absolute; bottom: calc(38px + var(--safe-bottom));
  color: var(--muted); font-size: 13px; animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---------------------------------------------------------------- camera */

.camera { background: #000; }
#screen-camera { display: none; }
#screen-camera.active { display: block; }
.camera-feed { position: absolute; inset: 0; background: radial-gradient(circle at 50% 42%, #1b1b20 0%, #000 72%); }

.reticle { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.reticle svg { width: 100%; height: 100%; }
.reticle line {
  stroke: var(--crosshair);
  stroke-width: 1.4;
  opacity: 0.85;
  vector-effect: non-scaling-stroke;
}
.reticle::after {
  /* centre crosshair */
  opacity: 0.0;
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 1.5px solid var(--crosshair);
  border-radius: 50%;
  box-shadow: 0 0 14px var(--crosshair-glow);
}

.bubble-track {
  /* The app's bubble moves in two axes inside a circle, so the track is a disc. */
  position: absolute; left: 50%; top: 50%;
  width: 116px; height: 116px; margin: 34px 0 0 -58px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 68%);
  touch-action: none;
  cursor: grab;
}
.bubble-track::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 1px; height: 22px; margin: -11px 0 0 -0.5px;
  background: rgba(255, 255, 255, 0.25);
}
.bubble {
  position: absolute; top: 50%; left: 50%;
  width: 20px; height: 20px; margin: -10px 0 0 -10px;
  border-radius: 50%;
  background: var(--bubble);
  box-shadow: 0 0 16px var(--bubble-glow);
  transition: transform 0.08s linear, box-shadow 0.15s ease;
  will-change: transform;
}

.guidance, .lookdown {
  position: absolute; left: 0; right: 0;
  text-align: center; font-size: 15px; font-weight: 650;
  color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  opacity: 0; transition: opacity 0.35s ease;
  pointer-events: none;
}
.guidance { top: 22%; }
.guidance.show, .lookdown.show { opacity: 1; }
.lookdown { top: 40%; font-size: 19px; }

.bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 52px; }
.camera-bar { position: absolute; top: var(--safe-top); left: 0; right: 0; z-index: 3; }
.camera-title { flex: 1; text-align: center; font-size: 16px; font-weight: 650; }

.icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-size: 17px; line-height: 1;
  transition: transform 0.18s var(--spring), background 0.18s ease;
}
.icon:active { transform: scale(0.9); background: rgba(255, 255, 255, 0.24); }
.ghost { background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(10px); }

.shutter-row {
  position: absolute; bottom: calc(26px + var(--safe-bottom)); z-index: 3;
  left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-around;
  padding: 0 34px;
}
.library input, .shutter input { position: absolute; opacity: 0; width: 0; height: 0; }

.shutter {
  position: relative; width: 76px; height: 76px;
  display: grid; place-items: center;
}
.shutter-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.92);
}
.shutter-core {
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--shutter);
  box-shadow: 0 0 22px var(--shutter-glow);
  transition: transform 0.14s var(--spring);
}
.shutter:active .shutter-core { transform: scale(0.88); }

/* ---------------------------------------------------------------- canvas */

.canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }

.label {
  position: absolute; transform: translate(-50%, -50%);
  padding: 5px 10px; border-radius: 9px;
  background: rgba(0, 0, 0, 0.74);
  font-size: 12.5px; font-weight: 700;
  white-space: pre; text-align: center;
  backdrop-filter: blur(8px);
  pointer-events: none;
  animation: label-in 0.32s var(--spring) both;
}
@keyframes label-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.86); } }

/* ---------------------------------------------------------------- calibrate */

.ref-circle {
  position: absolute; left: 50%; top: 33%;
  width: 260px; height: 260px; margin: -130px 0 0 -130px;
  border-radius: 50%;
  border: 2px solid var(--crosshair);
  box-shadow: 0 0 30px var(--crosshair-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  pointer-events: none;
  animation: ref-breathe 3.4s ease-in-out infinite;
}
@keyframes ref-breathe {
  0%, 100% { box-shadow: 0 0 26px var(--crosshair-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.22); }
  50% { box-shadow: 0 0 42px var(--crosshair-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
}
.ref-inner {
  position: absolute; inset: 30px; border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.28);
}

.cal-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
}
.cal-coin {
  flex: 1; text-align: center;
  padding: 9px 16px; border-radius: 22px;
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(10px);
}
.cal-coin span { display: block; font-size: 17px; font-weight: 700; }
.cal-coin small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }

.cal-status {
  position: absolute; left: 0; right: 0; bottom: 84px;
  text-align: center; font-size: 13px; color: var(--muted);
  margin: 0; transition: color 0.2s ease;
}
.cal-status.found { color: var(--ok); }
.cal-status.failed { color: var(--warn); }
.cal-zoom-label {
  position: absolute; right: 18px; bottom: 84px;
  margin: 0; font-size: 13px; font-weight: 700; color: rgba(255, 255, 255, 0.75);
}

.cal-footer { padding: 12px 18px calc(18px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
.lockin {
  width: 100%; padding: 17px;
  border-radius: 16px;
  background: var(--crosshair); color: #04121f;
  font-size: 21px; font-weight: 900; letter-spacing: 0.14em;
  transition: transform 0.16s var(--spring), opacity 0.2s ease;
}
.lockin:active { transform: scale(0.97); }
.lockin:disabled { opacity: 0.45; }

/* ---------------------------------------------------------------- measure */

.measure-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
}
.calibrated-chip {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: 20px;
  background: rgba(52, 199, 89, 0.2);
  color: var(--ok); font-size: 12.5px; font-weight: 650;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.calibrated-chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); flex: 0 0 auto;
}

.measure-footer {
  display: grid; gap: 9px;
  padding: 9px 11px calc(11px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}

.mode-row {
  display: flex; gap: 2px;
  padding: 2px; border-radius: 10px;
  background: rgba(120, 120, 128, 0.25);
  touch-action: pan-x;
}
.mode {
  flex: 1;
  display: grid; justify-items: center; gap: 2px;
  padding: 6px 2px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.45);
  transition: background 0.22s var(--spring), color 0.22s ease, transform 0.22s var(--spring);
}
.mode svg {
  width: 21px; height: 21px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.mode span { font-size: 10px; font-weight: 700; }
.mode[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.95);
  color: var(--mode-color, #3b82f6);
  box-shadow: 0 0 12px var(--mode-glow, transparent);
  transform: translateY(-1px);
}

.action-row { display: flex; gap: 7px; }
.action {
  flex: 1;
  padding: 11px 8px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12.5px; font-weight: 650;
  transition: transform 0.16s var(--spring), background 0.2s ease;
}
.action:active { transform: scale(0.95); background: rgba(255, 255, 255, 0.2); }
.primary-action { background: rgba(52, 199, 89, 0.9); color: #04120a; }

/* ---------------------------------------------------------------- sheets */

.sheet {
  position: fixed; inset: 0; display: none;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  animation: fade-in 0.2s ease both;
}
.sheet.open { display: flex; }
@keyframes fade-in { from { opacity: 0; } }

.sheet-inner {
  width: 100%; max-height: 84vh;
  display: flex; flex-direction: column;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  animation: sheet-up 0.36s var(--spring) both;
}
@keyframes sheet-up { from { transform: translateY(28px); opacity: 0; } }
.sheet-inner.compact { max-height: none; }

.sheet-head { display: flex; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; }

.search {
  width: 100%; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); margin-bottom: 10px;
}
.search::placeholder { color: var(--muted); }

.coin-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.coin-group {
  position: sticky; top: 0; padding: 10px 4px 6px;
  background: var(--surface); color: var(--muted);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.coin-row {
  display: flex; width: 100%; align-items: center; gap: 12px;
  padding: 12px 10px; border-radius: 11px; text-align: left;
  transition: background 0.15s ease;
}
.coin-row:active { background: var(--surface-2); }
.coin-row .name { flex: 1; font-weight: 600; }
.coin-row .dia { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.coin-empty { padding: 22px 10px; color: var(--muted); text-align: center; }

.help-list { margin: 0; padding-left: 20px; color: #d7d7dc; }
.help-list li { margin-bottom: 11px; }
.help-list strong { color: #fff; }

.depth-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 4px 0 14px; font-size: 13px; color: var(--muted);
}
.depth-row input {
  width: 110px; padding: 10px 12px; text-align: right;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
}
.sheet-actions { display: grid; gap: 8px; }

.export-readout {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px; margin-bottom: 14px;
}
.export-readout div { padding: 10px 12px; border-radius: 11px; background: var(--surface-2); }
.export-readout span {
  display: block; color: var(--muted); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.export-readout strong { display: block; margin-top: 3px; font-variant-numeric: tabular-nums; }

.export-buttons { display: grid; gap: 8px; }
.export-buttons .action { padding: 13px; font-size: 14px; }

.command {
  margin: 14px 0 0; padding: 11px 13px;
  border-radius: 11px; background: #08080a; border: 1px solid var(--border);
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); white-space: pre-wrap; word-break: break-all;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------- live camera */

.camera-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
  background: #000;
}
.camera-video[hidden] { display: none; }

.auto-badge {
  position: absolute; top: calc(var(--safe-top) + 58px); right: 16px;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 12px;
  background: rgba(52, 199, 89, 0.9);
  color: #04120a; font-size: 11px; font-weight: 800; letter-spacing: 0.08em;
  z-index: 4;
  animation: label-in 0.3s var(--spring) both;
}
.auto-badge[hidden] { display: none; }
.auto-badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #04120a;
  animation: pulse 1s ease-in-out infinite;
}

/* ---------------------------------------------------------------- map scale */

.map-row {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr auto;
  gap: 6px; align-items: center;
  margin-bottom: 14px;
}
.map-row input, .map-row select {
  padding: 11px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  min-width: 0;
}
.map-eq { color: var(--muted); font-weight: 700; }

/* ---------------------------------------------------------------- help sections */

.help-section {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}
.help-section:first-of-type { border-top: 0; }
.help-section summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 14px;
  padding: 4px 0;
  list-style: none;
}
.help-section summary::-webkit-details-marker { display: none; }
.help-section summary::before {
  content: '›';
  display: inline-block;
  width: 16px;
  color: var(--muted);
  transition: transform 0.2s var(--spring);
}
.help-section[open] summary::before { transform: rotate(90deg); }
.help-section ul {
  margin: 8px 0 4px 16px;
  padding-left: 8px;
  color: #d7d7dc;
  font-size: 13.5px;
}
.help-section li { margin-bottom: 7px; }
.help-section strong { color: #fff; }

/* ---------------------------------------------------------------- photo type */

.type-row {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 16px 14px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-align: left;
  margin-bottom: 9px;
  transition: border-color 0.2s ease, transform 0.16s var(--spring);
}
.type-row:active { transform: scale(0.985); border-color: var(--accent); }
.type-icon { font-size: 24px; }
.type-text { display: grid; gap: 2px; }
.type-text strong { font-size: 15px; }
.type-text small { color: var(--muted); font-size: 12.5px; }
