/* ============ Asteroid Tracker ============ */
:root {
  --bg: #07090f;
  --bg2: #0b0e17;
  --panel: #0e1220;
  --card: #121729;
  --line: #1e2540;
  --text: #d7ddee;
  --muted: #7a86a8;
  --accent: #58c7ff;     /* icy blue — orbits, selection, playhead */
  --accent2: #2a7fff;
  --hazard: #ff5470;     /* PHA / inside-Moon */
  --warn: #ffb347;       /* amber */
  --green: #46e0c0;      /* teal — distant / safe / live */
  --moon: #c9d2e8;
  --rock: #b9a98f;
  --font: "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#app {
  display: grid;
  grid-template-columns: 285px 1fr 330px;
  grid-template-rows: 52px 1fr;
  grid-template-areas:
    "head head head"
    "left stage right";
  height: 100vh;
}

/* ---------- header ---------- */
#topbar {
  grid-area: head;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, #11162a, #0b0e17);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 16px; letter-spacing: 3px; color: var(--accent); font-weight: 700; }
.brand .subtitle { color: var(--muted); font-size: 11px; }
.brand-rock {
  width: 16px; height: 16px; align-self: center;
  background: radial-gradient(circle at 35% 30%, #e9dcc4, var(--rock) 60%, #6b5f4a);
  box-shadow: 0 0 12px 2px rgba(88, 199, 255, .35);
  /* irregular asteroid silhouette */
  clip-path: polygon(50% 0, 80% 12%, 100% 42%, 88% 78%, 55% 100%, 18% 86%, 0 50%, 14% 16%);
  animation: tumble 9s linear infinite;
}
@keyframes tumble { to { transform: rotate(360deg); } }

#live-readouts { display: flex; gap: 18px; }
.readout { display: flex; align-items: baseline; gap: 5px; }
.readout label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.readout b { font-size: 15px; color: var(--text); min-width: 2ch; text-align: right; transition: color .4s; }
.readout small { color: var(--muted); font-size: 10px; }
.readout b.warn { color: var(--warn); }
.readout b.danger { color: var(--hazard); }
.readout b.ok { color: var(--green); }

/* ---------- side panels ---------- */
#left-panel {
  grid-area: left;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#right-panel {
  grid-area: right;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.scrolly { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.scrolly::-webkit-scrollbar { width: 8px; }
.scrolly::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.panel-head {
  padding: 10px 12px 6px;
  display: flex; align-items: baseline; justify-content: space-between;
}
.panel-head h2 { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--text); }
.panel-head .src { font-size: 10px; color: var(--muted); }
#neo-count { color: var(--muted); font-weight: 400; }

.type-filter { display: flex; gap: 4px; padding: 4px 8px 6px; }
.type-chip {
  flex: 1; min-width: 0;
  background: transparent; border: 1px solid var(--line); border-radius: 5px;
  font: inherit; cursor: pointer; padding: 3px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  transition: opacity .15s, border-color .15s, background .15s;
}
.type-chip:hover { background: #161c33; }
.type-chip .tc-letter { font-weight: 700; font-size: 11px; line-height: 1.3; }
.type-chip .tc-count { font-size: 9px; color: var(--muted); }
.type-chip.off { opacity: .4; }
.type-chip.off .tc-letter { text-decoration: line-through; }

#neo-list { flex: 1.6; min-height: 0; padding: 0 8px 8px; }
#fireball-list { flex: 1; min-height: 0; padding: 0 8px 8px; }
.loading { color: var(--muted); padding: 12px; }

.neo-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 6px 2px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
}
.neo-item:hover { background: #161c33; }
.neo-item.selected {
  background: #15203c;
  border-color: var(--accent);
  transform: translateX(2px);
}
.neo-item .row1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.neo-item .when { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.neo-item .dist { font-size: 12px; white-space: nowrap; }
.neo-item .row2 { display: flex; gap: 10px; margin-top: 4px; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.neo-item.hit    { border-left-color: var(--hazard); }
.neo-item.close  { border-left-color: #ff8c1a; }
.neo-item.near   { border-left-color: var(--warn); }
.neo-item.far    { border-left-color: #3a4569; opacity: .9; }
.neo-item .row-status {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 3px 8px; margin-top: 5px; min-height: 16px;
}
.neo-item .arr { font-size: 10px; color: var(--green); white-space: nowrap; }
.neo-item .arr.past { color: var(--muted); }

.badge {
  display: inline-block;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  letter-spacing: .5px;
  border: 1px solid currentColor;
}
.badge.pha    { color: var(--hazard); }
.badge.inside { color: var(--hazard); }
.badge.sentry { color: var(--warn); }

.fireball-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 8px; margin: 3px 2px;
  border-radius: 4px; border: 1px solid transparent;
  font-size: 11px; color: var(--muted);
}
.fireball-item:hover { border-color: var(--line); }
.fb-place { color: var(--muted); opacity: .7; margin-left: 4px; }
.fb-energy { font-weight: 700; font-size: 12px; }
.fb-energy.X { color: var(--hazard); }
.fb-energy.M { color: var(--warn); }
.fb-energy.C { color: var(--green); }

/* ---------- stage ---------- */
#stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; background: var(--bg); }
#helio-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
#helio-canvas.dragging { cursor: grabbing; }

#stage-hud { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
#sim-clock { background: rgba(10,13,25,.75); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; backdrop-filter: blur(4px); }
#sim-clock b { font-size: 14px; color: var(--text); }
#clock-tag { margin-left: 8px; font-size: 10px; color: var(--green); letter-spacing: 1px; }
#clock-tag.past { color: var(--accent); }
#clock-tag.future { color: var(--warn); }

#stage-tools { display: flex; gap: 6px; pointer-events: auto; }
.tool {
  background: rgba(10,13,25,.75); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 11px; padding: 5px 10px; cursor: pointer;
}
.tool:hover { color: var(--text); }
.tool.on { color: var(--accent); border-color: var(--accent); }

#impact-banner {
  position: absolute; top: 46px; left: 50%; transform: translateX(-50%);
  background: rgba(10, 13, 25, .9); border: 1px solid var(--hazard);
  color: #eaf0ff; border-radius: 8px; padding: 7px 8px 7px 14px;
  font-size: 13px; letter-spacing: 1px;
  display: flex; align-items: center; gap: 8px;
  animation: bannerpulse 1.2s ease-in-out infinite;
  pointer-events: none;
  white-space: nowrap;
}
#banner-body { display: flex; align-items: center; gap: 10px; }
#impact-banner .sev-chip {
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
  padding: 2px 8px; border-radius: 5px;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, .35);
}
#impact-banner .banner-msg::before { content: "⌖ "; opacity: .8; }
#banner-close {
  pointer-events: auto;
  background: transparent; border: none; color: #eaf0ff;
  font-size: 17px; line-height: 1; cursor: pointer;
  padding: 0 4px; opacity: .6; letter-spacing: 0;
}
#banner-close:hover { opacity: 1; }
@keyframes bannerpulse { 50% { box-shadow: 0 0 24px 4px var(--sev-glow, rgba(255, 84, 112, .45)); } }

#tooltip {
  position: absolute; z-index: 30; pointer-events: none;
  background: rgba(8,11,22,.92); border: 1px solid var(--accent);
  border-radius: 6px; padding: 7px 10px; font-size: 11px;
  max-width: 240px; line-height: 1.5;
}
#tooltip b { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- timeline ---------- */
#timeline-wrap {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(0deg, rgba(7,9,15,.95), rgba(7,9,15,.72));
  border-top: 1px solid var(--line);
  padding: 6px 12px 8px;
}
#transport { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
#btn-play, #btn-now {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; padding: 4px 12px; cursor: pointer;
}
#btn-play { width: 42px; color: var(--accent); }
#btn-play:hover, #btn-now:hover { border-color: var(--accent); }
#btn-now.live { color: var(--green); border-color: var(--green); }
#btn-now.live::before { content: "● "; animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }
#speed-ctl { display: flex; gap: 2px; }
.spd {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); font: inherit; font-size: 10px;
  padding: 4px 8px; cursor: pointer;
}
.spd:first-child { border-radius: 6px 0 0 6px; }
.spd:last-child { border-radius: 0 6px 6px 0; }
.spd.on { color: var(--bg); background: var(--accent); border-color: var(--accent); }
#timeline { display: block; width: 100%; height: 56px; cursor: pointer; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
}
.card h3 {
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text); margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.tag { font-size: 9px; color: var(--muted); border: 1px solid var(--line); padding: 1px 6px; border-radius: 8px; text-transform: none; letter-spacing: 0; }
.muted { color: var(--muted); }
.small-text { font-size: 11px; line-height: 1.55; }
.card canvas { width: 100%; display: block; }

