:root {
  --bg: #0b1020;
  --panel: #111734;
  --card: #141c3d;
  --fg: #e6ecff;
  --muted: #a7b6ff;
  --accent: #7aa2ff;
  --accent2: #ffd56b;
  --good: #6bff95;
  --bad: #ff6b6b;
  --line: #91a6ff;

  --space-1: 6px;
  --space-2: 10px;
  --space-3: 12px;
  --radius: 12px;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
  background: var(--bg);
  color: var(--fg);
}

/* App layout */
.app {
  display: flex;
  height: 100%;
  min-height: 100dvh;
}
#map {
  flex: 1 1 64%;
  min-width: 50vw;
}
.panel {
  flex: 0 0 36%;
  max-width: 36%;
  min-width: 360px;
  background: var(--panel);
  padding: var(--space-3);
  overflow-y: auto;
}

/* Panel header */
.panel-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  background: linear-gradient(
    var(--panel),
    color-mix(in oklab, var(--panel) 85%, transparent)
  );
  border-bottom: 1px solid #1e2753;
}
h1 {
  font-size: 18px;
  margin: 0;
}
.auth-box {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.auth-text {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.header-action,
.secondary-button {
  min-height: 34px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #2a3359;
  border-radius: 8px;
  background: #0f1530;
  color: var(--fg);
  font-size: 13px;
}
.header-action:hover,
.secondary-button:hover {
  border-color: var(--accent);
}
.badge {
  background: #0c1230;
  border: 1px solid #253065;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

/* Cards & form */
.card {
  background: var(--card);
  border: 1px solid #1e2753;
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin: calc(var(--space-3) * -1) calc(var(--space-3) * -1) 12px;
  padding: 12px var(--space-3);
  border-bottom: 1px solid #263160;
  background: linear-gradient(
    180deg,
    rgba(145, 166, 255, 0.08),
    rgba(145, 166, 255, 0.02)
  );
}
.card-title-row strong,
.collapse-toggle strong {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #f0f4ff;
}
.player-picker-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.row {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 13px;
  color: var(--muted);
}

/* Inputs – keep >=16px to prevent iOS zoom */
input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea,
button {
  font-size: 16px;
}
input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #2a3359;
  background: #0f1530;
  color: var(--fg);
  width: 100%;
}
textarea {
  resize: vertical;
  min-height: 76px;
  font-family: inherit;
}
button {
  margin-top: auto;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
button:active {
  transform: translateY(1px);
}
#addPlayerBtn,
#setTargetBtn,
#clearAllBtn {
  min-height: 44px;
}

.hidden {
  display: none;
}
[hidden] {
  display: none !important;
}
.muted {
  color: var(--muted);
  font-size: 12px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 6, 16, 0.72);
}
.modal-panel {
  width: min(720px, 100%);
  max-height: min(86dvh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #2a3359;
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}
.erase-panel {
  max-width: 560px;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid #263160;
}
.modal-header h2 {
  margin: 0;
  font-size: 18px;
}
.modal-subtitle {
  color: var(--muted);
  font-size: 12px;
}
.icon-close {
  min-width: 36px;
  min-height: 36px;
  margin: 0;
  padding: 0;
  border: 1px solid #2a3359;
  border-radius: 8px;
  background: #0f1530;
  color: var(--fg);
  font-size: 24px;
  line-height: 1;
}
.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid #263160;
  background: #101632;
}
.modal-actions button {
  margin: 0;
}
.privacy-alert {
  border: 1px solid color-mix(in oklab, var(--bad) 65%, #2a3359);
  border-radius: 8px;
  padding: 12px;
  background: color-mix(in oklab, var(--bad) 18%, #141c3d);
  color: #ffe7e7;
  font-size: 14px;
  font-weight: 700;
}
.privacy-note {
  border: 1px solid #2a3359;
  border-radius: 8px;
  padding: 10px 12px;
  background: #0f1530;
  color: var(--muted);
  font-size: 13px;
}
.privacy-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.privacy-footer a {
  color: var(--accent2);
}
.server-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.server-preset {
  min-height: 34px;
  margin: 0;
  padding: 7px 12px;
  border: 1px solid #2a3359;
  border-radius: 8px;
  background: #0f1530;
  color: var(--muted);
  font-size: 13px;
}
.server-preset.active {
  border-color: var(--accent2);
  background: color-mix(in oklab, var(--accent2) 22%, #0f1530);
  color: var(--fg);
}

.nrow {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}
.spread-row {
  justify-content: space-between;
}
.top-gap {
  margin-top: 10px;
}
.card-actions-row {
  margin-top: 10px;
  align-items: flex-start;
}
.target-actions-row {
  margin-top: 10px;
  justify-content: space-between;
  align-items: center;
}
input[type="range"] {
  width: 100%;
}
.player-picker-search {
  margin-bottom: 2px;
}
.player-select-label {
  gap: 8px;
}
#playerSelect {
  min-height: 228px;
}
.player-picker-actions {
  display: flex;
  margin-top: 2px;
}
.player-picker-actions button {
  width: 100%;
}
.selected-list,
.summary-list {
  padding: 10px;
}
.settings-card {
  padding: 0;
  overflow: hidden;
}
.collapse-toggle {
  width: 100%;
  margin: 0;
  padding: 12px var(--space-3);
  border-radius: inherit;
  border: none;
  background: linear-gradient(
    180deg,
    rgba(145, 166, 255, 0.08),
    rgba(145, 166, 255, 0.02)
  );
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  font-weight: 700;
}
.collapse-toggle:hover {
  background: linear-gradient(
    180deg,
    rgba(145, 166, 255, 0.13),
    rgba(145, 166, 255, 0.05)
  );
}
.collapse-chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid #b8c6ff;
  border-bottom: 2px solid #b8c6ff;
  transform: rotate(45deg);
  transition: transform 160ms ease;
}
.collapse-toggle.collapsed .collapse-chevron {
  transform: rotate(-45deg);
}

/* Results list */
.results {
  padding: 0;
  overflow: hidden;
}
.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.selected-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.result-item {
  border-bottom: 1px solid #1f2750;
}
.result-item button.item-head {
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  background: transparent;
  border: none;
  color: var(--fg);
  cursor: pointer;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 10px;
  align-items: center;
}
.rank {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f1530;
  border: 1px solid #2a3359;
  color: var(--muted);
  font-weight: 700;
}
.item-title {
  font-size: 14px;
}
.item-metrics {
  font-size: 12px;
  color: var(--muted);
}
.item-body {
  display: none;
  padding: 8px 12px 12px 50px;
  font-size: 13px;
  color: var(--muted);
}
.result-item.active .item-body {
  display: block;
}
.result-item.active button.item-head {
  background: #101943;
}

/* Key/Value */
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  margin-top: 6px;
}
.kv span.key {
  color: #8fa1ff;
}
.kv code {
  color: #dbe3ff;
  background: #0f1530;
  border: 1px solid #2a3359;
  border-radius: 6px;
  padding: 2px 6px;
}

.tag {
  font-size: 11px;
  color: #0a0a0a;
  background: var(--accent2);
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 8px;
}

.autofit {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.autofit input {
  transform: translateY(1px);
}
.settings-panel {
  margin-top: 0;
  padding: 0 var(--space-3) var(--space-3);
  border-top: 1px solid #1f2750;
}
.settings-title {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c9d4ff;
}
.switch-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  color: var(--fg);
}
.switch-row + .switch-row {
  border-top: 1px solid rgba(145, 166, 255, 0.12);
}
.compact-switch-row {
  flex: 0 0 auto;
  padding: 0;
  margin-top: 12px;
}
.compact-switch-row .switch-title {
  font-size: 13px;
}
.switch-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.switch-title {
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
}
.switch-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.settings-hint {
  margin-top: 8px;
}
.slider-setting {
  padding: 14px 0 12px;
  border-bottom: 1px solid rgba(145, 166, 255, 0.12);
}
.select-setting {
  padding: 14px 0 12px;
  border-bottom: 1px solid rgba(145, 166, 255, 0.12);
}
.select-setting select {
  margin-top: 10px;
}
.slider-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.slider-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.slider-value {
  min-width: 44px;
  text-align: right;
  color: #dfe7ff;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#dotSizeSlider {
  accent-color: var(--accent);
  margin: 0;
}
.switch {
  position: relative;
  display: inline-flex;
  width: 42px;
  height: 26px;
  flex: 0 0 auto;
}
.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #202b57;
  border: 1px solid #31407c;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
  box-shadow: inset 0 0 0 1px rgba(11, 16, 32, 0.18);
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #dfe7ff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition:
    transform 160ms ease,
    background 160ms ease;
}
.switch input:checked + .switch-track {
  background: color-mix(in oklab, var(--accent) 62%, #1f2a4d);
  border-color: color-mix(in oklab, var(--accent) 78%, white 8%);
}
.switch input:checked + .switch-track + .switch-thumb {
  transform: translateX(16px);
  background: #ffffff;
}
.switch input:focus-visible + .switch-track {
  box-shadow:
    0 0 0 3px rgba(122, 162, 255, 0.22),
    inset 0 0 0 1px rgba(11, 16, 32, 0.18);
}

/* distance pills */
.dist-pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
  color: #0a0a0a;
}
.dist-km {
  background: var(--accent2);
}
.dist-mi {
  background: var(--accent);
}

