:root {
  color-scheme: dark;
  --bg: #090b10;
  --bg-elevated: #11151d;
  --panel: #151b24;
  --panel-hover: #1a2130;
  --text: #f3f6fb;
  --muted: #8d98a8;
  --border: #273142;
  --accent: #4f8cff;
  --up: #22c55e;
  --up-soft: rgba(34, 197, 94, 0.14);
  --down: #ef4444;
  --down-soft: rgba(239, 68, 68, 0.14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background:
    radial-gradient(circle at top, rgba(79, 140, 255, 0.12), transparent 34%),
    var(--bg);
  color: var(--text);
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding:
    2rem
    max(1.25rem, env(safe-area-inset-right))
    max(3rem, calc(1.5rem + env(safe-area-inset-bottom)))
    max(1.25rem, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.03em;
}

.brand p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.meta {
  text-align: right;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:hover {
  color: var(--accent);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.25rem;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  min-height: 44px;
  touch-action: manipulation;
}

.nav-link:hover {
  color: var(--text);
  background: var(--panel-hover);
}

.nav-link.active {
  color: var(--text);
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.16);
}

.page-intro {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.link-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(79, 140, 255, 0.12);
  color: var(--accent);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  min-height: 36px;
  font-size: 0.82rem;
  cursor: pointer;
  touch-action: manipulation;
}

.link-btn:hover {
  background: rgba(79, 140, 255, 0.22);
}

.timeline-type.inline {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
}

.calendar-row .symbol {
  font-weight: 600;
}

.alert-banner {
  display: none;
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: var(--warn-soft);
  border-radius: 14px;
}

.alert-banner.visible {
  display: block;
}

.alert-banner h2 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
}

.alert-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.alert-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(245, 158, 11, 0.28);
  font-size: 0.85rem;
}