#earth-canvas { margin: 0 auto; max-width: 280px; }
#earth-caption { margin-top: 6px; text-align: center; }

#detail-card .impact-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 12px;
  font-size: 11px; margin-top: 4px;
}
#detail-card .impact-grid dt { color: var(--muted); }
#detail-card .impact-grid dd { color: var(--text); }
#detail-card .verdict { font-size: 13px; padding: 6px 0 8px; line-height: 1.4; }
#detail-card .verdict.hit { color: var(--hazard); }
#detail-card .verdict.close { color: #ff8c1a; }
#detail-card .verdict.near { color: var(--warn); }
#detail-card .verdict.far { color: var(--muted); }
#detail-card .countdown { font-size: 16px; padding: 6px 0 2px; }
.sentry-box {
  margin-top: 10px; padding: 8px 10px;
  border: 1px solid rgba(255,179,71,.4); border-radius: 6px;
  background: rgba(255,179,71,.06);
}
.sentry-box b { color: var(--warn); font-size: 11px; }
.sentry-box .impact-grid { margin-top: 6px; }

.legend { display: flex; gap: 14px; margin-top: 4px; }
.lg { font-size: 10px; color: var(--muted); }
.lg-near::before { content: "●"; margin-right: 4px; color: var(--hazard); }
.lg-moon::before { content: ""; }

.copyright {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 10px; color: var(--muted); letter-spacing: .3px;
}
kbd {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 3px;
  padding: 0 4px; font-size: 10px;
}

@media (max-width: 1100px) {
  #app { grid-template-columns: 235px 1fr 285px; }
}
