:root {
  --bg: #07090f;
  --bg-2: #0c1019;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf3;
  --muted: #8a94a7;
  --faint: #5a6377;
  --accent: #34d399;
  --accent-ink: #04140d;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --warn: #fbbf24;
  --glow-1: rgba(52, 211, 153, 0.13);
  --glow-2: rgba(99, 102, 241, 0.12);
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.7);
  --radius: 18px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-2: #ffffff;
  --surface: rgba(255, 255, 255, 0.75);
  --surface-2: rgba(15, 23, 42, 0.04);
  --surface-3: rgba(15, 23, 42, 0.08);
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --muted: #5b6475;
  --faint: #94a0b4;
  --accent: #059669;
  --accent-ink: #ffffff;
  --accent-soft: rgba(5, 150, 105, 0.1);
  --glow-1: rgba(16, 185, 129, 0.14);
  --glow-2: rgba(99, 102, 241, 0.1);
  --shadow: 0 20px 50px -24px rgba(15, 23, 42, 0.25);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  font: 500 11px/1 var(--mono);
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--muted);
}
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vw 40vw at 10% -10%, var(--glow-1), transparent 60%),
    radial-gradient(50vw 40vw at 100% 0%, var(--glow-2), transparent 60%);
}

.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1240px; width: 100%; margin: 0 auto; padding: 12px 16px 4px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.brand svg { stroke: none; }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); transition: color .15s, background .15s, border-color .15s, transform .1s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--surface-3); border-color: var(--border-strong); }
.icon-btn:active:not(:disabled) { transform: scale(.95); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Layout ---------- */
.wrap { flex: 1; max-width: 1240px; width: 100%; margin: 0 auto; padding: 6px 16px 20px; display: grid; gap: 10px; align-content: start; }

/* ---------- Controls ---------- */
.controls { padding: 10px; display: grid; gap: 8px; position: relative; z-index: 5; }

/* Search and timeframes share one row; timeframes drop below when space runs out. */
.controls-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.search { position: relative; display: flex; align-items: center; flex: 1 1 380px; min-width: 0; }
.search-icon { position: absolute; left: 11px; width: 14px; height: 14px; color: var(--faint); pointer-events: none; }
#tickerInput {
  flex: 1; min-width: 0; height: 34px; padding: 0 84px 0 32px;
  font: 400 14px Inter, system-ui, sans-serif; letter-spacing: .01em;
  color: var(--text); background: transparent;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#tickerInput::placeholder { color: var(--faint); font-weight: 400; font-size: 13px; }
#tickerInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .hint { position: absolute; right: 66px; }
.go-btn {
  position: absolute; right: 4px; height: 26px; padding: 0 11px;
  border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 600; transition: filter .15s, transform .1s;
}
.go-btn:hover { filter: brightness(1.08); }
.go-btn:active { transform: scale(.97); }

.suggestions {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; margin: 0; padding: 6px;
  list-style: none; max-height: 420px; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: 0 24px 60px -12px rgba(0,0,0,.6);
  animation: pop .14s ease-out;
}
.suggestions li {
  display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
}
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--surface-3); }
.suggestions .s-sym { font: 600 14px var(--mono); }
.suggestions .s-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.suggestions .s-tags { display: flex; gap: 4px; }
.suggestions mark { background: none; color: var(--accent); }
.suggestions .s-empty { display: block; color: var(--muted); cursor: default; }
.suggestions .s-empty:hover { background: none; }

