:root {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.88);
  --panel-solid: #111827;
  --line: rgba(148, 163, 184, 0.28);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-2: #16a34a;
  --danger: #f43f5e;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Cairo", system-ui, sans-serif;
  overflow: hidden;
}

button, input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.setup {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(circle at 20% 10%, rgba(34, 197, 94, 0.18), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(56, 189, 248, 0.12), transparent 40%),
    var(--bg);
}

.setup-card {
  width: min(440px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}

.setup-logo {
  display: block;
  margin-bottom: 12px;
}

.setup h1 {
  margin: 0 0 8px;
  font-size: 1.55rem;
}

.setup p, .setup label {
  color: var(--muted);
  line-height: 1.7;
}

.setup label {
  display: block;
  margin: 18px 0 8px;
  color: var(--text);
  font-weight: 700;
}

.setup input {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  border-radius: 14px;
  padding: 14px 12px;
  font-size: 16px;
}

.btn-primary {
  background: linear-gradient(180deg, #34d399, var(--accent-2));
  color: #052e16;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
}

.setup .btn-primary {
  width: 100%;
  margin-top: 14px;
  min-height: 48px;
}

.help {
  margin-top: 16px;
  color: var(--muted);
}

.help ol {
  padding-right: 18px;
  line-height: 1.8;
}

.app {
  position: fixed;
  inset: 0;
}

#map {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: calc(168px + var(--safe-bottom));
}

.leaflet-container {
  background: #0b1220;
  font-family: inherit;
}

.leaflet-div-icon {
  background: transparent;
  border: none;
}

.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.7) !important;
  color: #cbd5e1;
  font-size: 10px;
}

.img-meta {
  position: absolute;
  right: 10px;
  left: 10px;
  bottom: calc(176px + var(--safe-bottom));
  z-index: 1100;
  pointer-events: none;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #e2e8f0;
  text-align: center;
  box-shadow: var(--shadow);
}

.vertex-icon span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #052e16;
  font-weight: 800;
  font-size: 11px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.topbar {
  position: absolute;
  top: calc(10px + var(--safe-top));
  right: 10px;
  left: 10px;
  z-index: 1100;
  display: grid;
  gap: 8px;
}

.search {
  display: flex;
  gap: 8px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 6px;
  box-shadow: var(--shadow);
}

.search input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
  min-width: 0;
}

.search button,
.icon-btn,
.tool,
.draw-actions button,
.color-toggle {
  border: 0;
  background: #1e293b;
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
}

.search button {
  padding: 0 14px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
}

.icon-btn {
  width: 42px;
  height: 42px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.search-results {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.search-results button {
  display: block;
  width: 100%;
  text-align: right;
  background: transparent;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px;
  cursor: pointer;
}

.search-results button:last-child {
  border-bottom: 0;
}

.result {
  position: absolute;
  right: 10px;
  left: 10px;
  top: calc(108px + var(--safe-top));
  z-index: 1100;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

.result-kicker {
  font-weight: 800;
}

.result-extra, .empty, .toast {
  color: var(--muted);
}

.result-area {
  font-size: 1.8rem;
  font-weight: 800;
  color: #86efac;
  margin: 4px 0;
}

.toolbar {
  position: absolute;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 1100;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, rgba(11, 18, 32, 0.94) 28%);
}

.pwa-copy {
  text-align: center;
  color: #94a3b8;
  font-size: 11px;
  line-height: 1.55;
  padding: 6px 8px 0;
}

.pwa-copy p { margin: 0; }

.pwa-copy strong {
  color: #e2e8f0;
  letter-spacing: 0.04em;
}

.pwa-install-bar {
  text-align: center;
  padding: 10px 10px 8px;
  background: #14532d;
  border: 1px solid rgba(187, 247, 208, 0.35);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.pwa-install-bar[hidden] { display: none !important; }

.pwa-install {
  display: inline-block;
  margin: 0;
  border: 0;
  background: #bbf7d0;
  color: #052e16;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

#pwa-install-hint {
  margin: 6px 0 0;
  color: #bbf7d0;
  font-size: 12px;
  font-weight: 700;
}

.tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  overflow: visible;
  padding-bottom: 2px;
}

.tool {
  min-width: 0;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 4px;
  text-align: center;
  line-height: 1.25;
}

.tool.active {
  background: #14532d;
  border-color: var(--accent);
  color: #bbf7d0;
}

.draw-bar {
  display: grid;
  gap: 6px;
  margin-bottom: 6px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 8px;
}

.draw-bar-meta {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}

.color-toggle {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #fff;
  flex: 0 0 auto;
  overflow: hidden;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.45);
}

.color-swatch {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--c, #22c55e);
}

.draw-stats {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  color: #86efac;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-picker {
  position: absolute;
  inset-inline-start: 0;
  bottom: calc(100% + 6px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  flex: 0 0 auto;
  padding: 0;
  cursor: pointer;
  background: var(--c);
}

.color-dot.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.55);
}

