:root {
  /* Terminal Noir palette */
  --bg: #07090e;
  --bg-2: #0b0f17;
  --panel: #0e131d;
  --panel-2: #131a28;
  --panel-3: #182234;
  --border: #1c2637;
  --border-soft: #151d2b;
  --text: #e9eef6;
  --muted: #7c8aa3;
  --muted-2: #55627a;
  --up: #2ee6a0;
  --up-dim: #1a9d6e;
  --up-bg: rgba(46, 230, 160, 0.11);
  --down: #ff4d6a;
  --down-dim: #c23350;
  --down-bg: rgba(255, 77, 106, 0.11);
  --accent: #ffb347;      /* amber — terminal accent */
  --accent-2: #4cc9ff;    /* cyan — interactive */
  --accent-soft: rgba(76, 201, 255, 0.13);
  --amber-soft: rgba(255, 179, 71, 0.12);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  --mono: "IBM Plex Mono", "SF Mono", Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --serif: "IBM Plex Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--border) transparent; }
::selection { background: var(--accent-2); color: #04202b; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 480px at 82% -8%, rgba(76, 201, 255, 0.07), transparent 55%),
    radial-gradient(900px 420px at 8% 0%, rgba(255, 179, 71, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.006em;
}

/* faint grid + grain atmosphere */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.5;
  background-image:
    linear-gradient(rgba(255,255,255,0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.014) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 20%, #000 30%, transparent 85%);
}
body > *:not(.grain) { position: relative; z-index: 1; }

.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 15px 26px;
  background: linear-gradient(180deg, rgba(11,15,23,0.92), rgba(11,15,23,0.72));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40; flex-wrap: wrap;
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
  opacity: 0.4;
}
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.brand-glyph { color: var(--accent); font-size: 16px; align-self: center; text-shadow: 0 0 12px var(--accent); }
.brand-name { font-family: var(--mono); font-size: 18px; font-weight: 700; letter-spacing: 0.22em; }
.brand-sub { font-family: var(--serif); font-style: italic; font-size: 12.5px; color: var(--muted); letter-spacing: 0; }

.search { position: relative; flex: 1; min-width: 240px; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.search input {
  width: 100%; padding: 11px 14px 11px 40px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
  font-size: 13.5px; font-family: var(--mono); outline: none;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.search input::placeholder { color: var(--muted-2); font-family: var(--sans); }
.search input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-results {
  list-style: none; margin: 8px 0 0; padding: 5px; position: absolute; left: 0; right: 0;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px;
  max-height: 340px; overflow-y: auto; z-index: 50; box-shadow: var(--shadow);
}
.search-results li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.search-results li:hover { background: var(--panel-3); }
.search-results .sym { font-weight: 600; font-family: var(--mono); font-size: 13px; color: var(--accent-2); }
.search-results .desc { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.search-results .msg { color: var(--muted); cursor: default; }
.search-results .msg:hover { background: transparent; }

.status { display: flex; align-items: center; gap: 15px; color: var(--muted); white-space: nowrap; }
.market-status { display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 600; font-family: var(--mono); letter-spacing: 0.04em; }
.market-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.market-status.open .dot { background: var(--up); box-shadow: 0 0 10px var(--up); animation: breathe 2s ease-in-out infinite; }
.market-status.closed .dot { background: var(--down); }
@keyframes breathe { 50% { opacity: 0.4; } }
.last-updated { font-size: 11.5px; color: var(--muted-2); font-family: var(--mono); }

#refresh-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 10px; width: 38px; height: 38px; cursor: pointer;
  display: grid; place-items: center; transition: color 0.15s, border-color 0.15s;
}
#refresh-btn:hover { color: var(--accent-2); border-color: var(--accent-2); }
#refresh-btn.spinning svg { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Ticker ---------- */
.ticker {
  border-bottom: 1px solid var(--border); background: var(--bg-2);
  overflow: hidden; white-space: nowrap; height: 38px;
}
.ticker-track { display: inline-flex; align-items: center; height: 38px; gap: 30px; padding-left: 26px; animation: marquee 48s linear infinite; }
.ticker:hover .ticker-track { animation-play-state: paused; }
@keyframes marquee { to { transform: translateX(-50%); } }
.tick { display: inline-flex; align-items: baseline; gap: 8px; font-family: var(--mono); font-size: 12.5px; }
.tick .t-sym { color: var(--muted); font-weight: 600; }
.tick .t-px { color: var(--text); }
.tick .t-chg { font-weight: 600; }

/* ---------- Layout ---------- */
main {
  flex: 1; display: grid; grid-template-columns: 1fr 380px; gap: 20px;
  padding: 22px 26px; align-items: start; max-width: 1680px; width: 100%; margin: 0 auto;
}
.left-col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

.section-label {
  display: flex; align-items: center; gap: 9px; font-family: var(--mono);
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 13px;
}
.section-label span { color: var(--accent); }

/* ---------- Overview cards ---------- */
.overview-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; }
.ov-card {
  background: linear-gradient(165deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border); border-radius: 14px; padding: 16px 17px;
  position: relative; overflow: hidden;
}
/* Entrance animation only as an enhancement — cards are visible by default so
   they never get stuck hidden if animations are disabled or reduced. */
@media (prefers-reduced-motion: no-preference) {
  .ov-card { opacity: 0; transform: translateY(10px); animation: rise 0.5s cubic-bezier(0.2,0.8,0.3,1) forwards; }
  .ov-card:nth-child(1) { animation-delay: 0.04s; }
  .ov-card:nth-child(2) { animation-delay: 0.10s; }
  .ov-card:nth-child(3) { animation-delay: 0.16s; }
  .ov-card:nth-child(4) { animation-delay: 0.22s; }
}
@keyframes rise { to { opacity: 1; transform: none; } }
.ov-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--muted-2);
}
.ov-card.up::before { background: linear-gradient(var(--up), var(--up-dim)); box-shadow: 0 0 16px var(--up-bg); }
.ov-card.down::before { background: linear-gradient(var(--down), var(--down-dim)); box-shadow: 0 0 16px var(--down-bg); }
.ov-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.ov-sym { font-family: var(--mono); font-weight: 700; font-size: 14px; letter-spacing: 0.04em; }
.ov-name { font-size: 11px; color: var(--muted-2); }
.ov-price { font-family: var(--mono); font-size: 25px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; margin-bottom: 8px; }
.ov-change { font-family: var(--mono); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ov-range { margin-top: 13px; }

/* ---------- Day range bar ---------- */
.rng { display: flex; align-items: center; gap: 9px; }
.rng-lo, .rng-hi { font-family: var(--mono); font-size: 10.5px; color: var(--muted-2); min-width: 46px; }
.rng-hi { text-align: left; }
.rng-lo { text-align: right; }
.rng-track {
  position: relative; flex: 1; height: 4px; border-radius: 3px;
  background: linear-gradient(90deg, var(--down-dim), var(--muted-2), var(--up-dim));
  opacity: 0.55;
}
.rng-dot {
  position: absolute; top: 50%; width: 9px; height: 9px; border-radius: 50%;
  background: var(--text); transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--panel), 0 0 8px rgba(255,255,255,0.5); transition: left 0.4s ease;
}
.ov-range .rng-track { opacity: 0.7; }

/* ---------- Groups / table ---------- */
.prices { display: flex; flex-direction: column; gap: 20px; }
.group { background: var(--panel); border: 1px solid var(--border); border-radius: 15px; overflow: hidden; }
.group-header {
  display: flex; align-items: center; justify-content: space-between; padding: 13px 19px;
  border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.group-title { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
.group-title .tag { color: var(--accent); }
.group-count { font-size: 11px; color: var(--muted-2); font-family: var(--mono); background: var(--bg-2); padding: 2px 8px; border-radius: 20px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 9px 19px; font-family: var(--mono);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted-2);
  font-weight: 500; border-bottom: 1px solid var(--border-soft);
}
th.num, td.num { text-align: right; }
th.range-col, td.range-col { width: 200px; }

tbody tr { border-bottom: 1px solid var(--border-soft); cursor: pointer; transition: background 0.12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td { padding: 13px 19px; }

.sym-cell { display: flex; align-items: center; gap: 12px; }
.sym-badge {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; display: grid; place-items: center;
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  background: var(--panel-3); color: var(--accent-2); overflow: hidden; border: 1px solid var(--border);
}
.sym-badge img { width: 100%; height: 100%; object-fit: contain; }
.sym-text b { font-weight: 600; font-family: var(--mono); font-size: 13.5px; }
.sym-text small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; margin-top: 1px; }

.price-cell { font-size: 14.5px; font-weight: 600; }
.pct-badge {
  display: inline-block; min-width: 78px; text-align: right; padding: 4px 10px; border-radius: 7px;
  font-size: 13px; font-weight: 600; font-family: var(--mono);
}
.chg-arrow { margin-right: 4px; font-size: 9px; vertical-align: middle; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--muted); }
.pct-badge.up { background: var(--up-bg); } .pct-badge.down { background: var(--down-bg); }
.pct-badge.flat { background: rgba(124,138,163,0.1); }

.remove-btn {
  background: transparent; border: none; color: var(--muted-2); cursor: pointer; font-size: 13px;
  padding: 4px 7px; border-radius: 6px; line-height: 1; opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
tbody tr:hover .remove-btn { opacity: 1; }
.remove-btn:hover { color: var(--down); background: var(--down-bg); }
.empty-hint { padding: 30px 16px; text-align: center; color: var(--muted); }

/* ---------- News ---------- */
.news { background: var(--panel); border: 1px solid var(--border); border-radius: 15px; position: sticky; top: 92px; overflow: hidden; }
.news-header {
  display: flex; align-items: center; justify-content: space-between; padding: 15px 19px;
  border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.news-header h2 { font-family: var(--serif); font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.news-live { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; color: var(--up); background: var(--up-bg); padding: 4px 9px; border-radius: 20px; }
.news-live .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--up); animation: breathe 1.6s ease-in-out infinite; }
.news-list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 210px); overflow-y: auto; }
.news-list li { border-bottom: 1px solid var(--border-soft); }
.news-list li:last-child { border-bottom: none; }
.news-list a { display: block; padding: 14px 19px; color: var(--text); text-decoration: none; transition: background 0.12s; }
.news-list a:hover { background: var(--panel-2); }
.news-list a:hover .headline { color: var(--accent-2); }
.news-list .headline { font-size: 13px; line-height: 1.5; margin-bottom: 7px; transition: color 0.12s; }
.news-list .meta { font-size: 10.5px; color: var(--muted-2); font-family: var(--mono); letter-spacing: 0.02em; }
.news-empty { padding: 24px 19px; color: var(--muted); }

