:root {
  color-scheme: dark;
  --bg: rgba(10, 14, 18, 0.9);
  --card: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.12);
  --text: #e8eef4;
  --muted: #93a3b3;
  --accent: #3db8f5;
  --danger: #ffb4b4;
  --ok: #7dcea0;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0b1014;
  color: var(--text);
  font-family: var(--font);
}

#map {
  position: absolute;
  inset: 0;
  background: #0b1014;
}

.panel {
  position: absolute;
  z-index: 1100;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: min(360px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.sub, .count {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.sheet-hint { display: none; }

.drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 76px;
  border: 1px dashed rgba(61, 184, 245, 0.65);
  border-radius: 12px;
  background: rgba(61, 184, 245, 0.06);
  cursor: pointer;
  text-align: center;
  padding: 10px;
  overflow: hidden;
}

/* A full-size transparent input is what iOS Safari will actually open.
   display:none and an accept=".gpx" filter both block the Files picker. */
.drop input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}

.drop-title {
  font-weight: 650;
  color: var(--text);
}

.drop-hint { color: var(--muted); font-size: 0.82rem; }

.drop.over {
  background: rgba(61, 184, 245, 0.18);
  border-color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  font-size: 0.92rem;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-ui {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 99px;
  background: #24303a;
  border: 1px solid var(--line);
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #d5dee6;
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-ui {
  background: #14688f;
  border-color: #3db8f5;
}

.switch input:checked + .switch-ui::after {
  transform: translateX(18px);
  background: #fff;
}

.switch input:indeterminate + .switch-ui::after {
  transform: translateX(9px);
}

.switch input:focus-visible + .switch-ui {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:disabled + .switch-ui { opacity: 0.45; }

.sheet-handle {
  display: none;
}

.btn {
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.btn:hover { background: rgba(255, 255, 255, 0.08); }

.btn.danger {
  color: var(--danger);
  border-color: rgba(239, 107, 107, 0.4);
}

.btn:disabled { opacity: 0.4; cursor: default; }

.labels {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.labels input, .check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.status {
  min-height: 1.1em;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.status.err { color: var(--danger); }
.status.ok { color: var(--ok); }

.list {
  list-style: none;
  margin: 0;
  padding: 0 0 8px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 8px 2px;
}

.card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--c, #fff);
  border-radius: 12px;
  background: var(--card);
  padding: 8px;
}

.card.active { border-color: rgba(61, 184, 245, 0.7); }

.layer, .file-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.layer + .layer { margin-top: 8px; }

.name-block {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}

.meta {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px 2px;
}

.icon:hover { color: var(--text); }
.icon.remove:hover { color: var(--danger); }

.nested {
  list-style: none;
  margin: 8px 0 0;
  padding: 0 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaflet-container { font-family: var(--font); }

@media (max-width: 700px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 55vh;
    max-height: calc(100dvh - 8px);
    border-radius: 18px 18px 0 0;
    padding-top: 4px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    overflow: hidden;
    transition: height 0.22s ease;
  }

  .panel.dragging { transition: none; }

  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 100%;
    height: 36px;
    margin: 0;
    padding: 12px 0 6px;
    border: 0;
    background: transparent;
    cursor: grab;
    touch-action: none;
  }

  .grip {
    width: 48px;
    height: 5px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.42);
  }

  .head { cursor: grab; touch-action: none; }
  .head .sub:not(.sheet-hint) { display: none; }
  .sheet-hint { display: block; }

  .layer input,
  .file-head input {
    width: 22px;
    height: 22px;
    flex: none;
  }
}
