/* Ruler Edge Elements */
.ruler-canvas {
  position: absolute;
  z-index: 20;
  display: none;
  background: var(--ruler-bg);
}

#ruler-top {
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  border-bottom: 1px solid var(--ruler-border);
}

#ruler-bottom {
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  border-top: 1px solid var(--ruler-border);
}

#ruler-left {
  top: 0;
  left: 0;
  bottom: 0;
  width: 48px;
  border-right: 1px solid var(--ruler-border);
}

#ruler-right {
  top: 0;
  right: 0;
  bottom: 0;
  width: 48px;
  border-left: 1px solid var(--ruler-border);
}

/* Surface Area */
#surface {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-canvas);
  overflow: hidden;
  user-select: none;
  touch-action: none;
  transition: top 0.2s ease;
}

@media (max-width: 820px) {
  #surface {
    top: 86px;
  }
}

/* Fullscreen Mode: True edge-to-edge display */
:fullscreen #surface,
:-webkit-full-screen #surface,
body.is-fullscreen #surface {
  top: 0 !important;
  height: 100vh !important;
}

/* In fullscreen, float navbar cleanly below the top ruler (top: 56px) as a compact HUD */
:fullscreen #navbar,
:-webkit-full-screen #navbar,
body.is-fullscreen #navbar {
  position: fixed;
  top: 56px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  transition: opacity 0.2s ease, transform 0.2s ease;
  opacity: 0.95;
  background: var(--color-canvas);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-xl), 0 0 0 1px var(--color-hairline);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  z-index: 100;
  border: 1px solid var(--color-hairline);
}

:fullscreen #navbar:hover,
:-webkit-full-screen #navbar:hover,
body.is-fullscreen #navbar:hover {
  opacity: 1;
}

/* Crosshair Elements */
.crosshair-line {
  position: absolute;
  pointer-events: none;
  display: none;
  z-index: 15;
}

#crosshair-h {
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(37, 99, 235, 0.6);
}

#crosshair-v {
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(37, 99, 235, 0.6);
}

/* Guide Lines */
.guide-line {
  position: absolute;
  background: rgba(37, 99, 235, 0.85);
  z-index: 14;
  cursor: grab;
}

.guide-line.horizontal {
  left: 0;
  right: 0;
  height: 2px;
  border-top: 1px dashed #ffffff;
}

.guide-line.vertical {
  top: 0;
  bottom: 0;
  width: 2px;
  border-left: 1px dashed #ffffff;
}

.guide-badge {
  position: absolute;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

/* Delta Measurement Box between guides */
.guide-delta-badge {
  position: absolute;
  background: var(--color-accent);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 16;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Cursor Readout Pill */
#readout {
  position: absolute;
  pointer-events: none;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-family: var(--font-mono);
  color: #ffffff;
  background: #111827;
  white-space: nowrap;
  transform: translate(14px, -50%);
  display: none;
  z-index: 30;
  box-shadow: var(--shadow-md);
}

/* Floating 360° Rotatable Ruler */
#floating-ruler {
  position: absolute;
  top: 25%;
  left: 20%;
  background: var(--ruler-bg);
  border: 1px solid var(--ruler-border);
  border-radius: 6px;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,0.08);
  z-index: 25;
  display: none;
  cursor: move;
  transform-origin: center center;
  box-sizing: content-box;
}

#floating-ruler-canvas {
  display: block;
  border-radius: 5px;
}

.ruler-rotate-handle {
  position: absolute;
  right: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  background: var(--color-accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: var(--shadow-md);
  font-size: 12px;
}

.ruler-close-handle {
  position: absolute;
  left: -12px;
  top: -12px;
  width: 24px;
  height: 24px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  font-size: 11px;
  border: 2px solid #fff;
}

/* 2D Caliper Box */
#caliper-box {
  position: absolute;
  top: 30%;
  left: 35%;
  width: 220px;
  height: 160px;
  border: 2px dashed var(--color-accent);
  background: rgba(37, 99, 235, 0.06);
  border-radius: 6px;
  z-index: 22;
  display: none;
  cursor: move;
}

.caliper-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 2px solid var(--color-accent);
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
}
.caliper-handle.tl { top: -7px; left: -7px; cursor: nwse-resize; }
.caliper-handle.tr { top: -7px; right: -7px; cursor: nesw-resize; }
.caliper-handle.bl { bottom: -7px; left: -7px; cursor: nesw-resize; }
.caliper-handle.br { bottom: -7px; right: -7px; cursor: nwse-resize; }
.caliper-handle.tc { top: -7px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.caliper-handle.bc { bottom: -7px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.caliper-handle.lc { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.caliper-handle.rc { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.caliper-info {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(4px);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-family: var(--font-mono);
  white-space: nowrap;
  pointer-events: none;
  text-align: center;
}

/* 360° Circular Protractor Overlay */
.protractor-overlay {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 28;
  user-select: none;
  touch-action: none;
}

.protractor-header {
  position: absolute;
  top: -42px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(6px);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.protractor-title {
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
}

.protractor-badge {
  background: var(--color-accent);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.protractor-close {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
}
.protractor-close:hover {
  color: #ef4444;
}

.protractor-stats {
  position: absolute;
  bottom: -36px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(6px);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-family: var(--font-mono);
  color: #9ca3af;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.protractor-stats strong {
  color: #ffffff;
}

/* Preset Reference Object Box */
.preset-object-box {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(37, 99, 235, 0.15);
  border: 2px solid var(--color-accent);
  z-index: 26;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(2px);
}

.preset-object-content {
  text-align: center;
  pointer-events: none;
  padding: 6px;
}

.preset-title {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-ink);
}

.preset-dim {
  display: block;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--color-mute);
}

.preset-close {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  background: #ef4444;
  color: #ffffff;
  border-radius: 50%;
  border: 2px solid #ffffff;
  font-size: 11px;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Precision Loupe Magnifier Lens */
.precision-loupe {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid var(--color-accent);
  box-shadow: var(--shadow-2xl), 0 0 0 2px rgba(255,255,255,0.2);
  z-index: 35;
  pointer-events: none;
  overflow: hidden;
  background: #09090b;
}

.loupe-crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
}
.loupe-crosshair::before, .loupe-crosshair::after {
  content: '';
  position: absolute;
  background: #ef4444;
}
.loupe-crosshair::before {
  top: 5px;
  left: 0;
  right: 0;
  height: 2px;
}
.loupe-crosshair::after {
  left: 5px;
  top: 0;
  bottom: 0;
  width: 2px;
}

.loupe-coords {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
}

/* Preset selection modal list */
.preset-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-hairline);
  background: var(--color-canvas);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 8px;
  transition: all 0.15s ease;
  text-align: left;
}
.preset-btn:hover {
  background: var(--color-canvas-soft);
  border-color: var(--color-hairline-strong);
}
.preset-btn-info strong {
  display: block;
  font-size: 13px;
  color: var(--color-ink);
}
.preset-btn-info span {
  font-size: 11px;
  color: var(--color-mute);
  font-family: var(--font-mono);
}
.preset-btn-action {
  font-size: 12px;
  color: var(--color-accent);
  font-weight: 600;
}