.copy {
  cursor: pointer;
  position: relative;
}
.copy.copied::after {
  content: "Copied!";
  position: absolute;
  top: -18px;
  right: -4px;
  font-size: 10px;
  background: #00d1ff;
  color: #0a0a0a;
  padding: 2px 6px;
  border-radius: 6px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 0;
  display: block;
  line-height: 1.35;
}
.hint.ok {
  color: #9cffc4;
}
.hint.warn {
  color: #ffd56b;
}
.hint.err {
  color: #ff9f9f;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-bar {
  flex: 1;
  height: 12px;
  background: #0f1530;
  border: 1px solid #2a3359;
  border-radius: 999px;
  overflow: hidden;
}
#progressFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

/* ===== Mobile tweaks ===== */
@media (max-width: 900px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }
  #map {
    order: 1;
    width: 100%;
    min-width: 0;
    /* 50–60% of viewport height for comfortable interaction */
    min-height: 48dvh;
    height: 48dvh;
  }
  .panel {
    order: 2;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    padding: 14px clamp(12px, 3vw, 18px);
    max-height: none;
  }
  .row {
    grid-template-columns: 1fr;
  }
  .target-actions-row {
    align-items: stretch;
    flex-wrap: wrap;
  }
  .compact-switch-row {
    width: 100%;
    justify-content: space-between;
    margin-top: 0;
  }
  .slider-row {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
  }
  .slider-value {
    text-align: left;
  }
  #playerSelect {
    min-height: 200px;
  }
  .results-header select {
    max-width: 60%;
  }
  .result-item button.item-head {
    grid-template-columns: 28px 1fr;
  }
  .item-metrics {
    display: none;
  } /* keep list compact */
}