.quotes-sheet {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.sheet-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.quotes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.quotes-table th,
.quotes-table td {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.quotes-table th {
  background: #1c2430;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.quotes-table th.num,
.quotes-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.quotes-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.quote-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

.quote-row:hover {
  background: var(--panel-hover) !important;
}

.quote-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.quote-row.alert {
  background: rgba(245, 158, 11, 0.08);
}

.quote-row .symbol {
  font-weight: 600;
  white-space: nowrap;
}

.quote-row .name {
  color: var(--text);
  min-width: 8rem;
}

.quote-row .price {
  font-weight: 600;
}

.quote-row .change.up {
  color: var(--up);
}

.quote-row .change.down {
  color: var(--down);
}

.quote-row .change.flat {
  color: var(--muted);
}

.quote-row .alerts {
  white-space: nowrap;
}

.quote-row .muted {
  color: var(--muted);
}

.quote-row .important-dates-cell {
  min-width: 9rem;
  max-width: 14rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

.quote-row .important-dates-cell:hover {
  color: var(--text);
}

.quote-row .important-dates {
  color: var(--text);
}

.timeline-wrap {
  position: relative;
  min-height: 240px;
  max-height: min(70vh, 640px);
  overflow: auto;
}

.timeline-loading,
.timeline-error,
.timeline-empty {
  margin: 0;
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
}

.timeline-error {
  color: var(--down);
}

.timeline.hidden {
  display: none;
}

.timeline-track {
  position: relative;
  padding: 0.5rem 0 0.5rem 1.4rem;
}

.timeline-track::before {
  content: "";
  position: absolute;
  left: 0.45rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, rgba(141, 152, 168, 0.35), rgba(245, 158, 11, 0.85), rgba(79, 140, 255, 0.75));
}

.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.timeline-marker {
  width: 0.9rem;
  height: 0.9rem;
  margin-top: 0.2rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--panel);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.18);
}

.timeline-item.past .timeline-marker {
  border-color: rgba(141, 152, 168, 0.8);
}

.timeline-item.current .timeline-marker {
  border-color: #fbbf24;
  background: rgba(245, 158, 11, 0.25);
}

.timeline-item.future .timeline-marker {
  border-color: rgba(79, 140, 255, 0.85);
  background: rgba(79, 140, 255, 0.18);
}

.timeline-content {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
}

.timeline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.timeline-date {
  color: #fbbf24;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timeline-type {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.timeline-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.timeline-notes {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.timeline-link {
  display: inline-block;
  margin-top: 0.45rem;
  color: var(--accent);
  font-size: 0.8rem;
  text-decoration: none;
}

.timeline-link:hover {
  text-decoration: underline;
}

.quote-row .important-dates-cell.has-events .important-dates-sources {
  display: block;
  margin-top: 0.2rem;
  color: var(--accent);
  font-size: 0.72rem;
  line-height: 1.3;
}

.timeline-summary-label {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.timeline-sources-label {
  margin-top: 0.65rem;
}

.timeline-source-links {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.timeline-source-link {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem 0.55rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(79, 140, 255, 0.35);
  background: rgba(79, 140, 255, 0.1);
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.35;
}

.timeline-source-link:hover {
  background: rgba(79, 140, 255, 0.18);
  border-color: rgba(79, 140, 255, 0.55);
}

.timeline-source-publisher {
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.timeline-source-title {
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-source-icon {
  color: var(--accent);
  font-size: 0.9rem;
}

.timeline-summaries {
  margin-top: 0.65rem;
  display: grid;
  gap: 0.75rem;
}

.timeline-summary {
  padding: 0.7rem 0.75rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.timeline-price-badge {
  display: inline-block;
  margin-bottom: 0.45rem;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}

.timeline-price-badge.up {
  color: var(--up);
  background: var(--up-soft);
  border-color: rgba(34, 197, 94, 0.28);
}

.timeline-price-badge.down {
  color: var(--down);
  background: var(--down-soft);
  border-color: rgba(239, 68, 68, 0.28);
}

.timeline-price-badge.mixed,
.timeline-price-badge.unclear {
  color: #fbbf24;
  background: var(--warn-soft);
  border-color: rgba(245, 158, 11, 0.28);
}

.timeline-summary-body {
  margin: 0;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.5;
}

.timeline-today {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.35rem 0 1rem;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.timeline-today::before {
  content: "";
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.timeline-today span {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge.warn {
  color: #fbbf24;
  background: var(--warn-soft);
  border-color: rgba(245, 158, 11, 0.28);
}

.modal-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  margin-bottom: 1rem;
}

.modal-metric {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.modal-metric strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.modal-metric.alert-metric strong {
  color: #fbbf24;
}

.period-block {
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}

.period-title {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.65rem;
}

.period-row + .period-row {
  margin-top: 0.7rem;
}

.period-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  margin-bottom: 0.35rem;
}

.period-head strong {
  font-weight: 600;
}

.period-head span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #7aa7ff);
}

.bar.alert > span {
  background: linear-gradient(90deg, var(--warn), #fbbf24);
}

.footer {
  margin-top: 1.2rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.footer.error {
  color: var(--down);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: min(90vh, 90dvh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #171d27, #10151d);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 1.2rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.modal-subtitle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.6rem;
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.modal-subtitle .modal-price {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.modal-subtitle .change {
  font-variant-numeric: tabular-nums;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.88rem;
}

.modal-subtitle .change.up {
  color: var(--up);
  background: var(--up-soft);
}

.modal-subtitle .change.down {
  color: var(--down);
  background: var(--down-soft);
}

.modal-subtitle .change.flat {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.modal-subtitle .modal-period {
  color: var(--muted);
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  width: 2.75rem;
  height: 2.75rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn:hover {
  background: var(--panel-hover);
}

.range-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.range-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  min-height: 44px;
  font-size: 0.82rem;
  cursor: pointer;
  touch-action: manipulation;
}

.range-btn.active {
  color: var(--text);
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.16);
}

.chart-wrap {
  position: relative;
  min-height: 360px;
  height: min(360px, 45dvh);
}

#price-chart {
  width: 100% !important;
  height: 100% !important;
  min-height: 240px;
}

.chart-loading,
.chart-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
}

.chart-error {
  color: var(--down);
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .topbar,
  .footer {
    flex-direction: column;
    align-items: stretch;
  }

  .meta {
    text-align: left;
  }

  .footer {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .page {
    padding:
      1rem
      max(0.85rem, env(safe-area-inset-right))
      max(1.5rem, calc(0.75rem + env(safe-area-inset-bottom)))
      max(0.85rem, env(safe-area-inset-left));
  }

  .brand h1 {
    font-size: 1.5rem;
  }

  .brand p,
  .meta {
    font-size: 0.85rem;
  }

  .quotes-sheet {
    border: none;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }

  .sheet-scroll {
    overflow-x: visible;
  }

  .quotes-table {
    font-size: 0.9rem;
  }

  .quotes-table thead {
    display: none;
  }

  .quotes-table tbody tr {
    display: block;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    overflow: hidden;
  }

  .quotes-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .quotes-table td {
    display: grid;
    grid-template-columns: minmax(5.5rem, 42%) 1fr;
    gap: 0.5rem 0.75rem;
    align-items: center;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 0.85rem;
    text-align: left;
  }

  .quotes-table td.num {
    text-align: right;
    grid-template-columns: minmax(5.5rem, 42%) 1fr;
  }

  .quotes-table td.num::before {
    text-align: left;
  }

  .quotes-table td:last-child {
    border-bottom: none;
  }

  .quotes-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .quotes-table td.symbol {
    display: block;
    background: #1c2430;
    font-size: 1.05rem;
    font-weight: 600;
    padding: 0.8rem 0.85rem;
  }

  .quotes-table td.symbol::before {
    content: none;
  }

  .quote-row {
    touch-action: manipulation;
  }

  .quote-row .name {
    min-width: 0;
  }

  .quote-row .important-dates-cell {
    min-width: 0;
    max-width: none;
    min-height: 44px;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-panel {
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px));
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    padding:
      1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .modal-header h2 {
    font-size: 1.15rem;
  }

  .modal-subtitle {
    font-size: 0.85rem;
  }

  .chart-wrap {
    min-height: 220px;
    height: min(280px, 42dvh);
  }

  .timeline-wrap {
    max-height: calc(100dvh - 7.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .quotes-table th:first-child,
  .quotes-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
    box-shadow: 1px 0 0 var(--border);
  }

  .quotes-table th:first-child {
    background: #1c2430;
  }

  .quotes-table tbody tr:nth-child(even) td:first-child {
    background: #151922;
  }

  .quotes-table tbody tr:hover td:first-child {
    background: var(--panel-hover);
  }
}
