:root {
  --bg: #c9d3cf;
  --card: #ffffff;
  --ink: #1d2328;
  --ink-2: #4d5660;
  --ink-3: #8a929a;
  --line: #e6e8ea;
  --tile: #f3f4f5;
  --accent: #c62f3b;
  --ok: #2f9e64;
  --warn: #d08a16;
  --bad: #c62f3b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.08), 0 6px 18px rgba(20, 30, 40, 0.1);
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#stage { position: fixed; inset: 0; }

#map {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#map.dragging { cursor: grabbing; }
#map.hovering { cursor: pointer; }

#cover {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, #eef1f1 0%, #d8dedf 60%, #c7cfd1 100%);
  transition: opacity 1.6s ease;
  z-index: 5;
}

#cover p { font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em; }
#cover.gone { opacity: 0; pointer-events: none; }
#cover.error p { color: var(--bad); }

#panel {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-height: calc(100% - 24px);
  pointer-events: none;
}

#panel > * { pointer-events: auto; }

.card {
  width: 272px;
  max-height: calc(100vh - 24px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 12px 4px;
  min-height: 40px;
}

.card-head h1 {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.head-actions { display: flex; gap: 2px; }

.card-body {
  padding: 4px 12px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--ink-2);
  padding: 0;
}

.icon-btn[hidden] { display: none; }
.icon-btn:hover { background: var(--tile); color: var(--ink); }
.icon-btn:focus-visible, .row:focus-visible, .tile:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { color: var(--accent); }

.collapse {
  background: var(--card);
  box-shadow: var(--shadow);
  width: 30px;
  height: 30px;
  display: none;
}

.collapse[aria-expanded="false"] svg { transform: rotate(180deg); }

.intro { color: var(--ink-2); line-height: 1.5; margin: 2px 0 8px; }
.intro a, .link { color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; }

.row {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  cursor: pointer;
  text-align: left;
}

.row::after {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--ink-3);
  border-top: 1.5px solid var(--ink-3);
  transform: rotate(45deg);
  margin-right: 4px;
}

details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

details > summary::-webkit-details-marker { display: none; }

details > summary::after {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--ink-3);
  border-top: 1.5px solid var(--ink-3);
  transform: rotate(45deg);
  margin-right: 4px;
  transition: transform 0.15s;
}

details[open] > summary::after { transform: rotate(135deg); }
details details { margin-left: 0; }
details details > summary { color: var(--ink-2); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 4px 0 8px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 12px;
  margin: 12px 0 6px;
}

.section-title::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.muted { color: var(--ink-3); }
.small { font-size: 11px; }
.summary-line { color: var(--ink-2); line-height: 1.45; margin: 2px 0 6px; }

.atis {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-2);
  background: var(--tile);
  border-radius: 8px;
  padding: 8px;
  margin: 2px 0 6px;
  white-space: pre-wrap;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  margin-left: 6px;
}

.feeds { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; margin: 2px 0 6px; }
.feeds .name { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.feeds .age { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: var(--ok); }
.dot.stale { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.est { background: #6a8fbf; }

.seg { display: inline-flex; background: var(--tile); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { appearance: none; border: 0; background: transparent; font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }

.tile {
  background: var(--tile);
  border-radius: 9px;
  padding: 6px 6px 8px;
  border: 0;
  font: inherit;
  text-align: left;
  color: inherit;
}

.tile canvas { width: 100%; height: 62px; display: block; }
.tile b { display: block; font-size: 12px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile span { font-size: 11px; color: var(--ink-2); }
.tile.locked { opacity: 0.45; }

.model { width: 100%; height: 132px; display: block; margin: 2px 0 4px; }

.route { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: start; margin: 2px 0 4px; }
.route .code { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.route .name { font-size: 11px; color: var(--ink-2); line-height: 1.3; }
.route .arrow { padding-top: 4px; color: var(--ink-3); }
.route .to { text-align: right; }

.foot { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 11px; margin-top: 10px; }

.notice {
  font-size: 12px;
  line-height: 1.45;
  border-radius: 8px;
  padding: 7px 8px;
  background: #fbf3e4;
  color: #6c4b10;
  margin: 6px 0;
}

.notice.error { background: #fbe9ea; color: #7e1d25; }
.notice.info { background: #eaf1f8; color: #24456b; }

.search { display: flex; gap: 6px; margin: 4px 0 6px; }
.search input {
  flex: 1;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: var(--tile);
  color: var(--ink);
  min-width: 0;
}

.results { display: flex; flex-direction: column; }
.results .row::after { display: none; }
.results .row span:last-child { color: var(--ink-3); font-size: 12px; }

ul.plain { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 5px; }
ul.plain li { color: var(--ink-2); line-height: 1.4; }

#toasts {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  padding: 9px 12px;
  max-width: 300px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}

.toast b { display: block; }

@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

#mapctl {
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#mapctl .icon-btn { background: var(--card); box-shadow: var(--shadow); width: 32px; height: 32px; }

body.tv #mapctl { display: none; }

@media (max-width: 640px) {
  #panel { top: 8px; left: 8px; right: 8px; }
  .card { width: min(272px, calc(100vw - 56px)); max-height: 46vh; }
  .collapse { display: grid; }
  #panel.collapsed .card { display: none; }
  #mapctl { top: auto; bottom: 12px; right: 8px; }
  #toasts { left: 8px; right: 8px; bottom: 120px; align-items: stretch; }
  .toast { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  #cover { transition: none; }
  .toast { animation: none; }
}
.btn.small { appearance: none; border: 1px solid var(--line, rgba(0,0,0,0.12)); background: #fff; font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 7px; cursor: pointer; color: var(--ink); }
.btn.small[aria-pressed="true"] { background: var(--ink); color: #fff; }