/* Small phones */
@media (max-width: 420px) {
  h1 {
    font-size: 16px;
  }
  .badge {
    font-size: 11px;
    padding: 4px 8px;
  }
  .panel-header {
    padding-top: 6px;
    padding-bottom: 8px;
  }
  #map {
    height: 52dvh;
    min-height: 52dvh;
  }
}

/* Landscape phones: give the map more height */
@media (max-height: 480px) and (orientation: landscape) {
  #map {
    height: 60dvh;
    min-height: 60dvh;
  }
}

/* Improve scrolling momentum on iOS */
.panel {
  -webkit-overflow-scrolling: touch;
}

.maplibregl-popup {
  z-index: 20;
}
.maplibregl-popup-content {
  background: var(--card);
  color: var(--fg);
  border: 1px solid #1e2753;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  max-width: none;
}
.maplibregl-popup-close-button {
  color: var(--muted);
}
.maplibregl-popup-tip {
  border-top-color: var(--card) !important; /* match bubble */
  border-bottom-color: var(--card) !important;
}

/* Dark skin for our popups only */
.maplibregl-popup.tp-dark .maplibregl-popup-content {
  background: var(--card) !important;
  color: var(--fg) !important;
  border: 1px solid #1e2753 !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35) !important;
  border-radius: 10px !important;
  padding: 10px 12px !important;
  font-size: 12px !important;
  min-width: 240px;
  max-width: none;
  width: 360px;
}
.maplibregl-popup.tp-dark .maplibregl-popup-close-button {
  color: var(--muted) !important;
}
.maplibregl-popup.tp-dark .maplibregl-popup-tip {
  border-top-color: var(--card) !important;
  border-bottom-color: var(--card) !important;
}

