:root {
  --bg: #0c1118;
  --bg-elev: #141b24;
  --bg-soft: #1a2330;
  --line: #243041;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #3dd6c6;
  --accent-dim: #1f6f68;
  --danger: #f07178;
  --warn: #e6c07b;
  --home-run: #7c3aed;
  --past: #5a6574;
  --radius: 10px;
  --font: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  --map-strip: 140px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #16303a 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a1530 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#app { min-height: 100%; display: flex; flex-direction: column; }
#main { flex: 1; padding: 1rem 1rem calc(1.5rem + var(--safe-b)); max-width: 960px; margin: 0 auto; width: 100%; }

.topbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.65rem 1rem; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 40;
}
.brand {
  font-weight: 700; font-size: 1.15rem; letter-spacing: 0.02em;
  color: var(--text); text-decoration: none;
}
.brand:hover { color: var(--accent); text-decoration: none; }
.crumbs { flex: 1; min-width: 0; font-size: 0.85rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a { color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 0.4rem; }
.who { color: var(--muted); font-size: 0.85rem; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-soft);
  color: var(--text); border-radius: 8px; padding: 0.55rem 0.9rem;
  font: inherit; font-size: 0.95rem; cursor: pointer;
  min-height: 44px;
}
.btn:hover { border-color: var(--accent-dim); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #06201e; border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem;
}
.auth-panel {
  width: min(100%, 380px);
  background: linear-gradient(165deg, var(--bg-elev), var(--bg-soft));
  border: 1px solid var(--line); border-radius: 16px; padding: 1.75rem 1.5rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.auth-panel h1 {
  margin: 0 0 0.25rem; font-size: 1.85rem; letter-spacing: -0.02em;
}
.auth-panel .tagline { color: var(--muted); margin: 0 0 1.5rem; font-size: 0.95rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; }
.field label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.field input, .field textarea, .field select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 0.7rem 0.8rem; font: inherit; font-size: 1rem;
  min-height: 44px;
}
.field textarea { min-height: 96px; resize: vertical; }
.err { color: var(--danger); font-size: 0.9rem; margin: 0.5rem 0 0; min-height: 1.2em; }

.tree { list-style: none; margin: 0; padding: 0; }
.tree li { margin: 0; }
.tree a, .tree .crumb-only {
  display: flex; align-items: baseline; gap: 0.6rem;
  padding: 0.75rem 0.85rem; border-radius: var(--radius);
  border: 1px solid transparent; color: var(--text); text-decoration: none;
}
.tree a:hover { background: var(--bg-elev); border-color: var(--line); text-decoration: none; }
.tree .id { font-family: var(--mono); font-size: 0.8rem; color: var(--accent); min-width: 3.2rem; }
.tree .name { font-weight: 560; }
.tree .type { margin-left: auto; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.tree .crumb-only { opacity: 0.55; cursor: default; }
.tree .depth-1 { padding-left: 1.4rem; }
.tree .depth-2 { padding-left: 2.2rem; }
.tree .depth-3 { padding-left: 3rem; }
.tree .depth-4 { padding-left: 3.8rem; }

.section-head { margin: 0 0 1rem; }
.section-head h1 { margin: 0; font-size: 1.6rem; }
.section-head p { margin: 0.35rem 0 0; color: var(--muted); }

/* Trip layout */
.trip {
  display: flex; flex-direction: column; gap: 0.75rem;
  margin: -1rem -1rem 0; max-width: none; width: calc(100% + 2rem);
}
.trip-map-wrap {
  position: relative; height: var(--map-strip); transition: height 0.25s ease;
  border-bottom: 1px solid var(--line); background: #0a0e14;
}
.trip-map-wrap.expanded { height: min(55vh, 420px); }
.trip-map { height: 100%; width: 100%; }
.trip-map-toggle {
  position: absolute; right: 0.6rem; bottom: 0.6rem; z-index: 1000;
}
.map-filter {
  position: absolute; left: 0.6rem; top: 0.6rem; z-index: 1000;
  display: flex; gap: 0.3rem; flex-wrap: wrap;
}
.map-filter button {
  min-height: 36px; padding: 0.3rem 0.55rem; font-size: 0.8rem;
  background: rgba(12,17,24,0.85); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; cursor: pointer;
}
.map-filter button.active { border-color: var(--accent); color: var(--accent); }

.trip-body { padding: 0 1rem 1rem; max-width: 960px; margin: 0 auto; width: 100%; }
.trip-settings {
  display: grid; gap: 0.6rem; grid-template-columns: 1fr;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem; margin-bottom: 0.85rem;
}
@media (min-width: 700px) {
  .trip-settings { grid-template-columns: 1fr 1fr; }
  .trip-map-wrap { height: min(42vh, 380px); }
  .trip-map-wrap.expanded { height: min(60vh, 520px); }
  #main.wide { max-width: none; padding-left: 0; padding-right: 0; }
}

.itinerary { display: flex; flex-direction: column; gap: 0.55rem; }
.item {
  display: grid; grid-template-columns: 44px 1fr; gap: 0.65rem;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 0.75rem; scroll-margin-top: 70px;
}
.item.past { opacity: 0.55; }
.item.past .item-num { background: var(--past); }
.item-num {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #061018; font-size: 0.95rem;
}
.item-num.home { background: var(--home-run); color: #fff; }
.item-main h3 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.item-meta { color: var(--muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.45rem; }
.item-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.45rem; }
.item-actions .btn { min-height: 40px; padding: 0.4rem 0.65rem; font-size: 0.85rem; }
.now-line {
  display: flex; align-items: center; gap: 0.5rem; color: var(--accent);
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
  margin: 0.2rem 0;
}
.now-line::before, .now-line::after {
  content: ""; flex: 1; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.comments { margin-top: 0.5rem; padding-top: 0.45rem; border-top: 1px dashed var(--line); }
.comment { font-size: 0.88rem; margin: 0.25rem 0; }
.comment .by { color: var(--muted); }

.marker-dot {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 0.75rem; color: #061018; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}
.marker-dot.home { color: #fff; }
.marker-dot.faded { opacity: 0.45; }
.now-marker {
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  border: 3px solid var(--accent); box-shadow: 0 0 0 4px rgba(61,214,198,0.25);
}

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.75rem; border-bottom: 1px solid var(--line);
}
.checklist input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.checklist .done { text-decoration: line-through; color: var(--muted); }
.checklist .by { font-size: 0.75rem; color: var(--muted); }

.admin-grid { display: grid; gap: 1rem; }
.panel {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.45rem 0.35rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.mono { font-family: var(--mono); font-size: 0.85rem; }
.muted { color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }

.game-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.game-wrap canvas {
  width: min(100%, 420px); background: #060a10; border: 1px solid var(--line);
  border-radius: 8px; touch-action: none;
}
.scores { width: min(100%, 420px); }
.scores ol { margin: 0; padding-left: 1.2rem; }
.scores li { padding: 0.25rem 0; }

.empty { color: var(--muted); padding: 1rem 0; }

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