:root {
  color-scheme: dark;
  --bg: #06101e;
  --panel: #0c192b;
  --line: #223653;
  --line-strong: #36557f;
  --text: #edf4ff;
  --muted: #98abc4;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --positive: #4ade80;
  --negative: #fb7185;
  --shadow: 0 24px 64px rgba(1, 6, 16, 0.32);
}

* { box-sizing: border-box; }
html { background: var(--bg); }

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 85% -10%, rgba(56, 189, 248, 0.13), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, select, input { font: inherit; }
a { color: var(--accent); }

.page-shell {
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: 0 12px 52px;
}

.site-header {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 15px;
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(125, 211, 252, 0.45);
  border-radius: 9px;
  background: rgba(14, 165, 233, 0.12);
  color: var(--accent);
  font-size: 13px;
}

.compact-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.compact-nav a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 0 9px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.compact-nav a:hover,
.compact-nav a:focus-visible { color: var(--text); }
.compact-nav .dashboard-link { display: none; }

.chart-hero {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(10, 23, 40, 0.94);
  box-shadow: var(--shadow);
}

.chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 14px 8px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 0;
  font-size: clamp(22px, 7vw, 34px);
  line-height: 1.1;
}
h2 {
  margin-bottom: 10px;
  font-size: 20px;
}

.data-badge {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid rgba(125, 211, 252, 0.28);
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.chart-controls {
  display: grid;
  gap: 10px;
  padding: 8px 14px 10px;
}

.control-field,
.interval-control {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.control-field > span,
.interval-control legend {
  display: block;
  margin-bottom: 5px;
  padding: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.control-field select {
  width: 100%;
  min-height: 44px;
  padding: 0 38px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #091526;
  color: var(--text);
  cursor: pointer;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #091526;
}

.segmented-control label {
  position: relative;
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.segmented-control input:checked + span {
  background: #173454;
  color: var(--text);
}

.segmented-control input:focus-visible + span,
.control-field select:focus-visible,
.retry-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.price-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 4px 12px;
  padding: 9px 14px 11px;
  border-top: 1px solid rgba(34, 54, 83, 0.7);
}

.price-primary { min-width: 0; }
.summary-label,
.freshness-copy span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.price-primary strong {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  font-size: clamp(25px, 8vw, 38px);
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.daily-change {
  align-self: center;
  font-size: 14px;
  font-weight: 750;
  text-align: right;
}

.daily-change.is-positive { color: var(--positive); }
.daily-change.is-negative { color: var(--negative); }
.daily-change.is-neutral { color: var(--muted); }

.freshness-copy {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.freshness-copy span { display: inline; }
.freshness-copy strong {
  color: #cbd9eb;
  font-weight: 650;
}

.chart-frame {
  position: relative;
  height: clamp(330px, 53svh, 560px);
  min-height: 330px;
  overflow: hidden;
  border-block: 1px solid var(--line);
  background: #050b14;
}

#tv_chart_container {
  width: 100%;
  height: 100%;
}

.chart-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 11, 20, 0.93);
  text-align: center;
}

.chart-state[hidden] { display: none; }
.chart-state-content { max-width: 420px; }
.chart-state strong {
  display: block;
  font-size: 16px;
}
.chart-state p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.chart-state.is-error strong { color: #fecdd3; }

.loading-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.45);
  animation: loading-pulse 1.4s infinite;
}

.chart-state.is-error .loading-dot {
  background: var(--negative);
  animation: none;
}

@keyframes loading-pulse {
  70% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

.retry-button {
  min-width: 112px;
  min-height: 44px;
  margin-top: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #173454;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.chart-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 14px;
  color: var(--muted);
  font-size: 11px;
}

.indicator-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 4px 14px 14px;
}

.indicator-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(54, 85, 127, 0.55);
  border-radius: 10px;
  background: rgba(14, 30, 51, 0.76);
}

.indicator-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.indicator-card strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.information-grid {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.information-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.information-card p:not(.eyebrow) {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.information-card p:last-child { margin-bottom: 0; }

.site-footer {
  margin-top: 20px;
  padding: 16px 4px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.site-footer p { margin-bottom: 7px; }

@media (max-width: 520px) {
  .compact-nav a:not(:last-child) { display: none; }
  .compact-nav .dashboard-link { display: inline-flex; }
}

@media (min-width: 680px) {
  .page-shell { padding-inline: 20px; }
  .site-header { min-height: 68px; }
  .compact-nav .dashboard-link { display: inline-flex; }
  .chart-heading { padding: 20px 22px 10px; }

  .chart-controls {
    grid-template-columns: minmax(220px, 0.8fr) minmax(330px, 1.2fr);
    align-items: end;
    padding: 10px 22px 14px;
  }

  .price-summary {
    grid-template-columns: minmax(0, auto) auto 1fr;
    justify-content: start;
    align-items: center;
    padding: 12px 22px;
  }

  .daily-change {
    min-width: 150px;
    text-align: left;
  }

  .freshness-copy {
    grid-column: auto;
    justify-self: end;
  }

  .chart-frame {
    height: min(66vh, 680px);
    min-height: 460px;
  }

  .chart-meta {
    flex-direction: row;
    justify-content: space-between;
    gap: 20px;
    padding-inline: 22px;
  }

  .indicator-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 7px 22px 20px;
  }

  .information-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1000px) {
  .page-shell { padding-inline: 28px; }
  .chart-hero { border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-dot { animation: none; }
}