/* Tooltip card */
.tp-tooltip {
  min-width: 260px;
  max-width: 380px;
}
.tp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tp-title {
  font-weight: 600;
  font-size: 14px;
  color: #eaf0ff;
  letter-spacing: 0.01em;
}
.tp-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #c2cdfa;
  font-size: 12px;
  margin-top: 4px;
}
.tp-cluster-note {
  margin-top: 8px;
  color: #9aa8e8;
  font-size: 11px;
  line-height: 1.3;
}
.tp-comma {
  color: #8fa1ff;
  margin: 0 1px;
}
.tp-badge {
  background: #1a2452;
  color: #dfe7ff;
  border: 1px solid #2a3359;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}
.tp-dot {
  width: 4px;
  height: 4px;
  background: #8fa1ff;
  border-radius: 999px;
  display: inline-block;
}
.tp-coord {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tp-actions {
  margin-top: 10px;
}
.tp-actions .occ-btn {
  width: 100%;
  border: 1px solid #2a3359;
  border-radius: 8px;
  padding: 6px 10px;
  background: #111a3a;
  color: #dfe7ff;
  cursor: pointer;
  font-size: 12px;
}
.tp-actions .occ-btn:hover {
  background: #162253;
}

.tp-occ-list {
  margin-top: 10px;
  max-height: 160px;
  overflow: auto;
  overflow-x: hidden;
  padding: 6px;
  border: 1px solid #1f2a4d;
  border-radius: 10px;
  background: #0c1230;
}
.occ-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px;
}
.occ-left {
  min-width: 0;
  flex: 1 1 auto;
}
.occ-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: #eaf0ff;
}
.occ-meta {
  font-size: 11px;
  color: #9aa8e8;
  margin-top: 3px;
  line-height: 1.2;
}
.occ-meta-line {
  white-space: nowrap;
}
.occ-meta-line.layer-line {
  white-space: nowrap;
}
.occ-meta-line.shifted-line {
  color: #f4c76a;
}
.occ-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 150px;
}
.occ-badge {
  font-size: 10px;
  border: 1px solid #2a3359;
  border-radius: 999px;
  padding: 2px 6px;
  background: #0f1530;
  color: #b7c4ff;
  white-space: nowrap;
}
.occ-badge.official {
  background: #66f0b5;
  color: #0b1020;
  border-color: #1e5e46;
}
.occ-badge.unofficial {
  background: #ff9bd1;
  color: #2a1030;
  border-color: #6a2a52;
}
.occ-shift-cue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #3c2b06;
  color: #ffd980;
  border: 1px solid #705313;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  flex: 0 0 auto;
}
.occ-link {
  font-size: 11px;
  color: #0b1020;
  text-decoration: none;
  border: 1px solid #2a3359;
  border-radius: 8px;
  padding: 4px 10px;
  background: #ffe66b;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}
.occ-link:hover {
  background: #fff0a0;
}
.occ-divider {
  height: 1px;
  background: #1f2a4d;
  margin: 0 2px;
}

/* Auth/Discord UI */
.auth-box {
  gap: 10px;
}
.auth-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #121a3a;
  border: 1px solid #2a3359;
  color: var(--fg);
  font-size: 12px;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-text {
  overflow: hidden;
  text-overflow: ellipsis;
}
