:root {
  --live-bg: #0e1726;
  --live-panel: #16233a;
  --live-panel-2: #1d2d49;
  --live-line: #2b3d5e;
  --live-text: #eef3fb;
  --live-sub: #9fb0ca;
  --live-accent: #4da3ff;
  --live-accent-2: #ffd166;
  --live-mountain: #7ec8a9;
  --live-sea: #6db3f2;
  --live-danger: #ff6b6b;
  --live-radius: 14px;
}

html, body {
  height: 100%;
}

body.live-page {
  background: var(--live-bg);
  color: var(--live-text);
  overflow: hidden;
}

.live-sitebar {
  background: rgba(8, 16, 28, 0.88);
}

#app {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 45px);
  position: relative;
}

#livebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: rgba(14, 23, 38, 0.94);
  border-bottom: 1px solid var(--live-line);
  gap: 8px;
  z-index: 20;
}

.tb-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tb-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.tb-title strong {
  font-size: 0.95rem;
}

.tb-status {
  font-size: 0.72rem;
  color: var(--live-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-status.ok { color: var(--live-mountain); }
.tb-status.warn { color: var(--live-accent-2); }
.tb-status.err { color: var(--live-danger); }

.tb-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tb-metric {
  text-align: right;
  line-height: 1;
  padding: 2px 6px;
  font-variant-numeric: tabular-nums;
}

.tb-metric span {
  font-size: 1.15rem;
  font-weight: 700;
}

.tb-metric small {
  display: block;
  font-size: 0.6rem;
  color: var(--live-sub);
}

.tb-btn {
  background: var(--live-panel);
  color: var(--live-text);
  border: 1px solid var(--live-line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.tb-btn-toggle {
  font-size: 0.72rem;
  padding-inline: 7px;
}

.tb-btn-toggle[aria-pressed="true"] {
  border-color: rgba(255, 209, 102, 0.62);
}

.tb-btn-toggle.is-off {
  color: var(--live-sub);
  background: rgba(255,255,255,0.04);
}

#map {
  flex: 1 1 auto;
  min-height: 30dvh;
  background: #0a111e;
}

#live-map-controls {
  position: fixed;
  right: 12px;
  bottom: calc(46dvh + 14px + env(safe-area-inset-bottom));
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: min(520px, calc(100vw - 24px));
  padding: 6px;
  border: 1px solid rgba(238, 243, 251, 0.2);
  border-radius: 12px;
  background: rgba(8, 16, 28, 0.9);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
}

.map-control-btn {
  min-height: 38px;
  border-radius: 9px;
  border: 1px solid rgba(238, 243, 251, 0.2);
  padding: 8px 10px;
  color: var(--live-text);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.map-control-secondary {
  background: rgba(255, 255, 255, 0.1);
}

.map-control-secondary[aria-pressed="true"] {
  border-color: rgba(255, 209, 102, 0.68);
}

.map-control-secondary.is-off {
  color: var(--live-sub);
  background: rgba(255, 255, 255, 0.05);
}

.map-control-danger {
  background: rgba(255, 107, 107, 0.2);
  border-color: rgba(255, 107, 107, 0.72);
  color: #ffe3e3;
}

.leaflet-container {
  font: inherit;
}

.user-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--live-accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(77, 163, 255, 0.35);
}

.user-marker.pulse {
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 4px rgba(77, 163, 255, 0.4); }
  70% { box-shadow: 0 0 0 14px rgba(77, 163, 255, 0); }
  100% { box-shadow: 0 0 0 4px rgba(77, 163, 255, 0); }
}

.spot-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--live-accent);
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.spot-marker.passed {
  opacity: 0.45;
  filter: grayscale(0.6);
  border-color: #999;
}

.spot-marker.next {
  border-color: var(--live-accent-2);
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.45);
}

.station-label {
  background: rgba(14,23,38,0.8);
  color: #dfe8f5;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.65rem;
  border: 1px solid var(--live-line);
  white-space: nowrap;
}

#segband {
  position: absolute;
  top: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(14,23,38,0.88);
  border: 1px solid var(--live-line);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.78rem;
  z-index: 30;
  white-space: nowrap;
}

#alertbar {
  position: absolute;
  top: 98px;
  left: 10px;
  right: 10px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #3a2d09, #4d3a05);
  border: 1px solid var(--live-accent-2);
  border-radius: var(--live-radius);
  padding: 10px 12px;
  animation: slidein 0.3s ease;
}

@keyframes slidein {
  from { transform: translateY(-12px); opacity: 0; }
}

.al-icon { font-size: 1.8rem; }
.al-body { flex: 1; min-width: 0; }

.al-count {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--live-accent-2);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.al-text {
  font-size: 0.85rem;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#al-close {
  background: none;
  border: none;
  color: var(--live-sub);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
}

#sheet {
  background: var(--live-bg);
  border-top: 1px solid var(--live-line);
  max-height: 38dvh;
  overflow-y: auto;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

body.live-page.is-idle #sheet {
  max-height: min(58dvh, 440px);
}

#sheet-handle {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

#sheet-handle span {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--live-line);
}

#narrbar {
  background: linear-gradient(160deg, #10263a, var(--live-panel));
  border: 1px solid var(--live-accent);
  border-radius: var(--live-radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  animation: slidein 0.3s ease;
}

.nr-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nr-tag {
  background: var(--live-accent);
  color: #06121f;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.nr-name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#nr-close {
  background: none;
  border: none;
  color: var(--live-sub);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 2px 4px;
}

.nr-text {
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--live-text);
  margin-top: 6px;
}