.badge {
  font: 600 10px/1 Inter, sans-serif; letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 6px; border-radius: 6px; color: var(--muted); background: var(--surface-3);
}
.badge.stk { color: #60a5fa; background: rgba(96,165,250,.12); }
.badge.etf { color: #a78bfa; background: rgba(167,139,250,.13); }
.badge.fut { color: #fbbf24; background: rgba(251,191,36,.12); }
.badge.fx { color: #22d3ee; background: rgba(34,211,238,.12); }
.badge.crypto { color: #fb923c; background: rgba(251,146,60,.13); }
.badge.idx { color: #f472b6; background: rgba(244,114,182,.12); }
.badge.tag { color: var(--accent); background: var(--accent-soft); }

/* Timeframes */
.tf-row { display: flex; flex-wrap: wrap; gap: 6px; flex: 0 1 auto; }
.tf-group { display: inline-flex; align-items: center; height: 34px; padding: 2px; gap: 0; background: transparent; border: 1px solid var(--border); border-radius: 8px; }
.tf-group-label { align-self: center; padding: 0 5px 0 6px; font-size: 9px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.tf-btn {
  min-width: 32px; height: 28px; padding: 0 7px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); font: 500 12px var(--mono);
  transition: background .15s, color .15s;
}
.tf-btn:hover { color: var(--text); }
.tf-btn[aria-checked="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Recents */
.recents { display: flex; align-items: center; gap: 6px; min-width: 0; }
.recents-label { font-size: 9px; color: var(--faint); font-weight: 500; text-transform: uppercase; letter-spacing: .08em; }
.chips { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 22px; padding: 0 7px; border-radius: 6px;
  border: 1px solid transparent; background: transparent;
  font: 400 11px var(--mono); color: var(--muted); transition: border-color .15s, background .15s;
}
.chip:hover { color: var(--accent); background: var(--accent-soft); }
.link-btn { border: 0; background: none; color: var(--faint); font-size: 11px; padding: 4px; margin-left: auto; }
.link-btn:hover { color: var(--text); }

/* ---------- Chart card ---------- */
.chart-card { padding: 10px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chart-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.chart-title .sym { font: 700 18px var(--mono); letter-spacing: -.02em; }
.chart-title .name { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48ch; }
.tf-pill:empty { display: none; }
.tf-pill { font: 600 12px var(--mono); padding: 3px 8px; border-radius: 7px; border: 1px solid var(--border-strong); color: var(--muted); }
.toolbar { display: flex; gap: 6px; }

.stage {
  position: relative; aspect-ratio: 12 / 7; width: 100%;
  border-radius: 12px; overflow: hidden; background: #000;
  border: 1px solid var(--border);
}
.stage img { width: 100%; height: 100%; object-fit: contain; display: block; animation: fade .35s ease-out; }
.stage:fullscreen { border-radius: 0; border: 0; aspect-ratio: auto; display: grid; place-items: center; }

.empty, .error {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 24px; text-align: center; color: #8a94a7; background: radial-gradient(circle at 50% 40%, #0f1520, #000 70%);
}
.empty svg { width: 64px; height: 64px; color: #34d399; opacity: .7; stroke-width: 2.4; }
.empty p, .error p { margin: 0; max-width: 42ch; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.quick .chip { color: #e8ecf3; border-color: rgba(255,255,255,.1); background: rgba(255,255,255,.05); }
.error svg { width: 40px; height: 40px; color: var(--danger); }
.ghost-btn { height: 36px; padding: 0 16px; border-radius: 10px; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.05); color: #e8ecf3; }
.ghost-btn:hover { background: rgba(255,255,255,.1); }

.skeleton {
  position: absolute; inset: 0;
  background: linear-gradient(100deg, #05070b 30%, #111827 50%, #05070b 70%);
  background-size: 300% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton::after {
  content: ""; position: absolute; inset: 18% 6% 26% 4%;
  background: linear-gradient(to top right, transparent 49%, rgba(52,211,153,.18) 50%, transparent 51%);
}

.chart-foot { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--faint); min-height: 18px; }
.stale { color: var(--warn); }

/* ---------- Footer / toast ---------- */
.foot {
  max-width: 1240px; width: 100%; margin: 0 auto; padding: 8px 16px 24px;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--faint);
}
.foot .keys { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.foot .keys kbd { margin-left: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes fade { from { opacity: 0; transform: scale(.995); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .topbar { padding-top: 10px; }
  .controls { padding: 8px; }
  #tickerInput { height: 38px; font-size: 16px; padding-right: 72px; }
  #tickerInput::placeholder { font-size: 14px; }
  .search .hint { display: none; }
  .go-btn { padding: 0 11px; height: 28px; }
  .tf-row { flex: 1 1 100%; flex-wrap: nowrap; gap: 6px; }
  .tf-group { height: 34px; }
  .tf-group:first-child { flex: 5; } .tf-group:last-child { flex: 3; }
  .tf-group-label { display: none; }
  .tf-btn { flex: 1; min-width: 0; padding: 0; }
  .suggestions li { grid-template-columns: 76px 1fr auto; gap: 8px; }
  .suggestions .s-tags .tag { display: none; }
  .chart-card { padding: 8px; }
  .chart-title .sym { font-size: 16px; }
  .chart-head { flex-wrap: nowrap; gap: 8px; }
  .chart-title { flex-wrap: nowrap; gap: 6px; flex: 1; }
  .chart-title .name { flex: 1; min-width: 0; font-size: 12px; }
  .toolbar { gap: 4px; flex: none; }
  #stage img { cursor: zoom-in; }
  .foot .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
