:root {
  --bg: #0b1020;
  --panel: rgba(15, 23, 42, 0.92);
  --panel2: rgba(30, 41, 59, 0.96);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --line: rgba(148, 163, 184, 0.25);
  --accent: #38bdf8;
  --danger: #fb7185;
  --ok: #34d399;
  --warning: #fbbf24;
  --shadow: 0 18px 40px rgba(0,0,0,0.35);
  --radius: 18px;
}

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

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}

.app {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 12px 0 18px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.title {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: #F7931A;
}

.help-button {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  flex: 0 0 22px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid rgba(247,147,26,0.72);
  border-radius: 999px;
  background: rgba(247,147,26,0.14);
  color: #F7931A;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
  padding: 0;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(6px);
}

.help-dialog {
  position: relative;
  width: min(100%, 420px);
  padding: 20px 18px 18px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.98);
  box-shadow: var(--shadow);
}

.help-dialog h2 {
  margin: 0 34px 12px 0;
  font-size: 18px;
  line-height: 1.2;
}

.help-dialog ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.help-dialog li + li {
  margin-top: 8px;
}

.help-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.status {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  max-width: 55%;
}

.map-card {
  position: relative;
  width: 100%;
  height: min(68vh, 620px);
  min-height: 430px;
  overflow: hidden;
  border-radius: 24px;
  background: #111827;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  touch-action: none;
  user-select: none;
}

.map-mode-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  padding: 1px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255,255,255,0.16);
  backdrop-filter: blur(8px);
}

.map-mode-button {
  width: 28px;
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: visible;
}

.map-mode-button.heading {
  color: #111827;
  background: #F7931A;
}

.map-mode-button.north {
  color: var(--muted);
  background: transparent;
}

#mapImage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transform-origin: center center;
}

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background:
    linear-gradient(rgba(15,23,42,0.84), rgba(15,23,42,0.84)),
    repeating-linear-gradient(0deg, rgba(148,163,184,0.12) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(90deg, rgba(148,163,184,0.12) 0 1px, transparent 1px 42px);
  pointer-events: none;
}

.map-loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid rgba(255,255,255,0.22);
  border-top-color: var(--accent);
  animation: spin 0.85s linear infinite;
}

.map-loading-title {
  font-size: 15px;
  font-weight: 750;
}

.map-loading-text {
  max-width: 260px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.map-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.h3-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.h3-cell {
  fill: transparent;
  stroke: rgba(247, 147, 26, 0.38);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.h3-domain-area {
  fill-opacity: 0.18;
  stroke: #ff0000;
  stroke-opacity: 1;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.h3-domain-area.spot-allowed {
  fill-opacity: 0.14;
  stroke: rgba(52, 211, 153, 0.92);
  stroke-width: 2;
}

.h3-domain-area.spot-blocked {
  fill-opacity: 0.22;
  stroke: #ff0000;
  stroke-width: 3;
}

.map-toast {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 20;
  max-width: min(86%, 360px);
  transform: translateX(-50%);
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 8px;
  background: rgba(15,23,42,0.92);
  color: #ffffff;
  box-shadow: 0 12px 28px rgba(0,0,0,0.28);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

.map-toast.warning {
  border-color: rgba(247,147,26,0.72);
  background: rgba(65,42,14,0.94);
}

.user-dot {
  position: absolute;
  z-index: 2;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%) rotate(var(--user-heading, 0deg));
  transform-origin: 50% 50%;
  pointer-events: none;
}

.user-dot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 2px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 24px solid #ffffff;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,0.36));
}

.user-dot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 7px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 17px solid #0ea5e9;
}

.object-marker {
  position: absolute;
  z-index: 2;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  display: grid;
  place-items: center;
}

.object-marker::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--warning);
  border: 2px solid white;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

.object-marker.selected::before {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(251,113,133,0.22), 0 4px 14px rgba(0,0,0,0.4);
}

.install-marker {
  position: absolute;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -100%);
  pointer-events: none;
  display: grid;
  place-items: center;
}

.install-marker::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--ok);
  border: 2px solid white;
  box-shadow: 0 0 0 6px rgba(52,211,153,0.22), 0 4px 14px rgba(0,0,0,0.4);
}

.install-marker::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: white;
  position: absolute;
  top: 9px;
}

.panel {
  margin-top: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-title {
  font-size: 14px;
  font-weight: 750;
}

.panel > .panel-title {
  margin-bottom: 10px;
}

.panel-coords {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
  max-width: 62%;
}

.ar-control-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 14px;
  margin-bottom: 12px;
}

.ar-control-stack {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.start-ar-button {
  width: 100%;
  min-height: 54px;
}

.posture-canvas {
  width: 140px;
  height: 140px;
  display: block;
  flex: 0 0 auto;
  margin: 0;
  border-radius: 999px;
  background: rgba(15,23,42,0.72);
  border: 1px solid rgba(148,163,184,0.25);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: var(--muted);
  font-size: 12px;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.38);
  background: rgba(15,23,42,0.7);
  color: white;
  padding: 0 11px;
  font-size: 15px;
  outline: none;
}

textarea {
  min-height: 92px;
  padding: 10px 11px;
  line-height: 1.35;
  resize: vertical;
}

input:disabled {
  color: #dbeafe;
  opacity: 0.9;
}

input.limit-reached, textarea.limit-reached {
  background: rgba(251, 191, 36, 0.22);
  border-color: rgba(251, 191, 36, 0.85);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.12);
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

input[type="color"] {
  min-height: 42px;
  padding: 4px;
  cursor: pointer;
}

.text-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
  align-items: end;
}

.drawing-canvas {
  width: 100%;
  aspect-ratio: 32 / 27;
  display: block;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.42);
  background:
    linear-gradient(45deg, rgba(255,255,255,0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.08) 75%),
    rgba(15,23,42,0.72);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  touch-action: none;
}

.drawing-options {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(76px, 0.75fr) minmax(76px, 0.75fr);
  gap: 10px;
  margin-top: 10px;
  align-items: end;
}

.drawing-options button {
  min-height: 42px;
}

.hidden-file-input {
  display: none;
}

.drawing-placement-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
  align-items: end;
}

.check-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.38);
  background: rgba(15,23,42,0.7);
  color: var(--text);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(15,23,42,0.7);
  border: 1px solid rgba(148, 163, 184, 0.28);
}

button.segment {
  min-height: 38px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

button.segment.active {
  background: var(--accent);
  color: #03111f;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.actions button {
  width: 100%;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  font-weight: 750;
  color: #03111f;
  background: var(--accent);
  padding: 0 14px;
  cursor: pointer;
}

button.secondary {
  background: #94a3b8;
}

button.danger {
  background: var(--danger);
  color: white;
}

button.ok {
  background: var(--ok);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.message {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.hidden {
  display: none !important;
}

.ar-view {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: black;
}

#arCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.exit-ar {
  position: fixed;
  z-index: 1001;
  top: calc(env(safe-area-inset-top) + 14px);
  right: 14px;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: transparent;
  color: white;
  border: 0;
  font-size: 22px;
}

.ar-note {
  position: fixed;
  z-index: 1001;
  left: 14px;
  right: 72px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(15,23,42,0.84);
  color: white;
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.22);
}

@media (max-width: 390px) {
  .drawing-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