.color-custom {
  width: 18px;
  height: 18px;
  border: 0;
  padding: 0;
  background: transparent;
  flex: 0 0 auto;
  cursor: pointer;
}

.layer-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

.layer-colors .color-dot {
  width: 24px;
  height: 24px;
}

.draw-actions {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

#btn-right-angle.active,
.tool.recording {
  background: #14532d;
  border: 1px solid var(--accent);
  color: #bbf7d0;
}

.draw-actions button {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  border-radius: 10px;
}

#btn-finish {
  flex: 1.25;
}

.ghost {
  background: transparent !important;
  border: 1px solid var(--line) !important;
  color: var(--text);
}

.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1200;
}

.sheet {
  position: absolute;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 1300;
  max-height: 72%;
  background: #0f172a;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 8px 16px calc(16px + var(--safe-bottom));
  transform: translateY(110%);
  transition: transform 0.25s ease;
  box-shadow: var(--shadow);
}

.sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 48px;
  height: 5px;
  border-radius: 99px;
  background: #334155;
  margin: 6px auto 12px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.sheet-head .ghost {
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

.sheet-actions {
  display: flex;
  gap: 6px;
}

.layer-list {
  overflow: auto;
  max-height: 52vh;
}

.help-sheet {
  max-height: 82%;
  overflow: auto;
}

.guide-steps {
  margin: 0;
  padding: 0 0 8px;
  list-style: none;
  counter-reset: gstep;
  display: grid;
  gap: 10px;
}

.guide-steps li {
  counter-increment: gstep;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 0.92rem;
  line-height: 1.6;
  color: #e2e8f0;
}

.guide-steps li::before {
  content: counter(gstep);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #052e16;
  font-weight: 800;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layer-item {
  display: block;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.layer-main {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 10px;
  align-items: center;
}

.layer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.swatch {
  width: 12px;
  height: 36px;
  border-radius: 99px;
}

.layer-item strong {
  display: block;
}

.layer-item small {
  color: var(--muted);
}

.layer-item .row-actions {
  display: flex;
  gap: 6px;
}

.layer-tools button,
.layer-item .row-actions button {
  border: 1px solid var(--line);
  background: #1e293b;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 700;
}

.map-label {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  width: max-content;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.map-label.area {
  background: #14532d;
  border-color: #22c55e;
  font-size: 13px;
  padding: 4px 10px;
}

.shot-sheet {
  max-height: none;
  z-index: 1350;
}

.shot-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.shot-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.shot-option {
  min-height: 52px;
  border: 1px solid var(--line);
  background: #1e293b;
  color: var(--text);
  border-radius: 14px;
  padding: 10px 8px;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
}

.shot-option.active {
  background: #14532d;
  border-color: var(--accent);
  color: #bbf7d0;
}

.shot-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
}

.shot-actions .btn-primary,
.shot-actions .ghost {
  min-height: 48px;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(118px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 1400;
  background: #111827;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  max-width: 90%;
}

.gm-style img {
  max-width: none;
}
