:root{
  --bg:#0b1020;
  --line:rgba(255,255,255,.12);
  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.65);
  --accent:#2f7dff;
  --danger:#ff3b30;

  /* Sticky header sizing */
  --header-h: 54px;
}

*{box-sizing:border-box}

html, body{ height:100%; }

body{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  margin:0;

  padding: 0 22px 22px 22px;

  background:
    radial-gradient(1200px 600px at 20% -20%, rgba(47,125,255,.25), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255,159,10,.12), transparent 60%),
    var(--bg);
  color:var(--text);
}

/* Sticky header */
h1{
  position: sticky;
  top: 0;
  z-index: 120;

  margin: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  display:flex;
  align-items:flex-end;
  padding-bottom: 10px;

  font-size:22px;
  letter-spacing:.3px;

  background: rgba(11,16,32,.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  border-bottom: 1px solid rgba(255,255,255,.10);

  margin-left: -22px;
  margin-right: -22px;
  padding-left: 22px;
  padding-right: 22px;
}

/* When banner shows, it lives under the sticky header */
.banner{
  position: sticky;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  z-index: 119;

  margin: 0;
  margin-left: -22px;
  margin-right: -22px;

  padding: 10px 22px;
  border-bottom: 1px solid rgba(255,255,255,.10);

  font-size: 12px;
  color: rgba(255,255,255,.86);

  background:
    linear-gradient(90deg, rgba(255,59,48,.20), rgba(255,159,10,.12), rgba(47,125,255,.18));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.banner strong{ font-weight: 900; }
.banner .pill{ margin-left: 8px; height: 20px; }

/* Soacing */
.row{ margin-top: 10px; }

/* Form controls */
input, select, button{
  font:inherit;
  padding:10px 10px;
  border-radius:10px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.06);
  color:var(--text);
  outline:none;
}

input::placeholder{color:rgba(255,255,255,.45)}

button{
  cursor:pointer;
  background:rgba(47,125,255,.18);
  border-color:rgba(47,125,255,.35);
  white-space: nowrap;
}

button:hover{background:rgba(47,125,255,.25)}

.btn-ghost{
  background:rgba(255,255,255,.06);
  border-color:rgba(255,255,255,.14)
}
.btn-ghost:hover{background:rgba(255,255,255,.10)}

.row{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

.spacer{flex:1}

.board{
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px;
  background:rgba(255,255,255,.04);
  backdrop-filter: blur(8px);
}

/* Shared shell */
.appShell{
  margin-top:16px;
  border:1px solid var(--line);
  border-radius:14px;
  background:rgba(255,255,255,.04);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow:hidden;
}

.appShell .board{
  margin-top:0;
  border:none;
  border-radius:0;
  background:transparent;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
  padding:14px;
}

/* Footer as inner section */
.appShell .footerWrap{
  margin:0;
  padding:12px 14px;
  border-top:1px solid rgba(255,255,255,.08);
  display:flex;
  justify-content:center;
}

/* Footer box */
.appShell .footerBox{
  border:none;
  background:transparent;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
  padding:0;
  border-radius:0;
  font-size:11px;
  color: rgba(255,255,255,.45);
}

.muted{color:var(--muted)}

/* Pills base */
.pill{
  padding:2px 10px;
  border:1px solid var(--line);
  border-radius:999px;
  font-size:12px;
  color:var(--muted);
  display:inline-flex;
  align-items:center;
  gap:6px;
  height:22px;
}

.miniPill{
  padding:1px 8px;
  border:1px solid var(--line);
  border-radius:999px;
  font-size:12px;
  color:var(--muted);
  height:20px;
  display:inline-flex;
  align-items:center;
  gap:6px;
  background:rgba(255,255,255,.02);
}

/* Clicky pills */
.pillBtn{
  cursor: pointer;
  transition: background .15s ease, transform .05s ease;
}
.pillBtn:hover{ background: rgba(255,255,255,.08); }
.pillBtn:active{ transform: translateY(1px); }

/* Unified semantic tiers */
.pill.tierOk,
.miniPill.tierOk{
  color:rgba(255,255,255,.92);
  border-color:rgba(52,199,89,.55);
  background:rgba(52,199,89,.14);
  font-weight:1000;
}

.pill.tierWarn,
.miniPill.tierWarn{
  color:rgba(255,255,255,.90);
  border-color:rgba(255,159,10,.55);
  background:rgba(255,159,10,.14);
  font-weight:1000;
}

.pill.tierBad,
.miniPill.tierBad{
  color:var(--danger);
  border-color:rgba(255,59,48,.45);
  background:rgba(255,59,48,.12);
  font-weight:1000;
}

/* Pulse effect (used for 0m status) */
.pulseOk{
  animation: pulseOk 1.2s ease-in-out infinite;
}

@keyframes pulseOk{
  0%   { box-shadow: 0 0 0 0 rgba(52,199,89,.0); }
  50%  { box-shadow: 0 0 0 6px rgba(52,199,89,.18); }
  100% { box-shadow: 0 0 0 0 rgba(52,199,89,.0); }
}

@media (prefers-reduced-motion: reduce){
  .pulseOk{ animation:none; }
}

/* Disturbances list (overlay) */
.distList{
  margin-top:10px;
  display:grid;
  gap:10px;
}

.distItem{
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.03);
  border-radius:14px;
  padding:10px 12px;
}

.distTitle{ font-weight:1000; letter-spacing:.2px; }

.distMeta{
  margin-top:6px;
  font-size:12px;
  color:rgba(255,255,255,.65);
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.distDesc{
  margin-top:8px;
  font-size:13px;
  color:rgba(255,255,255,.82);
  line-height:1.35;
  white-space:pre-wrap;
}

.distLink{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:2px 10px;
  border:1px solid rgba(255,255,255,.14);
  border-radius:999px;
  font-size:12px;
  color:rgba(255,255,255,.86);
  text-decoration:none;
  background:rgba(255,255,255,.04);
}
.distLink:hover{
  background:rgba(255,255,255,.08);
  text-decoration:underline;
}

/* Autocomplete */
.autocomplete{
  position:relative;
  min-width:280px;
  flex:1;
  max-width:520px;
}

.stationRow{
  display:flex;
  gap:10px;
  align-items:center;
}

.stationRow input{
  flex:1;
  min-width: 220px;
}

.dropdown{
  position:absolute;
  top:calc(100% + 6px);
  left:0;
  right:0;
  background:rgba(15,23,51,.98);
  border:1px solid var(--line);
  border-radius:12px;
  overflow:hidden;
  box-shadow:0 14px 40px rgba(0,0,0,.45);
  display:none;
  z-index:50;
}

.dropdown.open{display:block}

.dd-item{
  padding:10px 10px;
  border-bottom:1px solid rgba(255,255,255,.06);
  cursor:pointer;
  display:flex;
  justify-content:space-between;
  gap:10px;
  align-items:center;
}

.dd-item:last-child{border-bottom:none}
.dd-item:hover{background:rgba(255,255,255,.06)}

.dd-name{font-weight:800}
.dd-id{font-size:12px;color:rgba(255,255,255,.55)}

/* Controls */
.controls{
  margin-top:10px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:end;
}

.controls label{
  font-size:12px;
  color:rgba(255,255,255,.65);
  display:grid;
  gap:6px;
}

.small{width:160px}

/* Board layout */
.headerline{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  margin-bottom:10px;
}

.title{
  font-size:18px;
  font-weight:900;
  letter-spacing:.3px;
}

.deps{margin-top:8px}

.dep{
  display:grid;
  grid-template-columns:110px 1fr 120px;
  gap:12px;
  padding:12px 8px;
  border-bottom:1px solid rgba(255,255,255,.08);
  align-items:center;
}

.dep:last-child{border-bottom:none}

.when{
  font-size:26px;
  font-weight:900;
  letter-spacing:.5px;
}

.meta{
  font-size:12px;
  color:rgba(255,255,255,.6);
  margin-top:3px;
}

.to{
  font-size:26px;
  font-weight:900;
  letter-spacing:.5px;
}

.right{
  justify-self:end;
  text-align:right;
  display:grid;
  gap:6px;
  justify-items:end;
}

.platform-badge{
  display:inline-grid;
  place-items:center;
  border:2px solid rgba(255,255,255,.85);
  border-radius:12px;
  width:66px;
  height:54px;
  background:rgba(255,255,255,.04);
}

.platform-badge .label{
  font-size:10px;
  color:rgba(255,255,255,.65);
  margin-top:-2px;
}

.platform-badge .num{
  font-size:26px;
  font-weight:1000;
  margin-top:-4px;
}

/* Clickable destination */
.toBtn{
  display:inline-flex;
  align-items:baseline;
  gap:8px;
  padding:0;
  border:none;
  background:transparent;
  color:var(--text);
  font:inherit;
  text-align:left;
  cursor:pointer;
}

.toBtn:hover{text-decoration: underline}

.chev{
  font-size:18px;
  line-height:1;
  transform: translateY(1px);
}

/* Overlay modal */
.overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  display:none;
  z-index:200;

  /* keep this, but DO NOT let it be the only overlay rule */
  touch-action: none;

  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.overlay.open{
  display:block;
  overscroll-behavior: contain;
}

.modal{
  max-width:820px;
  margin:0 auto;
  border:1px solid var(--line);
  border-radius:16px;
  background:rgba(15,23,51,.96);
  box-shadow:0 18px 60px rgba(0,0,0,.55);
  overflow:hidden;
}

.modalHeader{
  display:flex;
  align-items:center;
  gap:10px;
  padding:12px 14px;
  border-bottom:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.04);
}

.modalTitle{
  font-weight:1000;
  letter-spacing:.2px;
}

.closeBtn{
  margin-left:auto;
  padding:8px 10px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.06);
  cursor:pointer;
  color:var(--text);
  font:inherit;
}
.closeBtn:hover{background:rgba(255,255,255,.10)}

