/* Signal City: the page around the canvas. System fonts, no offsite anything. */

:root {
  --bg: #16181c;
  --panel: #20242a;
  --panel-2: #2a2f36;
  --ink: #e9ecef;
  --dim: #9aa3ad;
  --green: #2ee06b;
  --yellow: #ffc21f;
  --red: #ff3b30;
  --blue: #4f8cff;
  /* what changed the signal (the Signal line, the strip, the legend) */
  --by-start: #6b7480;
  --by-player: #4f8cff;
  --by-rule: #b07cff;
  --by-plan: #8b95a1;
  --by-offset: #2ec4b6;
  --by-corridor: #ff5a4f;
  --by-outage: #0b0c0e;
  --by-flash: #ffc21f;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--blue); }
button { font: inherit; color: inherit; background: var(--panel-2); border: 1px solid #3a4048; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
button:hover { background: #343a43; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid #2c3138; flex-wrap: wrap; }
.top h1 { font-size: 20px; margin: 0; letter-spacing: 0.3px; }
.top h1 .lv { color: var(--dim); font-weight: 400; font-size: 15px; margin-left: 8px; }
.home { text-decoration: none; color: var(--dim); font-size: 14px; }
.hud { display: flex; gap: 16px; margin-left: auto; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; min-width: 54px; }
.stat.wide { min-width: 130px; }
.stat.mid { min-width: 90px; }
.stat .label, .panel .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--dim); }
.stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat b.bad { color: var(--red); }
.bar { height: 5px; background: #2c3138; border-radius: 3px; margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.3s; }

.play { display: flex; gap: 16px; padding: 16px; flex: 1; align-items: flex-start; }
.board-wrap { flex: 1; min-width: 0; position: relative; background: #5d7a4a; border-radius: var(--radius); overflow: hidden; }   /* grass behind the ground canvas while a drag slides it */
/* (a) event banners queue in the board's top-left corner, newest last, and never overlap */
.banners { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; pointer-events: none; max-width: 45%; }
.banner { font-weight: 800; font-size: 15px; letter-spacing: 1px; padding: 5px 10px; border-radius: 6px; background: rgba(20,22,26,0.88); color: var(--yellow); border-left: 4px solid var(--yellow); box-shadow: 0 2px 8px rgba(0,0,0,0.4); animation: banner-in 0.25s ease-out; }
.banner.off { color: var(--dim); border-left-color: var(--dim); }
.banner.alarm { color: #fff; background: rgba(160,28,22,0.92); border-left-color: #fff; }
@keyframes banner-in { from { transform: translateX(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
/* the ground (roads, roofs, trees) is its own canvas under the board, redrawn only when the camera moves */
canvas#board { display: block; position: relative; border-radius: var(--radius); width: 100%; }
canvas#ground { display: block; position: absolute; left: 0; top: 0; border-radius: var(--radius); background: #5d7a4a; }
.panel { width: 270px; flex: none; background: var(--panel); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.panel-head { display: flex; flex-direction: column; gap: 2px; }
.panel-head b { font-size: 15px; }
.head-row { display: flex; justify-content: space-between; align-items: center; }
.help-btn { width: 24px; height: 24px; padding: 0; border-radius: 50%; font-size: 13px; font-weight: 700; line-height: 1; }
.help-btn[aria-expanded="true"] { border-color: var(--yellow); background: #3a3320; }
.help-box { display: flex; flex-direction: column; gap: 8px; background: #1a1d22; border-radius: 8px; padding: 10px; }
.help-box .legend { font-size: 11px; color: var(--dim); margin: 0; line-height: 1.8; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 3px 0 6px; vertical-align: -1px; }
/* (d) why the signal changed: a coloured dot and a line */
.cause { font-size: 12px; color: var(--dim); min-height: 16px; }
.cause::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c, var(--by-start)); vertical-align: 0; }
.cause.fresh { color: var(--ink); }
.strip { position: relative; height: 16px; margin-top: 6px; background: #1a1d22; border-radius: 4px; overflow: hidden; }
.strip .seg { position: absolute; top: 0; bottom: 0; font-size: 9px; font-weight: 700; line-height: 16px; color: rgba(255,255,255,0.9); text-align: center; overflow: hidden; white-space: nowrap; }
.strip .seg.yellow { background: var(--yellow) !important; top: 5px; bottom: 5px; }
.strip .seg.allred { background: #7a1d18 !important; top: 5px; bottom: 5px; }
.strip .seg.flash { background: repeating-linear-gradient(90deg, var(--by-flash) 0 3px, #3a3320 3px 6px) !important; }
.strip .seg.dark { background: var(--by-outage) !important; outline: 1px solid #3a4048; }
.by-start { background: var(--by-start); --c: var(--by-start); }
.by-player { background: var(--by-player); --c: var(--by-player); }
.by-rule { background: var(--by-rule); --c: var(--by-rule); }
.by-plan { background: var(--by-plan); --c: var(--by-plan); }
.by-offset { background: var(--by-offset); --c: var(--by-offset); }
.by-corridor { background: var(--by-corridor); --c: var(--by-corridor); }
.by-outage { background: var(--by-outage); --c: var(--by-outage); outline: 1px solid #3a4048; }
.by-flash { background: var(--by-flash); --c: var(--by-flash); }
.cause[class*="by-"] { background: none; outline: none; }
/* (e) one section at a time */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid #2c3138; }
.tab { flex: 1; padding: 6px 2px; font-size: 12px; border: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; background: transparent; color: var(--dim); }
.tab:hover { background: var(--panel-2); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--yellow); background: var(--panel-2); }
.tab.fired { animation: fired 0.5s 3 alternate; }
.pane { display: none; flex-direction: column; gap: 8px; }
.panel[data-tab="phases"] .pane[data-pane="phases"], .panel[data-tab="timing"] .pane[data-pane="timing"], .panel[data-tab="rules"] .pane[data-pane="rules"],
.panel[data-tab="crossings"] .pane[data-pane="crossings"], .panel[data-tab="mode"] .pane[data-pane="mode"] { display: flex; }
.pane > .section:first-child { border-top: 0; padding-top: 0; }
.foot-controls { padding-top: 8px; border-top: 1px solid #2c3138; }
.phases { display: flex; flex-direction: column; gap: 6px; }
/* (c) a phase card: key, a drawn diagram of its movements, its name */
.phase { display: grid; grid-template-columns: 18px 44px 1fr; align-items: center; gap: 8px; text-align: left; padding: 5px 10px 5px 8px; border-left: 4px solid #3a4048; }
.phase .key { font-weight: 700; color: var(--dim); }
.phase .name { font-weight: 600; }
.phase .dia { width: 44px; height: 44px; display: block; }
.dia .road { fill: #474c54; }
.dia .mv { fill: none; stroke: #e9ecef; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.dia .mv.permissive { stroke-dasharray: 1.6 1.4; stroke: #c9ced4; }
.dia .head { fill: #e9ecef; }
.dia .walk { fill: #e9ecef; opacity: 0.7; }
.phase.green .dia .mv { stroke: var(--green); }
.phase.green .dia .head { fill: var(--green); }
.phase:focus-visible, .phase.previewing { outline: 2px solid #7fd4ff; outline-offset: 1px; }
.phase.active { border-left-color: var(--yellow); }
.phase.green { border-left-color: var(--green); background: #253328; }
.phase.queued { border-left-color: var(--blue); }
.phase:disabled, .controls button:disabled { opacity: 0.45; cursor: default; }   /* the power is out (M7) */
.priority { display: none; background: #4a1d1a; border-color: #8a2f28; }
.priority.show { display: block; animation: pulse 0.8s infinite alternate; }
.priority .key, .keys { color: var(--dim); }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(255,59,48,0.5); } to { box-shadow: 0 0 0 6px rgba(255,59,48,0); } }
.hint { font-size: 13px; color: var(--dim); margin: 0; line-height: 1.4; }
.note { font-size: 12px; color: var(--dim); margin: -4px 0 0; }
.event { font-size: 13px; font-weight: 600; color: var(--yellow); margin: 0; line-height: 1.4; }
.event.late { color: #ff3b30; }
.hidden { display: none !important; }
.section { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid #2c3138; }
.section .controls button { padding: 6px 10px; font-size: 13px; }
button.small { padding: 5px 9px; font-size: 12px; }
button.on { border-color: var(--yellow); background: #3a3320; }
.slider { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.slider > span { display: flex; justify-content: space-between; align-items: baseline; }
.slider b { font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--yellow); }
.wave { display: block; width: 100%; height: auto; border-radius: 8px; background: #1a1d22; }
.rules { display: flex; flex-direction: column; gap: 6px; }
.rule { display: grid; grid-template-columns: 1fr auto; gap: 4px 6px; align-items: center; background: var(--panel-2); border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.rule .body { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.rule input, .rule select { font: inherit; font-size: 12px; color: var(--ink); background: var(--panel); border: 1px solid #3a4048; border-radius: 5px; padding: 2px 4px; }
.rule input.seconds, .rule input.threshold, .rule input.after { width: 52px; }
.rule .ops { display: flex; gap: 2px; }
.rule .ops button { padding: 2px 6px; font-size: 12px; border-radius: 5px; }
.rule.sleeping .body { opacity: 0.45; }
.rule.sensed { border-left: 3px solid var(--blue); }
.rule.fired { animation: fired 0.5s 3 alternate; }
@keyframes fired { from { box-shadow: 0 0 0 0 rgba(176,124,255,0.9); background: #3a2d52; } to { box-shadow: 0 0 0 5px rgba(176,124,255,0); } }
.nodes { display: flex; flex-wrap: wrap; gap: 6px; }
.nodes .node { flex: 1 0 30%; padding: 6px 8px; font-size: 13px; }
.nodes .node.on { border-color: var(--blue); background: #22304a; }
.calls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.call { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 8px; font-size: 12px; border-left: 4px solid #3a4048; }
.call .leg { font-weight: 700; }
.call .state { color: var(--dim); font-size: 11px; }
.call.waiting { border-left-color: var(--yellow); }
.call.walk { border-left-color: #f4f4f4; background: #2e3438; }
.call.walk .state { color: var(--ink); }
.call.clear { border-left-color: #ff8c1a; }
.rule.sleeping .badge { grid-column: 1 / span 2; font-size: 11px; color: var(--yellow); }
.rules .empty { font-size: 12px; color: var(--dim); margin: 0; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.keys { font-size: 11px; margin: 0; line-height: 1.5; }
.save { font-size: 12px; }

.scrim { position: fixed; inset: 0; background: rgba(10,12,15,0.82); display: none; align-items: safe center; justify-content: safe center; padding: 16px; z-index: 5; overflow-y: auto; } /* safe: nine level cards overflow a 900 px window, and a centred flex scroll container puts the overflow above the scroll origin (#132) */
.scrim.show { display: flex; }
.card { background: var(--panel); border-radius: 14px; padding: 24px; width: min(560px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.card h2 { margin: 0 0 4px; font-size: 26px; }
.tagline { color: var(--dim); margin: 0 0 16px; }
.levels { display: flex; flex-direction: column; gap: 10px; }
.level-card { text-align: left; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.lv-name { font-weight: 700; font-size: 16px; }
.lv-blurb { color: var(--dim); font-size: 13px; }
.lv-stars { color: var(--yellow); font-size: 14px; letter-spacing: 2px; }
.lv-best { color: var(--yellow); font-size: 13px; }
.lv-meta { font-size: 11px; color: var(--dim); }
.lv-bought { font-size: 11px; color: var(--green); }
.lv-shut { font-size: 13px; color: var(--dim); }
.level-card.locked { opacity: 0.55; cursor: default; }
/* the sandbox's district choice (#614), tucked under Free Play's card */
.district { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: -6px 0 0 14px; padding: 6px 10px; border-left: 2px solid var(--dim); font-size: 13px; }
.district .district-size { min-width: 5.5em; text-align: center; }
.district .district-city { color: var(--dim); }
.district .district-note { flex-basis: 100%; font-size: 11px; color: var(--dim); }
.level-card.next { outline: 2px solid var(--yellow); outline-offset: -2px; }
.shop { margin-top: 16px; }
.shop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.shop-head h3 { margin: 0 0 8px; font-size: 16px; }
.shop-head b { color: var(--yellow); }
.shop-list { display: flex; flex-direction: column; gap: 8px; }
.shop-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--panel-2); border-radius: 6px; }
.shop-item.owned { opacity: 0.7; }
.shop-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; font-size: 13px; }
.shop-text span { color: var(--dim); }
.shop-text .shop-why { font-size: 11px; }
.shop-item .buy { flex: none; min-width: 56px; }
.shop-item .ring-switch.on { border-color: var(--green); color: var(--green); }
.ring-note { margin: 10px 0; }
.phase.bought .name::before { content: '+ '; }
.foot { margin: 16px 0 0; color: var(--dim); font-size: 13px; }
.stars { font-size: 34px; color: var(--yellow); letter-spacing: 6px; margin: 4px 0 12px; }
.end-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #2c3138; }
.end-row.total { border-bottom: 0; font-size: 18px; }
.end-why { color: var(--dim); font-size: 13px; line-height: 1.4; }
.card .controls { margin-top: 16px; }

@media (max-width: 760px) {
  .play { flex-direction: column; padding: 12px; }
  .panel { width: 100%; }
  .hud { margin-left: 0; gap: 12px; }
  .stat.wide { min-width: 130px; }
}
