@import url('https://fonts.googleapis.com/css2?family=VT323&family=Space+Grotesk:wght@500;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg-color: #08080b;
  --fg-color: #B0E0E6;
  --panel-bg: #101018;
  --panel-border: #2a2f3d;
  --accent: #B0E0E6;
  --accent-dim: #6f9498;
  --moss: #7a9b76;
  --ghost: #c9a8e0;
  --danger: #c1728a;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-title: 'VT323', monospace;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-color);
  color: var(--fg-color);
  font-family: var(--font-display);
  min-height: 100vh;
  position: relative;
}

/* faint CRT scanlines for atmosphere -- decorative only, doesn't touch input */
body::before {
  content: "";
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    to bottom, rgba(176,224,230,0.025) 0px, rgba(176,224,230,0.025) 1px,
    transparent 1px, transparent 3px
  );
  pointer-events: none;
  z-index: 9999;
}

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px 24px;
}

/* ---------------------------------------------------------------- menu */

#menubar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--panel-border);
  margin-bottom: 14px;
}
.menu-title {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 1.7rem;
  letter-spacing: 0.03em;
  color: var(--accent);
  text-shadow: 0 0 6px rgba(176,224,230,0.55), 0 0 16px rgba(176,224,230,0.25);
  margin-right: 12px;
  animation: flicker 7s infinite;
}
@keyframes flicker {
  0%, 91%, 100% { opacity: 1; }
  92% { opacity: 0.62; }
  93% { opacity: 1; }
  94.5% { opacity: 0.72; }
  96% { opacity: 1; }
}
.site-link {
  font-size: 0.78rem;
  color: var(--ghost);
  text-decoration: none;
  opacity: 0.8;
  margin-left: auto;
  white-space: nowrap;
}
.site-link:hover { opacity: 1; text-decoration: underline; }
.menu-group { display: flex; gap: 4px; }
.menu-item {
  position: relative;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.92rem;
}
.menu-item:hover { background: var(--panel-bg); }
.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px;
  min-width: 190px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.menu-dropdown.open { display: flex; flex-direction: column; gap: 6px; }
.menu-dropdown hr { border: none; border-top: 1px solid var(--panel-border); margin: 4px 0; width: 100%; }
.menu-dropdown label {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------- topbar */

#topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  padding: 10px 4px 18px;
}
.stat { font-weight: 700; font-size: 1.02rem; }
#stat-day { color: var(--accent); }
#stat-sentiment { color: var(--moss); }

/* ---------------------------------------------------------------- main */

#main {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 14px;
  flex: 1 1 380px;
  min-width: 300px;
}
.panel h2 {
  font-family: var(--font-title);
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
  color: var(--accent);
  opacity: 0.9;
}
.checkbox-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82rem; margin-bottom: 8px; cursor: pointer;
}

table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.88rem; }
thead th {
  text-align: left; padding: 6px 8px; cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--panel-border); font-family: var(--font-display); font-size: 0.82rem;
  opacity: 0.8;
}
thead th:hover { color: var(--accent); }
tbody td { padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,0.05); }
tbody tr:hover { background: rgba(255,255,255,0.04); cursor: pointer; }
tbody tr.selected { background: rgba(212,162,76,0.18); }
.bankrupt-row { color: var(--danger); opacity: 0.7; }

/* ---------------------------------------------------------------- buttons */

button {
  font-family: var(--font-display);
  background: var(--panel-bg);
  color: var(--fg-color);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.86rem;
  transition: border-color 0.15s, color 0.15s;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent-dim); border-color: var(--accent); color: #1b1508; font-weight: 600; }
button.primary:hover { background: var(--accent); color: #1b1508; }

#button-row, #time-controls-row {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 4px 0;
}

/* ---------------------------------------------------------------- modals */

.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
}
.modal-overlay.open { display: block; }

.modal {
  display: none;
  position: fixed;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 22px;
  z-index: 101;
  min-width: 320px;
  max-width: 90vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal.open { display: block; }
.modal.modal-large { width: 900px; }
.modal h3 { margin-top: 0; color: var(--accent); font-family: var(--font-title); font-size: 1.4rem; letter-spacing: 0.03em; }
.modal label { display: block; margin-bottom: 12px; font-size: 0.88rem; }
.modal select, .modal input[type=number] {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px;
  background: var(--bg-color); color: var(--fg-color); border: 1px solid var(--panel-border);
  border-radius: 5px; font-family: var(--font-mono);
}
.modal-buttons { display: flex; gap: 8px; margin-top: 14px; }
.muted { opacity: 0.7; font-size: 0.85rem; margin-bottom: 6px; }
.warn { color: var(--danger); font-size: 0.85rem; min-height: 1em; margin: 6px 0; }

.viewer-layout { display: flex; gap: 16px; }
.viewer-controls { width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; }
.viewer-controls h4 { margin: 4px 0; font-size: 0.85rem; opacity: 0.8; }
.viewer-controls hr { border: none; border-top: 1px solid var(--panel-border); margin: 8px 0; }
#stock-checklist, #eco-checklist { display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.checklist-item { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
canvas { background: rgba(0,0,0,0.15); border-radius: 6px; border: 1px solid var(--panel-border); }

/* ---------------------------------------------------- floating panels */
/* Stock Viewer / Ecosystem Viewer: independent, draggable, non-blocking --
   the rest of the page (playback controls, holdings, buy/sell) stays
   fully usable while these are open, and both can be open at once. */

.floating-panel {
  display: none;
  position: fixed;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  z-index: 90;
  max-height: 85vh;
}
.floating-panel.open { display: flex; flex-direction: column; }
.panel-large { width: 900px; max-width: 92vw; }
#panel-stock-viewer { top: 64px; left: 16px; }
#panel-ecosystem-viewer { top: 64px; right: 16px; }

.panel-titlebar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px;
  background: rgba(0,0,0,0.22);
  border-bottom: 1px solid var(--panel-border);
  border-radius: 10px 10px 0 0;
  cursor: move;
  user-select: none;
  font-family: var(--font-title);
  font-size: 1.15rem;
  letter-spacing: 0.03em;
  color: var(--accent);
  flex-shrink: 0;
}
.panel-close {
  background: transparent; border: none; color: var(--fg-color);
  font-size: 1rem; cursor: pointer; padding: 2px 8px; border-radius: 4px;
}
.panel-close:hover { color: var(--danger); border-color: transparent; }
.floating-panel .viewer-layout { padding: 14px; overflow-y: auto; }

#report-text, #history-text {
  font-family: var(--font-mono);
  white-space: pre-wrap;
  background: rgba(0,0,0,0.2);
  padding: 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.5;
  max-height: 60vh;
  overflow-y: auto;
}
.history-layout { display: flex; gap: 14px; }
#history-list { width: 140px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
#history-list button { text-align: left; }
#history-list button.active { border-color: var(--accent); color: var(--accent); }
#history-text { flex: 1; }

@media (max-width: 720px) {
  .viewer-layout, .history-layout { flex-direction: column; }
  .viewer-controls, #history-list { width: 100%; }
  canvas { max-width: 100%; height: auto; }
  .modal.modal-large { width: 95vw; }
  .panel-large { width: 95vw; max-height: 90vh; }
  #panel-stock-viewer, #panel-ecosystem-viewer { left: 2.5vw; right: 2.5vw; top: 54px; }
}