#next-card {
  background: linear-gradient(160deg, var(--live-panel-2), var(--live-panel));
  border: 1px solid var(--live-line);
  border-radius: var(--live-radius);
  padding: 12px;
  margin-bottom: 10px;
}

.nc-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.nc-label {
  font-size: 0.72rem;
  color: var(--live-accent-2);
  letter-spacing: 0.08em;
}

.nc-eta {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--live-accent-2);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.nc-main {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.nc-icon {
  font-size: 2rem;
  line-height: 1.2;
}

.nc-info {
  flex: 1;
  min-width: 0;
}

.nc-name {
  font-size: 1.05rem;
  font-weight: 700;
}

.nc-hook {
  font-size: 0.82rem;
  color: var(--live-sub);
  margin-top: 2px;
}

.nc-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--live-sub);
}

.nc-photo {
  width: 84px;
  height: 63px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--live-line);
  flex-shrink: 0;
}

.side-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #08131f;
}

.side-badge.E { background: var(--live-mountain); }
.side-badge.A { background: var(--live-sea); }

#upcoming {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.up-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--live-panel);
  border: 1px solid var(--live-line);
  border-radius: 10px;
  padding: 8px 10px;
}

.up-icon {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
}

.up-info {
  flex: 1;
  min-width: 0;
}

.up-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.up-sub {
  font-size: 0.7rem;
  color: var(--live-sub);
}

.up-eta {
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--live-text);
  white-space: nowrap;
}

.up-eta small {
  color: var(--live-sub);
  font-weight: 400;
}

#passed-wrap { margin-top: 10px; }
#passed-wrap summary {
  font-size: 0.8rem;
  color: var(--live-sub);
  cursor: pointer;
  padding: 6px 0;
}

.pa-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 2px;
  font-size: 0.8rem;
  color: var(--live-sub);
}

.pa-row .ok { color: var(--live-mountain); }

#idle-panel {
  text-align: center;
  padding: 14px 6px 8px;
}

#idle-panel h2 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}

#idle-panel p {
  font-size: 0.82rem;
  color: var(--live-sub);
  margin-bottom: 14px;
  line-height: 1.6;
}

.idle-feature-list {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.idle-feature-list li {
  border: 1px solid rgba(238, 243, 251, 0.14);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--live-text);
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 8px 10px;
}

.big-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--live-radius);
  border: none;
  cursor: pointer;
  background: var(--live-accent);
  color: #06121f;
}

.big-btn.ghost {
  background: var(--live-panel);
  color: var(--live-text);
  border: 1px solid var(--live-line);
}

.big-btn:active {
  transform: scale(0.99);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(4, 8, 15, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--live-panel);
  border: 1px solid var(--live-line);
  border-radius: var(--live-radius);
  padding: 18px;
  width: 100%;
  max-width: 380px;
}

.modal-card h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.modal-card p {
  font-size: 0.82rem;
  color: var(--live-sub);
  margin-bottom: 12px;
  line-height: 1.5;
}

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--live-line);
}

.set-row:last-of-type {
  border-bottom: none;
}

.set-check-row {
  justify-content: flex-start;
}

.set-check-row span {
  flex: 1;
  min-width: 0;
}

.set-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--live-accent);
}

.set-row select {
  background: var(--live-panel-2);
  color: var(--live-text);
  border: 1px solid var(--live-line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.85rem;
  max-width: 190px;
}

.set-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.primary-btn,
.ghost-btn {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn {
  background: var(--live-accent);
  color: #06121f;
  border: none;
}

.ghost-btn {
  background: none;
  color: var(--live-sub);
  border: 1px solid var(--live-line);
}

.set-note {
  font-size: 0.7rem !important;
  margin-top: 12px;
  margin-bottom: 0 !important;
}

.set-help {
  margin: -4px 0 10px !important;
  color: var(--live-sub);
  font-size: 0.72rem !important;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

@media (min-width: 900px) {
  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto minmax(0, 1fr);
    height: calc(100dvh - 47px);
  }

  #livebar {
    position: relative;
    grid-column: 1;
    grid-row: 1;
  }

  #map {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    min-height: 0;
  }

  #sheet {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 380px;
    max-height: none;
    height: calc(100dvh - 47px);
    border-top: none;
    border-left: 1px solid var(--live-line);
    padding-top: 10px;
  }

  body.live-page.is-idle #sheet {
    max-height: none;
  }

  #segband { left: calc(50% - 190px); }
  #alertbar { right: 390px; }

  #live-map-controls {
    right: 396px;
    bottom: 32px;
  }
}

@media (max-width: 540px) {
  #app {
    height: calc(100dvh - 81px);
  }

  #segband {
    top: 126px;
    max-width: calc(100vw - 24px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #alertbar {
    top: 132px;
  }

  #btn-narr-toggle,
  #btn-pause {
    display: none !important;
  }

  #live-map-controls {
    left: 8px;
    right: 8px;
    bottom: calc(38dvh + 8px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  body.live-page.is-idle #map {
    min-height: 22dvh;
  }

  body.live-page.is-idle #sheet {
    max-height: min(72dvh, 560px);
  }

  .map-control-btn {
    flex: 1;
    min-width: 0;
    padding-inline: 6px;
    font-size: 0.72rem;
  }
}

/* α版表示 */
.live-alpha-badge {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0.08em 0.5em;
  border-radius: 999px;
  background: #f59e0b;
  color: #1a1a1a;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
  white-space: nowrap;
}
.idle-alpha-note {
  margin: 0.6em 0 0;
  padding: 0.5em 0.75em;
  border: 1px solid rgba(245, 158, 11, 0.7);
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  font-size: 0.8rem;
  line-height: 1.55;
}
#idle-panel #idle-alpha-note { color: #fbbf24; }