.modalBody{
  padding:14px;
  max-height: min(70vh, 560px);
  overflow:auto;

  /* nice-to-have */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.stops{
  margin-top:10px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:14px;
  overflow:hidden;
  background:rgba(255,255,255,.03);
}

.stopRow{
  display:grid;
  grid-template-columns:160px 1fr 140px;
  gap:12px;
  padding:10px 12px;
  border-bottom:1px solid rgba(255,255,255,.08);
  align-items:flex-start;
}
.stopRow:last-child{border-bottom:none}

.stopTime{font-weight:1000}
.stopStation{font-weight:900}

.stopMeta{
  margin-top:4px;
  font-size:12px;
  color:rgba(255,255,255,.65);
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
}

.timeStack{
  display:grid;
  gap:6px;
}

/* keep it EXACTLY like before for the “old good” look */
.stopStack{
  display:grid;
  gap:6px;
}

.depLine{
  font-weight:1000;
  display:flex;
  align-items:baseline;
  gap:8px;
}

.arrLine{
  display:flex;
  align-items:baseline;
  gap:8px;
}

.arrLine, .stopOcc{
  line-height: 1;
}

.arrLine .miniPill{
  opacity:.9;
}

/* Mobile portrait */
@media (max-width:720px) and (orientation:portrait){
  body{ padding: 0 16px 18px 16px; }

  h1{
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .banner{
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .dep{ grid-template-columns:92px 1fr 92px; }

  .when{ font-size: clamp(20px, 5.5vw, 22px); }
  .to{ font-size: clamp(20px, 5.5vw, 22px); }

  .platform-badge{ width:56px; height:48px; }
  .platform-badge .num{ font-size:22px; }

  .stopRow{ grid-template-columns:140px 1fr 110px; }
}

/* Phone landscape */
@media (max-height:520px) and (orientation:landscape){
  .dep{ grid-template-columns:110px 1fr 120px; }

  .when{ font-size:26px; }
  .to{ font-size:26px; }

  .platform-badge{ width:66px; height:54px; }
  .platform-badge .num{ font-size:26px; }
}
