:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #6b7d90;
  --panel: #f9fbfd;
  --panel-soft: #eef3f8;
  --accent: #2f6ea5;
  --accent-strong: #1f4f7c;
  --border: rgba(15, 23, 42, 0.1);
  --shadow-soft: 0 14px 34px rgba(15, 23, 42, 0.13);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-pill: 999px;
  --ambient-grid: rgba(71, 118, 161, 0.05);
  --ambient-topo: rgba(148, 163, 184, 0.06);
  --background: radial-gradient(circle at top, #f7fafc 0%, #ecf2f8 38%, #e5edf6 100%);
  --frame-ink: rgba(14, 22, 34, 0.9);
  --frame-edge: rgba(15, 23, 42, 0.22);
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --panel: #101925;
  --panel-soft: #0d1621;
  --accent: #77abd6;
  --accent-strong: #9bc3e4;
  --border: rgba(148, 163, 184, 0.12);
  --shadow-soft: 0 14px 34px rgba(2, 6, 23, 0.42);
  --ambient-grid: rgba(119, 171, 214, 0.07);
  --ambient-topo: rgba(148, 163, 184, 0.05);
  --background: radial-gradient(circle at top, #172336 0%, #101825 46%, #090f18 100%);
  --frame-ink: rgba(8, 12, 19, 0.96);
  --frame-edge: rgba(148, 163, 184, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
}

button,
a {
  font: inherit;
}

button {
  border: 0;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

a {
  color: inherit;
}

.is-hidden {
  display: none !important;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  isolation: isolate;
}

.shell::before,
.shell::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.shell::before {
  background:
    linear-gradient(var(--ambient-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--ambient-grid) 1px, transparent 1px);
  background-size: 56px 56px;
  opacity: 0.55;
  mask-image: linear-gradient(to bottom, transparent, black 14%, black 86%, transparent);
}

.shell::after {
  background:
    radial-gradient(circle at 16% 20%, rgba(59, 130, 246, 0.14), transparent 26%),
    radial-gradient(circle at 80% 18%, rgba(6, 182, 212, 0.12), transparent 22%),
    radial-gradient(circle at 70% 82%, rgba(99, 102, 241, 0.08), transparent 24%),
    radial-gradient(circle at 22% 78%, var(--ambient-topo), transparent 18%);
  filter: blur(24px);
  opacity: 0.9;
}

.shell.is-auth-pending {
  opacity: 1;
}

.shell.is-auth-pending .routes-shell--frame {
  opacity: 0.78;
  filter: saturate(0.88);
}

.shell.is-auth-pending .shell-context__title::after {
  content: " · Loading";
  font-weight: 500;
  color: rgba(226, 232, 240, 0.72);
}

.shell.is-auth-pending .user-menu,
.shell.is-auth-pending .theme-toggle {
  opacity: 0.7;
}

.shell.is-auth-ready {
  opacity: 1;
  transition: opacity 0.24s ease;
}

.shell-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(180deg, rgba(11, 18, 28, 0.88), rgba(14, 22, 34, 0.74));
  backdrop-filter: blur(18px) saturate(1.16);
  -webkit-backdrop-filter: blur(18px) saturate(1.16);
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  box-shadow: 0 18px 34px rgba(2, 6, 23, 0.16);
  color: #e2e8f0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 0.45rem 0.75rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.brand-logo {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 14px rgba(59, 130, 246, 0.28));
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  background: linear-gradient(135deg, #7dd3fc 0%, #60a5fa 40%, #3b82f6 70%, #06b6d4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-tagline {
  display: block;
  color: rgba(226, 232, 240, 0.78);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.shell-context {
  justify-self: center;
  display: grid;
  gap: 2px;
  padding: 0.45rem 0.75rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.12);
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.shell-context__eyebrow {
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.72);
}

.shell-context__title {
  color: #eff6ff;
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  justify-self: end;
  gap: 10px;
  align-items: center;
  position: relative;
}

.shell-header .theme-toggle {
  width: 36px;
  height: 36px;
}

.theme-toggle {
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.18);
  color: #e2e8f0;
  font-size: 1.1rem;
  transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  transform: scale(1.04);
  border-color: rgba(147, 197, 253, 0.38);
}

[data-theme="dark"] .theme-toggle {
  background: rgba(255, 255, 255, 0.06);
}

.map-settings-shell {
  position: relative;
}

.map-settings-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.18);
  color: #e2e8f0;
  font-size: 1rem;
  line-height: 1;
}

.map-settings-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(340px, calc(100vw - 32px));
  display: grid;
  gap: 10px;
  padding: 0.9rem;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(9, 16, 27, 0.96), rgba(11, 19, 31, 0.94));
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 26px 48px rgba(2, 6, 23, 0.42);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 140;
}

.map-settings-popover.basemap-picker-host--all > :not(.basemap-picker) {
  display: none !important;
}

.map-settings-field {
  display: grid;
  gap: 0.4rem;
}

.map-settings-field > span {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.74);
}

.map-settings-field select,
.map-settings-field input {
  min-height: 36px;
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.52);
  color: #eff6ff;
  padding: 0 0.65rem;
}

.map-settings-refresh {
  justify-self: start;
}

.map-settings-meta {
  margin: 0;
  font-size: 0.8rem;
  color: rgba(191, 219, 254, 0.9);
}

.map-settings-popover .pill-toggle {
  margin-top: 0.2rem;
}

.user-menu {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.38rem 0.5rem 0.38rem 0.38rem;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(96, 165, 250, 0.22);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.user-name {
  font-size: 0.9rem;
  color: #e2e8f0;
}

.user-admin-link {
  margin-right: 0.15rem;
  font-size: 0.82rem;
  color: #93c5fd;
  text-decoration: none;
}

.ghost {
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

[data-theme="dark"] .ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

.user-logout-btn {
  padding: 0.45rem 0.8rem;
  font-size: 0.84rem;
}

.shell-main--routes {
  padding: 18px 22px 22px;
  flex: 1;
  display: flex;
  min-height: 0;
}

.routes-shell--frame {
  position: relative;
  width: 100%;
  min-height: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--frame-edge);
  box-shadow: 0 32px 84px rgba(2, 6, 23, 0.22);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    linear-gradient(180deg, var(--frame-ink), rgba(16, 24, 36, 0.92));
}

.routes-shell--frame::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.05);
  pointer-events: none;
}

#routes-iframe {
  width: 100%;
  height: calc(100dvh - 122px);
  min-height: 560px;
  border: 0;
  display: block;
  background: transparent;
}

@media (max-width: 860px) {
  .shell-header {
    grid-template-columns: 1fr auto;
  }

  .shell-context {
    order: 3;
    grid-column: 1 / -1;
    justify-self: stretch;
  }

  .shell-main--routes {
    padding: 14px;
  }

  .map-settings-popover {
    right: -8px;
  }

  #routes-iframe {
    height: calc(100dvh - 170px);
    min-height: 460px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shell.is-auth-ready,
  .theme-toggle {
    transition: none;
  }
}
