* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #1b1320;
  color: #eee;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; }
#header {
  background: linear-gradient(180deg, #2a1d33, #1f1428);
  border-bottom: 2px solid #3a2848;
  padding: 8px 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; z-index: 5;
}
.team-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) auto minmax(220px, 1fr) minmax(260px, 1fr);
  gap: 10px;
  align-items: stretch;
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
}
.team-hero::before,
.team-hero::after {
  content: "";
  position: absolute;
  inset: auto;
  pointer-events: none;
}
.team-hero::before {
  top: -20%;
  right: 8%;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,0.2), transparent 62%);
  opacity: 0.55;
}
.team-hero::after {
  left: 6%;
  bottom: -35px;
  width: 260px;
  height: 120px;
  background: radial-gradient(circle, rgba(255,255,255,0.12), transparent 68%);
  opacity: 0.42;
}
.team-hero.team-purple {
  background:
    radial-gradient(circle at 15% 18%, rgba(255,255,255,0.16), transparent 24%),
    radial-gradient(circle at 70% 26%, rgba(255,255,255,0.14), transparent 18%),
    radial-gradient(circle at 84% 38%, rgba(255,255,255,0.12), transparent 12%),
    linear-gradient(135deg, #623286 0%, #4f246e 36%, #2d153d 100%);
}
.team-hero.team-yellow {
  background:
    radial-gradient(circle at 18% 16%, rgba(255,255,255,0.12), transparent 24%),
    radial-gradient(circle at 72% 28%, rgba(255,255,255,0.10), transparent 16%),
    linear-gradient(135deg, #776120 0%, #5f4d1a 38%, #231b0d 100%);
}
.team-hero.team-admin {
  background:
    radial-gradient(circle at 18% 18%, rgba(255,255,255,0.08), transparent 24%),
    linear-gradient(135deg, #34363b 0%, #23262a 40%, #0f1114 100%);
}
.team-hero-main,
.team-hero-actions,
.team-hero-clocks,
.team-scoreboard {
  position: relative;
  z-index: 1;
}
.team-hero-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
.team-hero-eyebrow {
  color: rgba(255,255,255,0.72);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
#team-hero-title {
  font-size: clamp(18px, 2vw, 26px);
  line-height: 0.95;
  color: #fff;
  text-shadow: 0 10px 28px rgba(0,0,0,0.28);
}
.team-hero-actions {
  display: flex;
  align-items: center;
}
.team-hero-clocks {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: stretch;
}
.clock-pill {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 125px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(18,15,24,0.28);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(5px);
}
.clock-pill.game {
  background: rgba(244,208,63,0.13);
  border-color: rgba(244,208,63,0.26);
}
.clock-label {
  color: rgba(255,255,255,0.72);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}
.clock-pill strong {
  font-size: 18px;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.clock-meta {
  color: rgba(255,255,255,0.72);
  font-size: 10px;
  line-height: 1.4;
}
.clock-meta.paused { color: #f3cc78; }
.clock-meta.done { color: #f0a9a9; }
.team-scoreboard {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.team-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 11px;
  background: rgba(17,14,22,0.3);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(5px);
  cursor: pointer;
}
.team-score-row.yellow {
  background: rgba(244,208,63,0.14);
  border-color: rgba(244,208,63,0.28);
}
.team-score-row.purple {
  background: rgba(183,114,238,0.15);
  border-color: rgba(183,114,238,0.28);
}
.team-score-name {
  color: rgba(255,255,255,0.96);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
}
.team-score-value {
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}
.group { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.admin-only[hidden] { display: none !important; }

.session-strip { margin-left: 6px; }
#session-pill {
  display: inline-flex; align-items: center;
  min-height: 38px; padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  color: #f0e6f7; font-size: 13px; font-weight: 700;
}
#session-pill.yellow { background: rgba(244,208,63,0.16); border-color: rgba(244,208,63,0.45); color: #ffe986; }
#session-pill.purple { background: rgba(183,114,238,0.16); border-color: rgba(183,114,238,0.45); color: #ebc7ff; }
#session-pill.admin { background: rgba(93,211,112,0.12); border-color: rgba(93,211,112,0.4); color: #c7f6ce; }

button, .file-input-label {
  padding: 8px 14px; background: #3b2a4d; color: #fff;
  border: 1px solid #563b6f; border-radius: 6px;
  cursor: pointer; font-size: 14px; user-select: none;
}
button:hover, .file-input-label:hover { background: #4c3863; }
.nav-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  background: #251733;
  color: #f0e6f7;
  border: 1px solid #5a3a78;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  user-select: none;
  transition: background .15s, transform .1s, box-shadow .15s;
}
.hero-link {
  background: rgba(17,14,22,0.36);
  border-color: rgba(255,255,255,0.16);
}
.nav-link-btn:hover {
  background: #342146;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.28);
}
button.active { background: #c0392b; border-color: #e67163; }
.file-input-label { display: inline-block; }
.file-input-label input { display: none; }

#folder-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: #251733;
  border: 1px dashed #5a3a78;
  border-radius: 6px;
  font-size: 12.5px; color: #c8b2db; max-width: 260px;
}
#folder-status.connected { border-style: solid; border-color: #4ea65a; color: #b8e6bf; }
#folder-status.stale     { border-style: solid; border-color: #e6a14e; color: #e8c79a; }
#folder-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #6c4f8e; flex: 0 0 auto; }
#folder-status.connected .dot { background: #5dd370; }
#folder-status.stale .dot     { background: #f0a653; }
#folder-status .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

#map-container {
  flex: 1; overflow: auto; position: relative;
  background: radial-gradient(circle at 20% 20%, #2a1d33 0%, #15101a 100%);
}
#map-inner { position: relative; display: inline-block; min-width: 100%; min-height: 100%; }
#park-map {
  display: block; user-select: none; pointer-events: none; -webkit-user-drag: none;
  position: relative; z-index: 1;
}
#map-overlay-tint {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 2;
  background: linear-gradient(180deg,
    rgba(120,120,120,0.40) 0%,
    rgba(60,60,60,0.55)    50%,
    rgba(20,20,20,0.65)    100%);
  display: none;
}
#map-inner.has-map #map-overlay-tint { display: block; }

#overlay { position: absolute; top: 0; left: 0; overflow: visible; z-index: 3; }

.edge {
  stroke: #cccccc; stroke-width: 5; stroke-linecap: round;
  pointer-events: none; opacity: 0.85;
  transition: stroke .25s, stroke-width .25s, opacity .25s;
}
.edge.yellow { stroke: #f4d03f; stroke-width: 8; opacity: 1; filter: drop-shadow(0 0 6px rgba(244,208,63,0.7)); }
.edge.purple { stroke: #b772ee; stroke-width: 8; opacity: 1; filter: drop-shadow(0 0 6px rgba(183,114,238,0.7)); }

/* Line draws from existing-coloured node to new node over 1.5s */
.edge.new-link {
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  animation: edgeGrow 1.5s cubic-bezier(.25,.65,.35,1) forwards;
}
@keyframes edgeGrow {
  0%   { stroke-dashoffset: var(--len); filter: drop-shadow(0 0 8px currentColor); }
  30%  { filter: drop-shadow(0 0 18px currentColor); }
  60%  { filter: drop-shadow(0 0 24px currentColor) brightness(1.4); }
  100% { stroke-dashoffset: 0; filter: drop-shadow(0 0 6px currentColor); }
}

.node {
  cursor: pointer; pointer-events: auto;
  fill: #f5f5f5; stroke: #1c1226; stroke-width: 3;
  transition: r .15s, stroke-width .15s, fill .25s;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.55));
}
.node.yellow { fill: #f4d03f; }
.node.purple { fill: #b772ee; }
.node:hover { stroke-width: 5; }
.node.pending { stroke: #fff; stroke-dasharray: 4 3; }
.node.selected { stroke: #fff; stroke-width: 5; }

.node-burst {
  fill: none; stroke-width: 5; pointer-events: none; opacity: 0;
  transform-box: fill-box; transform-origin: center;
}
.node-group.stealing.steal-yellow .node-burst { stroke: #f4d03f; }
.node-group.stealing.steal-purple .node-burst { stroke: #b772ee; }
.node-group.stealing .node-burst { animation: nodeBurst 0.85s ease-out; }
@keyframes nodeBurst {
  0%   { opacity: 1;   transform: scale(1);   stroke-width: 6; }
  60%  { opacity: 0.7; }
  100% { opacity: 0;   transform: scale(2.6); stroke-width: 1; }
}

.node-group.stealing .node {
  transform-box: fill-box; transform-origin: center;
  animation: nodePulse 0.55s ease-out;
}
@keyframes nodePulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.45); }
  70%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.node-label {
  fill: #fff; font-size: 13px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central;
  pointer-events: none; user-select: none;
  paint-order: stroke; stroke: #000; stroke-width: 3px;
  display: none;
}
body.edit-mode .node-label { display: block; }

body.edit-mode .node { cursor: move; }
body.edit-mode #map-container::before {
  content: "EDIT MODE";
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(192,57,43,0.85);
  padding: 4px 12px; border-radius: 4px;
  font-size: 12px; font-weight: bold; letter-spacing: 1px;
  z-index: 4; pointer-events: none;
}

#empty-state {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; padding: 32px 40px;
  background: rgba(36,24,48,0.85); border: 2px dashed #5a3a78; border-radius: 14px;
  max-width: 560px;
}
#empty-state h2 { font-size: 22px; margin-bottom: 8px; }
#empty-state p { font-size: 14px; line-height: 1.6; color: #bca6cf; margin-bottom: 12px; }
#empty-state ol { text-align: left; font-size: 13.5px; color: #d8c1ec; line-height: 1.7; margin: 10px 0 16px 22px; }
#empty-state .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#empty-state .file-input-label,
#empty-state button { background: #6a3895; border-color: #8a4ec0; }

#edit-info {
  position: fixed; bottom: 14px; right: 14px;
  background: rgba(20,14,28,0.92); border: 1px solid #4a345e;
  padding: 12px 14px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.6; display: none; z-index: 6; max-width: 280px;
}
body.edit-mode #edit-info { display: block; }
#edit-info strong { color: #f4d03f; }
#edit-info kbd {
  background: #3b2a4d; border: 1px solid #563b6f; border-radius: 3px;
  padding: 1px 6px; font-size: 11px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(20,14,28,0.95); border: 1px solid #4a345e;
  padding: 8px 14px; border-radius: 8px; font-size: 13px;
  z-index: 7; opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }

#winner {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(20,14,28,0.95); padding: 8px 16px;
  border-radius: 8px; font-weight: 700; z-index: 6; display: none;
}

.popup {
  position: fixed; z-index: 20; min-width: 220px;
  background: #2a1d33; border: 1px solid #5a3a78; border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.55);
  color: #f0e6f7;
}
.popup[hidden] { display: none; }
.popup .popup-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.popup .popup-owner { font-size: 12.5px; color: #c8b2db; margin-bottom: 12px; min-height: 16px; }
.popup .popup-owner.yellow { color: #f4d03f; }
.popup .popup-owner.purple { color: #d6a3ee; }
.popup .popup-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.popup .popup-claim {
  flex: 1; background: #6a3895; border-color: #8a4ec0;
  font-weight: 700; padding: 10px 12px;
}
.popup .popup-claim.yellow { background: #f4d03f; border-color: #d6b432; color: #2a2014; }
.popup .popup-claim.purple { background: #9b51d6; border-color: #b772ee; }
.popup .popup-claim.release { background: #a83a3a; border-color: #c95151; }
.popup .popup-rename, .popup .popup-close { padding: 8px 10px; font-size: 13px; }

#node-tooltip {
  position: fixed; z-index: 19;
  background: rgba(20,14,28,0.95); color: #f0e6f7;
  padding: 4px 10px; border-radius: 6px;
  font-size: 12.5px; font-weight: 600;
  border: 1px solid #4a345e;
  pointer-events: none; white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}
#node-tooltip[hidden] { display: none; }

#login-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: none; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at top, rgba(125,60,152,0.25), transparent 40%),
    rgba(10,8,14,0.74);
  backdrop-filter: blur(8px);
  padding: 24px;
}
body.login-required #login-overlay { display: flex; }
#login-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, rgba(46,31,57,0.98), rgba(27,19,32,0.98));
  border: 1px solid rgba(216,193,236,0.16);
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
#login-card .eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  color: #cdb5df;
  margin-bottom: 10px;
}
#login-card h2 { font-size: 30px; margin-bottom: 10px; }
#login-card .login-copy {
  color: #c8b2db;
  line-height: 1.6;
  margin-bottom: 18px;
}
#login-password {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #5a3a78;
  background: rgba(19,12,26,0.9);
  color: #fff;
  font-size: 16px;
  margin-bottom: 14px;
}
#login-password:focus {
  outline: 2px solid rgba(244,208,63,0.45);
  border-color: #f4d03f;
}
.login-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.login-btn {
  min-height: 52px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
}
.login-btn.yellow { background: #f4d03f; border-color: #d6b432; color: #2a2014; }
.login-btn.purple { background: #8c49be; border-color: #b772ee; color: #fff; }
.login-btn.admin { background: #29573a; border-color: #4ea65a; color: #e7ffeb; }
#login-error {
  margin-top: 12px;
  color: #ffb7b7;
  font-size: 13px;
}

#clock-modal {
  position: fixed;
  inset: 0;
  z-index: 42;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9,8,13,0.7);
  padding: 20px;
}
#clock-modal[hidden] { display: none; }
.clock-modal-card {
  width: min(640px, calc(100vw - 28px));
  background: linear-gradient(180deg, #2e2737, #1d1824);
  border: 1px solid #5a4a6d;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.52);
}
.clock-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}
.clock-modal-eyebrow {
  margin: 0 0 6px;
  color: #c8b2db;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
.clock-modal-header h3 {
  margin: 0;
  font-size: 28px;
}
.clock-modal-copy {
  margin: 0 0 16px;
  color: #ccb9dc;
  line-height: 1.6;
}
.clock-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.clock-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #efe6f7;
  font-size: 13px;
  font-weight: 700;
}
.clock-grid input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #5a4a6d;
  background: #15111a;
  color: #fff;
  font: inherit;
}
.clock-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  #header { padding: 10px 12px; gap: 10px; }
  .team-hero {
    grid-template-columns: 1fr;
    padding: 14px 12px;
  }
  .session-strip { width: 100%; margin-left: 0; }
}

@media (max-width: 640px) {
  #app { height: 100dvh; }
  #header { align-items: stretch; }
  .clock-pill { flex: 1 1 100%; }
  .group { width: 100%; flex-wrap: wrap; }
  .group > * { flex: 1 1 auto; }
  .team-btn, button, .file-input-label { text-align: center; }
  .login-actions { grid-template-columns: 1fr; }
  #login-card { padding: 22px; }
  #login-card h2 { font-size: 24px; }
  .clock-grid { grid-template-columns: 1fr; }
}

#manage-drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 360px;
  background: #1f1428; border-left: 1px solid #3a2848; z-index: 15;
  display: flex; flex-direction: column;
  box-shadow: -10px 0 30px rgba(0,0,0,0.5);
}
#manage-drawer[hidden] { display: none; }
#manage-drawer .drawer-header {
  padding: 14px 16px; border-bottom: 1px solid #3a2848;
  display: flex; align-items: center; justify-content: space-between;
  background: #2a1d33;
}
#manage-drawer h3 { font-size: 16px; }
#manage-drawer .drawer-hint {
  padding: 10px 16px; font-size: 12.5px; color: #bca6cf;
  border-bottom: 1px solid #2a1d33; line-height: 1.55;
}
#rides-list { flex: 1; overflow-y: auto; padding: 6px 10px 18px; }
.ride-row { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-bottom: 1px solid #2a1d33; }
.ride-row .badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: #f5f5f5; border: 2px solid #1c1226;
  flex: 0 0 auto; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; color: #1c1226;
}
.ride-row .badge.yellow { background: #f4d03f; }
.ride-row .badge.purple { background: #b772ee; color: #fff; }
.ride-row input {
  flex: 1; padding: 7px 10px;
  background: #15101a; color: #fff;
  border: 1px solid #3a2848; border-radius: 5px;
  font-size: 13.5px; font-family: inherit;
}
.ride-row input:focus { outline: none; border-color: #8a4ec0; }
.ride-row .locate {
  background: transparent; border: 1px solid #3a2848;
  padding: 6px 8px; font-size: 11px;
}

/* ---------- Stars (top SVG layer) ---------- */
.edge-star { pointer-events: none; }
.edge-star.yellow { color: #f4d03f; }
.edge-star.purple { color: #b772ee; }
.edge-star.yellow .star-shape { fill: #f4d03f; stroke: #fff7c2; stroke-width: 1.4; }
.edge-star.purple .star-shape { fill: #b772ee; stroke: #efd5fb; stroke-width: 1.4; }
.edge-star.yellow .star-glow { fill: rgba(244,208,63,0.22); }
.edge-star.purple .star-glow { fill: rgba(183,114,238,0.25); }
.edge-star .star-shape { filter: drop-shadow(0 0 5px currentColor); }

.edge-star .star-floater {
  transform-origin: center;
  animation: starFloat 3.4s ease-in-out infinite;
}
@keyframes starFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

/* Simple scale-up from 0, then ongoing twinkle */
.edge-star .star-popper {
  transform-origin: center;
  animation: starPop 0.5s ease-out,
             starTwinkle 2.1s ease-in-out infinite 0.5s;
}
@keyframes starPop {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes starTwinkle {
  0%, 100% { filter: drop-shadow(0 0 3px currentColor); }
  50%      { filter: drop-shadow(0 0 10px currentColor) drop-shadow(0 0 18px currentColor); }
}
.edge-star.removing .star-popper {
  animation: starPoof 0.45s ease-in forwards;
}
@keyframes starPoof {
  0%   { transform: scale(1);    opacity: 1; }
  100% { transform: scale(0.2);  opacity: 0; }
}
.edge-star.flashing .star-popper {
  animation: starFlash 0.55s ease-out, starTwinkle 2.1s ease-in-out infinite 0.55s;
}
@keyframes starFlash {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); filter: brightness(2.2) drop-shadow(0 0 14px currentColor); }
  100% { transform: scale(1); }
}
