/* ============ CME Tracker ============ */
:root {
  --bg: #07090f;
  --bg2: #0b0e17;
  --panel: #0e1220;
  --card: #121729;
  --line: #1e2540;
  --text: #d7ddee;
  --muted: #7a86a8;
  --accent: #ffb347;
  --accent2: #ff6a00;
  --blue: #4da3ff;
  --green: #3ddc97;
  --red: #ff5470;
  --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(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

#app {
  display: grid;
  grid-template-columns: 280px 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-sun {
  width: 18px; height: 18px; border-radius: 50%;
  align-self: center;
  background: radial-gradient(circle at 35% 35%, #fff3c4, #ffb347 55%, #ff6a00);
  box-shadow: 0 0 14px 3px rgba(255, 140, 0, .55);
  animation: sunpulse 3.5s ease-in-out infinite;
}
@keyframes sunpulse {
  0%, 100% { box-shadow: 0 0 12px 2px rgba(255,140,0,.45); }
  50%      { box-shadow: 0 0 20px 6px rgba(255,140,0,.75); }
}

#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: 3ch; text-align: right; transition: color .4s; }
.readout small { color: var(--muted); font-size: 10px; }
.readout b.warn { color: var(--accent); }
.readout b.danger { color: var(--red); }
.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); }
#cme-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; }
.type-chip.off .tc-count { opacity: .6; }

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

.cme-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;
  position: relative;
}
.cme-item:hover { background: #161c33; }
.cme-item.selected {
  background: #1a2140;
  border-color: var(--accent);
  transform: translateX(2px);
}
.cme-item .row1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.cme-item .when { font-size: 12px; color: var(--text); }
.cme-item .row2 { display: flex; gap: 8px; margin-top: 4px; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.cme-item .speed { color: var(--text); }
.cme-item.hit    { border-left-color: var(--red); }
.cme-item.glance { border-left-color: var(--accent); }
.cme-item.miss   { border-left-color: #3a4569; opacity: .8; }
/* Dedicated status footer: badge always bottom-left; arrival/in-flight text
   sits beside it when it fits and wraps onto its own line when it doesn't, so
   it never runs past the cell edge in the narrow panel. */
.cme-item .row-status {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 3px 8px; margin-top: 5px; min-height: 16px;
}
.cme-item .row-status .arr { font-size: 10px; color: var(--muted); white-space: nowrap; }
.cme-item .inflight-tag { color: var(--green); animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }

.badge {
  display: inline-block;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  letter-spacing: .5px;
  border: 1px solid currentColor;
}
.badge.hit    { color: var(--red); }
.badge.glance { color: var(--accent); }
.badge.miss   { color: var(--muted); }
.badge.type-S  { color: var(--muted); }
.badge.type-C  { color: var(--blue); }
.badge.type-O  { color: var(--accent); }
.badge.type-R, .badge.type-ER { color: var(--red); }

.flare-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);
}
.flare-item:hover { border-color: var(--line); }
.flare-class { font-weight: 700; font-size: 12px; }
.flare-class.X { color: var(--red); }
.flare-class.M { color: var(--accent); }
.flare-class.C { color: var(--blue); }
.flare-class.B, .flare-class.A { color: var(--muted); }

/* ---------- 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(--blue); }
#clock-tag.future { color: var(--accent); }

#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(--red);
  color: #eaf0ff; border-radius: 8px; padding: 7px 14px;
  font-size: 13px; letter-spacing: 1px;
  display: flex; align-items: center; gap: 10px;
  animation: bannerpulse 1.2s ease-in-out infinite;
  pointer-events: none;
  white-space: nowrap;
}
#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; }
@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: 260px; 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); }
#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; }
#earth-caption { margin-top: 6px; text-align: center; }

#impact-card .impact-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 12px;
  font-size: 11px; margin-top: 4px;
}
#impact-card .impact-grid dt { color: var(--muted); }
#impact-card .impact-grid dd { color: var(--text); }
#impact-card .verdict { font-size: 13px; padding: 6px 0 8px; }
#impact-card .verdict.hit { color: var(--red); }
#impact-card .verdict.glance { color: var(--accent); }
#impact-card .verdict.miss { color: var(--muted); }
#impact-card .countdown { font-size: 16px; color: var(--accent); padding: 4px 0; }
#impact-card .note { margin-top: 8px; font-size: 10px; color: var(--muted); line-height: 1.5; max-height: 76px; overflow-y: auto; }

#sdo-tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.sdo-tab {
  flex: 1; background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px;
  font: inherit; font-size: 10px; padding: 3px 0; cursor: pointer;
}
.sdo-tab.on { color: var(--accent); border-color: var(--accent); }
#sun-wrap { position: relative; width: 100%; aspect-ratio: 1; }
#sdo-img { width: 100%; height: 100%; border-radius: 6px; display: block; background: #000; }
#sun-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#region-caption { margin-top: 6px; }

.legend { display: flex; gap: 14px; margin-top: 4px; }
.lg { font-size: 10px; color: var(--muted); }
.lg::before { content: "—"; margin-right: 4px; font-weight: 700; }
.lg-speed::before { color: var(--accent); }
.lg-bz::before { color: var(--red); }

#api-key {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px;
  font: inherit; font-size: 11px; padding: 3px 6px; width: 100%;
  margin-top: 4px;
}
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: 230px 1fr 280px; }
}
