:root {
  color-scheme: dark;
  --bg: #11161c;
  --panel: #171e26;
  --panel2: #202a35;
  --line: #34404c;
  --text: #ecf1f5;
  --muted: #a7b1bb;
  --amber: #f59e0b;
  --red: #dc2626;
  --gray: #77818b;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.topbar { min-height: 68px; display: grid; grid-template-columns: minmax(220px,auto) minmax(280px,640px) auto; gap: 18px; align-items: center; padding: 10px 16px; background: rgba(17,22,28,.97); border-bottom: 1px solid var(--line); z-index: 20; }
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 18px; letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.search-wrap { position: relative; }
#search { width: 100%; padding: 11px 13px; border: 1px solid #465463; border-radius: 7px; background: #0d1217; color: var(--text); font-size: 15px; outline: none; }
#search:focus { border-color: #7c8b99; box-shadow: 0 0 0 2px rgba(124,139,153,.18); }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 5px); max-height: 55vh; overflow: auto; background: #111820; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 12px 36px rgba(0,0,0,.35); z-index: 30; }
.search-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #28333e; padding: 10px 12px; background: transparent; color: var(--text); cursor: pointer; }
.search-item:hover, .search-item:focus { background: var(--panel2); }
.search-item strong { display: block; }
.search-item span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.search-pending { display: flex; align-items: center; gap: 9px; cursor: default; color: var(--muted); }
.search-pending:hover { background: transparent; }
.search-pending span { display: inline-block; margin: 0; font-size: 13px; color: var(--muted); }
.search-spinner { width: 16px; height: 16px; flex: 0 0 16px; border: 2px solid #465463; border-top-color: var(--amber); border-radius: 50%; animation: search-spin .7s linear infinite; }
@keyframes search-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .search-spinner { animation-duration: 1.8s; } }
.controls { display: flex; gap: 14px; white-space: nowrap; font-size: 13px; color: #d9e0e6; }
.controls label { display: flex; gap: 6px; align-items: center; }
main { min-height: 0; position: relative; }
#map { width: 100%; height: 100%; }
.legend, .map-status { position: absolute; z-index: 5; background: rgba(17,22,28,.92); border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 4px 18px rgba(0,0,0,.2); }
.legend { left: 12px; bottom: 12px; padding: 9px 11px; font-size: 12px; max-width: 260px; }
.legend > div { margin: 3px 0; display: flex; align-items: center; gap: 7px; }
.legend small { display: block; color: var(--muted); margin-top: 7px; }
.swatch { width: 14px; height: 10px; border-radius: 2px; display: inline-block; border: 1px solid #000; box-sizing: border-box; }
.swatch-gray { background: var(--gray); }.swatch-orange { background: var(--amber); }.swatch-red { background: var(--red); }
.map-status { right: 12px; bottom: 12px; padding: 7px 10px; color: #c9d1d9; font-size: 12px; }
.detail { position: absolute; z-index: 15; top: 12px; right: 12px; bottom: 12px; width: min(470px, calc(100vw - 24px)); overflow: auto; background: rgba(17,24,32,.98); border: 1px solid #40505f; border-radius: 9px; box-shadow: 0 18px 50px rgba(0,0,0,.42); padding: 20px; }
.detail-close { position: sticky; float: right; top: 0; z-index: 2; margin: -8px -8px 0 8px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid #52606d; background: #1b242d; color: #fff; font-size: 24px; line-height: 28px; cursor: pointer; }
.detail h1 { font-size: 22px; margin: 0 42px 4px 0; }.detail h2 { font-size: 15px; margin: 22px 0 7px; padding-bottom: 5px; border-bottom: 1px solid #33414e; }.detail h3 { font-size: 14px; margin: 12px 0 4px; }
.kicker { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; }
.fact-grid { display: grid; grid-template-columns: 135px 1fr; gap: 5px 10px; margin: 13px 0; }
.fact-grid dt { color: var(--muted); }.fact-grid dd { margin: 0; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 2px 7px; border: 1px solid #596775; border-radius: 999px; font-size: 11px; vertical-align: 1px; }.badge-warn { border-color: #b97918; color: #ffc45e; background: rgba(185,121,24,.12); }
.discrepancy { margin: 9px 0; padding: 10px 11px; border-left: 3px solid var(--amber); background: #201c15; border-radius: 4px; }.discrepancy strong { display: block; }.discrepancy p { margin: 4px 0; }.citation { color: #b9c3cc; font-size: 12px; margin-top: 5px; }
.report-card, .event-row { padding: 9px 0; border-bottom: 1px solid #2a3540; }.report-card:last-child, .event-row:last-child { border-bottom: 0; }
.report-card p { margin: 4px 0; }.muted { color: var(--muted); }.narrative { white-space: pre-wrap; background: #0f151b; border: 1px solid #2d3944; border-radius: 5px; padding: 9px; }
.entity-link { padding: 0; border: 0; background: none; color: #e9b04e; cursor: pointer; text-decoration: underline; font: inherit; }
.source-list { font-size: 12px; color: #c0cad3; padding-left: 18px; }
.error { color: #ffb4b4; }
footer { min-height: 30px; padding: 7px 12px; border-top: 1px solid var(--line); background: #10151a; color: var(--muted); font-size: 11px; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.maplibregl-popup-content { background: #161e26; color: #fff; border: 1px solid #45525f; }.maplibregl-popup-tip { border-top-color: #161e26 !important; }
@media (max-width: 900px) {
  body { grid-template-rows: auto 1fr auto; }
  .topbar { grid-template-columns: 1fr; gap: 8px; padding: 8px 10px; }
  .brand span { display: none; }.controls { justify-content: space-between; }
  .legend { display: none; }.detail { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 70%; }
  footer { display: none; }
}

/* National landing-view count pins are DOM markers so they render immediately
   from the embedded precomputed summary and do not depend on a glyph service. */
.state-count-pin {
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 999px;
  border: 2px solid var(--gray); background: #111820; color: #fff;
  font: 700 11px/26px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center; cursor: pointer; box-shadow: 0 0 0 1px #000, 0 2px 8px rgba(0,0,0,.42);
}
.state-count-pin-recent { border-color: var(--amber); }
.state-count-pin-high { border-color: var(--red); } /* inherited from a real 2+ crossing in the rolling window */
.state-count-pin-none { border-color: var(--gray); color: #d8dee4; }
.state-count-pin:hover, .state-count-pin:focus { transform: scale(1.08); outline: 2px solid rgba(255,255,255,.55); outline-offset: 1px; }

/* RailIncident.com v0.2.1 publishing/navigation additions */
.brand { min-width: 290px; }
.brand-name { color: var(--text); text-decoration: none; font-size: 19px; font-weight: 750; letter-spacing: .01em; }
.primary-nav { display: flex; gap: 13px; margin-top: 6px; }
.primary-nav a { color: var(--muted); text-decoration: none; font-size: 12px; }
.primary-nav a:hover, .primary-nav a[aria-current="page"] { color: #fff; }
.full-record-link { color: #e9b04e; }
.detail a { color: #e9b04e; }
.state-preview-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(4,8,12,.72); display: grid; place-items: center; padding: 18px; }
.state-preview-overlay[hidden] { display: none; }
.state-preview-modal { position: relative; width: min(760px, 96vw); max-height: min(84vh, 760px); overflow: auto; background: #151d25; border: 1px solid #43515e; border-radius: 10px; box-shadow: 0 24px 70px rgba(0,0,0,.58); padding: 28px; }
.state-preview-close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid #52606d; background: #1b242d; color: #fff; font-size: 24px; line-height: 28px; cursor: pointer; }
.state-preview-modal h1 { margin: 0 42px 6px 0; font-size: 30px; }
.state-preview-window { margin: 0 0 18px; color: #c7d0d8; }
.state-preview-chart { width: 100%; height: auto; max-height: 220px; overflow: visible; }
.state-preview-chart path { fill: none; stroke: #e4a33a; stroke-width: 2.4; vector-effect: non-scaling-stroke; }
.state-preview-chart circle { fill: #f1b44e; }
.state-preview-chart text { fill: #aeb8c2; font-size: 10px; }
.state-preview-summary { margin: 8px 0 18px; padding: 10px 12px; border-left: 3px solid #657484; background: #111820; color: #dbe2e8; }
.state-preview-stats { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); margin: 18px 0 12px; }
.state-preview-stats > div { background: #111820; padding: 12px; }
.state-preview-stats span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.state-preview-stats strong { font-size: 18px; }
.state-preview-range { color: var(--muted); font-size: 12px; }
.state-report-cta { display: inline-block; margin-top: 10px; padding: 10px 14px; border: 1px solid #8b6b32; border-radius: 5px; color: #ffd68a; background: #241c10; text-decoration: none; font-weight: 650; }
.state-report-cta:hover, .state-report-cta:focus { background: #302514; }
@media (max-width: 900px) {
  .brand { min-width: 0; }
  .primary-nav { margin-top: 4px; }
  .state-preview-modal { padding: 22px 18px; }
  .state-preview-stats { grid-template-columns: 1fr; }
}

/* Report heading labels retain Initial Caps. */
#state-preview .kicker { text-transform: none; }
/* Release candidate responsive controls */
.brand-name,.site-brand{color:#fff!important}.brand-incident{color:#ef5350}
button:focus-visible,a:focus-visible,input:focus-visible,summary:focus-visible{outline:3px solid #8bc8ff;outline-offset:3px}
#legend-toggle{display:none}#legend-close{display:none}.legend{max-width:min(360px,calc(100% - 24px));max-height:65vh;overflow:auto}
.detail{max-width:100%;overflow-wrap:anywhere}.fact-grid dd{min-width:0;overflow-wrap:anywhere}
.primary-nav a,button.entity-link{min-height:36px}.search-wrap{min-width:0}.search-results{max-height:55dvh;overflow:auto}
@media(max-width:720px){
 body{height:100dvh}.topbar{display:flex;flex-wrap:wrap;padding:8px 12px;gap:8px}.brand{width:100%;display:flex;flex-wrap:wrap;gap:6px 14px}.brand-name{font-size:22px}.primary-nav{flex-wrap:wrap;gap:12px}.search-wrap{width:100%;flex:1 1 100%}#search{font-size:16px;min-height:44px}.controls{display:flex;flex-wrap:wrap;gap:12px;font-size:13px}.controls label{min-height:36px;display:flex;align-items:center}
 #legend-toggle{display:block;position:absolute;left:12px;bottom:36px;z-index:5;width:44px;height:44px;font-size:26px;background:#171e26;color:white;border:1px solid #73808d;border-radius:6px}
 .legend{display:none;left:12px;bottom:88px;z-index:6;background:#171e26;padding:16px;max-height:55dvh}.legend.is-open{display:block}#legend-close{display:block;float:right;width:44px;height:44px;font-size:26px;background:transparent;color:white;border:0}
 .detail{width:100%;top:0;bottom:0;right:0;max-height:100%;padding:16px}.detail-close{min-width:44px;min-height:44px}.map-status{max-width:calc(100% - 80px);font-size:12px}footer{font-size:11px;padding:7px 10px}.legend small{font-size:13px}
}

/* Keep branding, privacy controls and legend available at tablet widths too. */
.brand .brand-incident{display:inline}
@media(min-width:721px) and (max-width:900px){.legend{display:block}}
@media(max-width:900px){footer{display:block}.brand-name{white-space:nowrap}}
@media(max-width:720px){.detail{left:0;box-sizing:border-box}.primary-nav a{display:inline-flex;align-items:center;min-height:40px}}

.brand .brand-incident{color:#ef5350;font-size:inherit;margin:0}
#legend-content{display:block}#legend-content>div{display:flex;align-items:center;gap:8px;margin:7px 0}.swatch{flex-shrink:0;width:12px;height:12px;border-radius:50%;border:1px solid #000;box-sizing:border-box}
footer a{color:#cbd4dc}.privacy-control{background:none;border:0;color:inherit;text-decoration:underline;font:inherit;cursor:pointer;padding:8px}
@media(max-width:720px){.legend{position:fixed;bottom:12px;max-height:calc(100dvh - 24px);z-index:40}.detail{position:fixed;inset:0;z-index:35;height:100dvh}}
@media(max-height:500px) and (max-width:900px){.topbar{display:flex;flex-wrap:wrap;gap:5px 12px;padding:5px 10px}.brand{flex:1 1 250px;width:auto}.search-wrap{flex:1 1 220px;width:auto}.controls{gap:12px}footer{padding:2px 8px}}
.map-status{right:12px;top:auto;bottom:42px;pointer-events:none}
@media(max-width:900px) and (max-height:500px){
 #legend-toggle{display:block;position:absolute;left:12px;bottom:12px;z-index:5;width:44px;height:44px;font-size:26px;background:#171e26;color:white;border:1px solid #73808d;border-radius:6px}
 .legend{display:none;position:fixed;left:12px;bottom:12px;max-height:calc(100dvh - 24px);z-index:40;background:#171e26;padding:16px}.legend.is-open{display:block}#legend-close{display:block;float:right;width:44px;height:44px;font-size:26px;background:transparent;color:white;border:0}
 .detail{position:fixed;inset:0;width:100%;height:100dvh;max-height:100%;z-index:35}
}

/* Static category shapes match the map images; area is balanced across shapes. */
.swatch-diamond,.swatch-circle,.swatch-square{background:#ef5350!important;border:1px solid #17212b!important;box-shadow:0 2px 3px rgba(0,0,0,.3);border-radius:0!important;display:inline-block}
.swatch-circle{width:16px!important;height:16px!important;border-radius:50%!important}
.swatch-square{width:14px!important;height:14px!important;margin-left:1px;margin-right:9px}
.swatch-diamond{width:14px!important;height:14px!important;transform:rotate(45deg);margin-left:1px;margin-right:9px}
.legend-note{max-width:230px;white-space:normal;font-size:11px;line-height:1.4;color:#c5ced7;margin:10px 0 0}
.map-info-label{display:block;font-size:10px;letter-spacing:.08em;margin-bottom:3px;color:#ecf1f5}

/* Mobile map owns the viewport remainder; footer follows below the fold. */
@media(max-width:900px){
 body{height:auto;min-height:100dvh;overflow:auto;grid-template-rows:auto max(240px,calc(100dvh - var(--map-header-height,188px))) auto}
 body>main{height:100%;min-height:240px}
}

.incident-navigation{display:flex;align-items:center;flex-wrap:wrap;gap:8px 16px;margin:8px 0 18px;font-size:13px}.incident-navigation button,.incident-navigation a{min-height:36px;display:inline-flex;align-items:center}.incident-navigation [aria-disabled="true"]{opacity:.55}.incident-navigation>span{color:var(--muted)}

.legend-title{color:var(--text);font-size:12px;font-weight:700;letter-spacing:.06em;margin:0 32px 10px 0}

/* A fixed icon column keeps category descriptions on one left edge. */
#legend-content>div{display:grid;grid-template-columns:24px auto;column-gap:8px;justify-content:start}
#legend-content>div>.swatch{justify-self:center;margin-left:0;margin-right:0}

.layer-control{position:relative}.layer-control>button{min-height:44px;background:#202a35;color:#ecf1f5;border:1px solid #657484;border-radius:5px;padding:8px 12px;font:inherit;cursor:pointer}#layers-panel{position:absolute;right:0;top:100%;z-index:60;width:280px;max-width:calc(100vw - 24px);max-height:70dvh;overflow:auto;background:#171e26;border:1px solid #657484;border-radius:6px;padding:14px;box-shadow:0 5px 20px #0008}#layers-panel[hidden]{display:none}#layers-panel fieldset{border:0;padding:0;margin:0 0 14px}#layers-panel legend{font-size:12px;text-transform:uppercase;letter-spacing:.06em;color:#c5ced7;margin-bottom:6px}#layers-panel label{display:flex;align-items:center;gap:10px;min-height:44px;white-space:normal}#layers-panel label span,.layer-symbol{color:#ef5350;font-size:22px;width:24px;text-align:center}#layers-done{min-height:44px;padding:8px 20px;background:#234e70;color:white;border:1px solid #799bb4;border-radius:5px;font:inherit}#legend-content>div[hidden]{display:none}.map-status{max-width:min(450px,calc(100% - 24px));font-size:12px} .maplibregl-ctrl-attrib{max-width:calc(100vw - 24px)}
@media(max-width:900px){#layers-panel{left:0;right:auto}}

#legend-content>div{margin:2px 0;line-height:1.25;min-height:22px}.layer-symbol{line-height:1;font-size:19px}.legend-title{margin-bottom:6px}.legend-note{margin-top:6px}.layer-inactive{opacity:.55}.layer-inactive::after{content:'off';font-size:10px;color:#c5ced7;grid-column:2}
.incident-choice-popup .maplibregl-popup-content{background:#171e26;color:#ecf1f5;border:1px solid #657484;border-radius:6px;padding:10px;box-shadow:0 4px 14px #0006}.marker-chooser strong{display:block;font-size:12px;margin-bottom:5px}.marker-chooser button{display:block;width:100%;min-height:40px;text-align:left;padding:8px 10px;background:#202a35;color:#ecf1f5;border:0;border-radius:4px;margin-top:4px;font:inherit;font-size:13px;cursor:pointer}.marker-chooser button:hover{background:#34404c}.marker-chooser button:focus-visible{outline:2px solid #8bc8ff}
#legend-content>div{grid-template-columns:24px auto auto}.layer-inactive::after{grid-column:3;grid-row:1;margin-left:4px}

/* Keep the complete legend visible; muted rows indicate deselected layers. */
#legend-content>div.layer-inactive{opacity:1;color:#87919b}
#legend-content>div.layer-inactive .layer-symbol{color:#87919b}
.layer-inactive::after{content:none}

.layer-count{display:flex;align-items:baseline;justify-content:space-between;gap:16px;line-height:1.5}.layer-count strong{font-weight:650;font-variant-numeric:tabular-nums}.layer-count-inactive{color:#87919b}

.marker-chooser{max-height:min(320px,50dvh);overflow-y:auto}

.search-group{margin:0;padding:8px 12px 5px;font-size:12px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);background:var(--panel)}
.search-item strong{font-size:14px;line-height:1.4}.search-item span{font-size:13px;line-height:1.4}