footer { padding: 15px 26px; color: var(--muted-2); font-size: 11.5px; font-family: var(--mono); border-top: 1px solid var(--border); text-align: center; letter-spacing: 0.02em; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(4, 6, 10, 0.76);
  backdrop-filter: blur(8px); display: grid; place-items: center; padding: 20px; animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  position: relative; width: min(580px, 100%); max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border); border-radius: 20px; padding: 28px;
  box-shadow: var(--shadow); animation: pop 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes pop { from { transform: translateY(14px) scale(0.98); opacity: 0; } }
.modal-close {
  position: absolute; top: 18px; right: 18px; background: var(--panel-3); border: 1px solid var(--border);
  color: var(--muted); width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font-size: 12px;
}
.modal-close:hover { color: var(--text); border-color: var(--accent-2); }
.modal-head { display: flex; align-items: center; gap: 17px; margin-bottom: 18px; padding-right: 40px; }
.modal-logo {
  width: 56px; height: 56px; border-radius: 14px; flex-shrink: 0; display: grid; place-items: center;
  overflow: hidden; background: var(--panel-3); color: var(--accent-2); border: 1px solid var(--border);
  font-family: var(--mono); font-weight: 700; font-size: 16px;
}
.modal-logo img { width: 100%; height: 100%; object-fit: contain; }
.modal-title { flex: 1; min-width: 0; }
.modal-title h2 { margin: 0; font-size: 24px; font-family: var(--mono); letter-spacing: 0.01em; font-weight: 700; }
.modal-name { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.modal-price-block { text-align: right; }
.modal-price { font-size: 23px; font-weight: 600; font-family: var(--mono); }
.modal-change { font-size: 12.5px; font-weight: 600; font-family: var(--mono); margin-top: 4px; }
.modal-range { margin: 0 0 20px; }
.modal-range .rng-lo, .modal-range .rng-hi { min-width: 60px; }
.modal-description { color: var(--text); font-family: var(--serif); font-size: 15px; line-height: 1.62; margin: 0 0 22px; opacity: 0.94; }
.modal-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; margin-bottom: 24px; }
.stat { background: var(--bg-2); border: 1px solid var(--border-soft); border-radius: 11px; padding: 12px 14px; }
.stat .label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-2); margin-bottom: 6px; }
.stat .value { font-size: 14px; font-weight: 600; font-family: var(--mono); }
.modal-news-section h3 { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; margin: 0 0 12px; color: var(--muted); font-weight: 500; }
.modal-news { list-style: none; margin: 0 0 20px; padding: 0; }
.modal-news li { border-bottom: 1px solid var(--border-soft); }
.modal-news li:last-child { border-bottom: none; }
.modal-news a { display: block; padding: 11px 0; color: var(--text); text-decoration: none; }
.modal-news a:hover .mn-headline { color: var(--accent-2); }
.mn-headline { font-size: 13px; line-height: 1.5; margin-bottom: 5px; transition: color 0.12s; }
.mn-meta { font-size: 10.5px; color: var(--muted-2); font-family: var(--mono); }
.modal-link { display: inline-block; color: var(--accent-2); text-decoration: none; font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.modal-link:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) { .overview-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .news { position: static; }
  th.hide-sm, td.hide-sm { display: none; }
}
@media (max-width: 560px) {
  .overview-grid { grid-template-columns: 1fr; }
  .modal-stats { grid-template-columns: repeat(2, 1fr); }
  td, th { padding-left: 13px; padding-right: 13px; }
}
