:root {
  color-scheme: dark;
  --ink: #f4ead8;
  --dim: #b9c4bd;
  --faint: #7f8f8a;
  --good: #7fd69a;
  --warn: #f2c14e;
  --bad: #f0684f;
  --idle: #8fb7ff;
  --sans: "Fira Sans", system-ui, sans-serif;
  --mono: "Fira Mono", ui-monospace, monospace;
  --edge: max(14px, env(safe-area-inset-left), env(safe-area-inset-right));
  /* every panel is one neutral surface; a hairline is the only divider */
  --panel: #141a19f2;
  --line: #ffffff17;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #16393b;
  color: var(--ink); font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
canvas#world { position: fixed; inset: 0; width: 100vw; height: calc(100dvh - var(--bar-h, 0px)); display: block; touch-action: none; cursor: grab; }
canvas#world:active { cursor: grabbing; }

/* scrims keep the HUD readable over the scene */
body::before, body::after { content: ""; position: fixed; left: 0; right: 0; z-index: 1; pointer-events: none; }
body::before { top: 0; height: 26vh; background: linear-gradient(#0c2224e6, #0c222400); }
body::after { bottom: 0; height: 18vh; background: linear-gradient(#0c222400, #0c2224d9); }
#labels { z-index: 2; }
.hud { z-index: 3; }

/* floating signs over buildings and yards */
#labels { position: fixed; inset: 0; pointer-events: none; }
.sign {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -100%);
  text-align: center; white-space: nowrap;
  text-shadow: 0 1px 0 #0009, 0 0 10px #0008;
  will-change: transform;
  pointer-events: auto; cursor: pointer;
}
.sign b { display: block; font-weight: 800; font-size: var(--s, 16px); letter-spacing: 0.02em; line-height: 1; }
.sign span { display: block; font-family: var(--mono); font-size: calc(var(--s, 16px) * 0.6); color: var(--ink); opacity: 0.85; margin-top: 0.25em; text-shadow: 0 1px 1px #000, 0 0 6px #000c; }
.sign[data-under="1"] { opacity: 0.08; pointer-events: none; }
.sign { transition: opacity 0.25s; }
.sign.yard b { font-size: calc(var(--s, 16px) * 1.7); font-family: var(--mono); }
.sign.yard span { color: var(--ink); }
.sign[data-hot="1"] b { color: var(--warn); }

body:not([data-near="1"]) .sign:not(.yard):not(.district) span { display: none; }
.sign.district { transform: translate(-50%, 0); padding: 6px 12px 7px; border-radius: 6px; background: var(--panel); text-shadow: none; }
.sign.district b { font-size: calc(var(--s, 16px) * 1.25); color: var(--ink); letter-spacing: 0.01em; }
.sign.district span { color: var(--dim); opacity: 1; text-shadow: none; font-size: calc(var(--s, 16px) * 0.72); }
body[data-drill="1"] .sign:not(.district) { opacity: 0.35; }

/* HUD */
.hud { position: fixed; left: 0; right: 0; display: flex; justify-content: space-between; gap: 16px; padding: 0 var(--edge); pointer-events: none; }
.hud > * { pointer-events: auto; }
.top { top: max(12px, env(safe-area-inset-top)); align-items: flex-start; }
.bottom { bottom: max(12px, env(safe-area-inset-bottom)); align-items: flex-end; }

.status { --c: var(--dim); display: flex; flex-direction: column; max-width: min(70vw, 900px); }
.status[data-state="good"] { --c: var(--good); }
.status[data-state="warn"] { --c: var(--warn); }
.status[data-state="bad"] { --c: var(--bad); }
.status[data-state="idle"] { --c: var(--idle); }
.kicker { font-size: clamp(11px, 1.4vmin, 18px); letter-spacing: 0.32em; text-transform: uppercase; color: var(--dim); }
.status strong {
  font-size: clamp(40px, 9vmin, 150px); font-weight: 800; line-height: 0.95; color: var(--c);
  text-shadow: 0 2px 0 #0006;
}
.status #status-why { font-size: clamp(14px, 2.2vmin, 32px); color: var(--ink); margin-top: 0.2em; text-shadow: 0 1px 2px #000a; }
.clock { text-align: right; font-family: var(--mono); text-shadow: 0 1px 2px #000a; }
.clock strong { display: block; font-size: clamp(22px, 4.4vmin, 72px); font-weight: 700; line-height: 1; }
.clock span { font-size: clamp(11px, 1.4vmin, 18px); color: var(--dim); }

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; line-height: 1.35; text-shadow: 0 1px 2px #000c; min-width: 0; width: min(46vw, 600px); }
.log li { min-width: 0; border-radius: 4px; }
.log li:nth-child(2) { opacity: 0.72; }
.log li:nth-child(3) { opacity: 0.48; }
.log a { display: flex; gap: 7px; align-items: center; padding: 1px 4px 1px 0; color: var(--ink); text-decoration: none; min-width: 0; }
.log img, .log .face { flex: none; width: 16px; height: 16px; border-radius: 50%; background: #ffffff1f; }
.log .l1 { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--dim); }
.log .who, .log b { color: var(--ink); font-weight: 600; }
.log b { font-family: var(--mono); font-weight: 500; }
.log .t { color: var(--ink); }
.log .why { color: var(--dim); }
.log em { flex: none; font: 11px var(--mono); font-style: normal; color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.35em; }
.log .ago { flex: none; margin-left: auto; padding-left: 6px; font: 12px var(--mono); color: var(--faint); }
.log a:hover .t, .log a:focus-visible .t { text-decoration: underline; }

.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.4em 1em; font-family: var(--mono); font-size: clamp(11px, 1.4vmin, 18px); color: var(--dim); text-shadow: 0 1px 2px #000c; max-width: 46vw; }
.legend span { display: inline-flex; align-items: center; gap: 0.4em; }
.legend i { width: 0.85em; height: 0.85em; border-radius: 2px; background: var(--c); box-shadow: 0 0 0 1px #0008; }
.legend a, .legend button { color: var(--dim); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.tip {
  position: fixed; z-index: 5; max-width: min(420px, 86vw);
  padding: 10px 12px; border-radius: 6px;
  background: var(--panel);
  font-size: 15px; line-height: 1.35; pointer-events: none;
}
.tip b { font-family: var(--mono); color: var(--ink); margin-right: 0.3em; }
.tip span { display: block; margin-top: 4px; color: var(--dim); font-family: var(--mono); font-size: 12px; }


/* drill-in: a side panel on desktop, a bottom sheet on phones */
.drill {
  position: fixed; z-index: 4; top: max(12px, env(safe-area-inset-top)); right: var(--edge); bottom: max(12px, env(safe-area-inset-bottom));
  width: min(400px, 40vw); overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 20px 18px; border-radius: 8px;
  background: var(--panel);
  animation: drill-in 0.22s ease-out;
}
@keyframes drill-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes drill-up { from { transform: translateY(40px); opacity: 0; } }
body[data-drill="1"] .clock, body[data-drill="1"] .legend { visibility: hidden; }
body[data-drill="1"] .status { max-width: calc(100vw - min(400px, 40vw) - 2 * var(--edge) - 24px); }
.drill .grip { display: none; }
.drill .head { position: relative; }
.drill .x { position: absolute; top: -6px; right: -8px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: #ffffff14; color: var(--ink); font-size: 26px; line-height: 1; cursor: pointer; }
.drill h2 { margin: 0 44px 2px 0; font-size: 20px; font-weight: 800; line-height: 1.2; }
.drill .sub { margin: 0 0 12px; font-size: 14px; color: var(--dim); }
.drill .verdict { margin: 0 0 14px; font-size: 22px; font-weight: 800; line-height: 1.25; text-wrap: balance; }
.drill .verdict span { color: var(--faint); font-weight: 700; }
.drill .stats { display: flex; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.drill .stat { flex: 1 1 0; min-width: 0; padding: 10px 10px 10px 0; }
.drill .stat + .stat { padding-left: 10px; border-left: 1px solid var(--line); }
.drill .stat b { display: block; font-size: 30px; font-weight: 800; line-height: 1; }
.drill .stat span, .drill .stat em { display: block; margin-top: 4px; font: 12px var(--mono); color: var(--dim); }
.drill .stat em { font-style: normal; color: var(--faint); margin-top: 2px; }
.drill b.bad { color: var(--bad); }
.drill .explain { margin: 14px 0 10px; font-size: 15px; line-height: 1.45; color: var(--ink); }
.drill .chart { display: block; width: 100%; height: auto; margin: 4px 0 2px; }
.drill .chart text { font: 11px var(--mono); fill: var(--faint); }
.drill .lever { margin: 0; font-size: 15px; line-height: 1.45; }
.drill h3 { margin: 18px 0 6px; font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); }
.drill .items { list-style: none; margin: 0; padding: 0; }
.drill .items li + li { border-top: 1px solid var(--line); }
.drill .items a { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 9px 0; color: var(--ink); text-decoration: none; }
.drill .items a:hover .t { text-decoration: underline; }
.drill .items b { font-family: var(--mono); color: var(--ink); }
.drill .items .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drill .items i { grid-column: 2; font-style: normal; font-family: var(--mono); font-size: 12px; color: var(--faint); }
.drill .items li.focus a { background: #ffffff0f; }
.drill .tag { font: 500 11px var(--mono); font-style: normal; color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-right: 4px; }

/* where work waits, in order: a 2x2 grid at the head of the panel on desktop,
   a sideways strip on phones; each tile switches the panel */
@media not (max-aspect-ratio: 1/1) {
  .drill .strip { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0 0 16px; }
  .drill .strip .arrow, .drill .strip .tile .tr { display: none; }
  .drill .strip .tile { padding: 8px 10px; background: #1c2322; }
  .drill .strip .tile.on { background: #262f2e; }
  .drill .strip .tile b { font-size: 20px; }
}
.tile { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 10px 12px; border-radius: 6px; border: 1px solid transparent; background: var(--panel); color: var(--ink); font: inherit; cursor: pointer; }
.tile.on { background: #232b2a; border-color: #ffffff3d; }
.tile .tn { font-size: 13px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tile b { font-size: 26px; font-weight: 800; line-height: 1.15; margin-top: 2px; }
.tile .tu, .tile .tw, .tile .tr { font: 12px var(--mono); color: var(--faint); white-space: nowrap; }
.tile .tw { color: var(--dim); margin-top: 4px; }
.drill .arrow { align-self: center; color: var(--faint); font-size: 14px; }

@media (max-aspect-ratio: 1/1) {
  .drill { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 46dvh; max-height: 92dvh; padding: 0 16px max(16px, env(safe-area-inset-bottom)); border-radius: 12px 12px 0 0; animation-name: drill-up; transition: height 0.25s ease; }
  .drill.dragging { transition: none; }
  body[data-drill="1"] .hud.top .status { visibility: hidden; }
  .drill .grip { display: grid; place-items: center; height: 24px; margin: 0 -16px; cursor: grab; touch-action: none; }
  .drill .grip::before { content: ""; width: 38px; height: 4px; border-radius: 2px; background: #ffffff40; }
  .drill .strip { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 2px; scrollbar-width: none; }
  .drill .strip::-webkit-scrollbar { display: none; }
  .drill .strip .tile { flex: 0 0 auto; min-width: 140px; padding: 8px 10px; background: #1c2322; }
  .drill .strip .tile.on { background: #262f2e; }
  .drill .strip .tile b { font-size: 20px; }
  .drill .x { top: -4px; right: -4px; width: 36px; height: 36px; font-size: 24px; }
  .drill h2, .drill .sub, .drill .verdict { touch-action: none; }
  .drill .verdict { font-size: 19px; margin-bottom: 10px; }
  .drill .stat b { font-size: 24px; }
  .drill .stat span, .drill .stat em { font-size: 11px; }
  body[data-drill="1"] .hud.bottom { display: none; }
  .clock span { white-space: nowrap; }
  .bottom { flex-direction: column; align-items: stretch; }
  .legend { max-width: none; justify-content: flex-start; }
  .log { width: auto; }
  .log li:nth-child(n+2) { display: none; }
}
.log li.new { animation: log-new 8s ease-out; }
@keyframes log-new { 0%, 15% { background: #ffffff26; color: var(--ink); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .log li.new { animation: none; background: #ffffff1a; } }
@media (max-width: 600px) {
  .sign.district b { font-size: calc(var(--s, 16px) * 0.85); }
  .sign.district span { font-size: calc(var(--s, 16px) * 0.55); }
  .sign.district { padding: 4px 9px 5px; }
}
.sign.tag { font-family: var(--mono); font-weight: 700; font-size: calc(var(--s, 16px) * 0.75); padding: 2px 7px; border-radius: 4px; background: var(--ink); color: #141a19; text-shadow: none; pointer-events: none; }

/* rewind: an activity strip along the bottom that is also the scrubber; on a
   phone it sits just above the drill-in sheet */
.rewind { position: fixed; z-index: 5; left: var(--edge); right: var(--edge); bottom: max(10px, env(safe-area-inset-bottom)); padding: 8px 12px 6px; border-radius: 6px; background: #141a19; font: 12px var(--mono); color: var(--dim); }
body[data-drill="1"] .rewind { right: calc(var(--edge) + min(400px, 40vw) + 12px); }
.hud.bottom { bottom: calc(max(12px, env(safe-area-inset-bottom)) + var(--bar-h, 0px)); }
.rewind[hidden], .pill[hidden], .pill [hidden] { display: none !important; }
.rewind .hide { padding: 5px 8px; color: var(--dim); }
.pill { display: inline-flex; align-items: center; gap: 6px; pointer-events: auto; }
.legend .pill button { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 14px; background: #141a19cc; color: var(--ink); text-decoration: none; text-shadow: none; white-space: nowrap; }
.pill .pill-when.on { color: var(--good); }
.pill canvas { width: 60px; height: 14px; }
.pill .pill-more { color: var(--dim); }
.legend .pill .pill-live { background: var(--ink); color: #141a19; border-color: var(--ink); font-weight: 700; }
.rewind .top { display: flex; align-items: center; gap: 8px; }
.rewind button, .rewind select { flex: none; border: 1px solid var(--line); background: none; color: var(--ink); font: inherit; border-radius: 4px; padding: 5px 9px; cursor: pointer; }
.rewind .play { font-weight: 700; min-width: 96px; text-align: left; }
.rewind .scales { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.rewind .scales button { border: 0; border-radius: 0; color: var(--dim); }
.rewind .scales button + button { border-left: 1px solid var(--line); }
.rewind .scales button[aria-pressed="true"] { background: #ffffff1a; color: var(--ink); }
.rewind .when { flex: 1; min-width: 0; text-align: right; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rewind .live.on { border-color: transparent; color: var(--good); cursor: default; }
body[data-replay="1"] .rewind .live { background: var(--ink); color: #141a19; border-color: var(--ink); font-weight: 700; }
.rewind .strip { position: relative; height: 44px; margin-top: 8px; cursor: crosshair; touch-action: none; outline: none; }
.rewind .strip:focus-visible { box-shadow: 0 0 0 1px #ffffff55; border-radius: 3px; }
.rewind canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.rewind .tip { position: absolute; bottom: calc(100% + 6px); padding: 5px 8px; border-radius: 4px; background: #232b2a; color: var(--dim); white-space: nowrap; pointer-events: none; line-height: 1.35; }
.rewind .tip b { color: var(--ink); }
.rewind .axis { display: flex; justify-content: space-between; margin-top: 3px; color: var(--faint); font-size: 11px; }
body[data-replay="1"] .rewind { background: #1c2322; }
@media (max-aspect-ratio: 1/1) {
  .rewind { left: 8px; right: 8px; padding: 6px 8px 5px; }
  body[data-drill="1"] .rewind { right: 8px; bottom: calc(var(--sheet-h, 0px) + 8px); }
  .rewind .top { flex-wrap: wrap; gap: 6px; }
  .rewind .play { min-width: 0; }
  .rewind .speed { display: none; }
  .rewind .when { order: 5; flex: 1 1 calc(100% - 60px); text-align: left; }
  .rewind .hide { order: 6; }
  .rewind .strip { height: 36px; margin-top: 6px; }
}
