:root {
  color-scheme: dark;
  --page: #0d1312;
  --surface: #131d1b;
  --surface-raised: #182522;
  --surface-soft: #1c2a27;
  --line: rgba(224, 241, 235, 0.12);
  --line-strong: rgba(224, 241, 235, 0.19);
  --text: #f2f7f4;
  --muted: #9baca6;
  --quiet: #6e817a;
  --mint: #8de2c0;
  --mint-bright: #c4f9e6;
  --red: #e79191;
  --red-bright: #ffd1d1;
  --neutral: #8fa19c;
  --focus: #e8d48a;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  --radius: 18px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #f4f7f5;
  --surface: #ffffff;
  --surface-raised: #fbfcfb;
  --surface-soft: #edf3f0;
  --line: rgba(22, 48, 39, 0.12);
  --line-strong: rgba(22, 48, 39, 0.19);
  --text: #15231e;
  --muted: #60716b;
  --quiet: #788780;
  --mint: #167557;
  --mint-bright: #0d573f;
  --red: #b44f57;
  --red-bright: #893941;
  --neutral: #63736e;
  --focus: #806816;
  --shadow: 0 16px 44px rgba(36, 64, 52, 0.1);
}

* { box-sizing: border-box; }

html { background: var(--page); }

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 92% -18%, rgba(67, 151, 117, 0.12), transparent 32rem),
    var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input { font: inherit; }

button, a, input { -webkit-tap-highlight-color: transparent; }

button { cursor: pointer; }

a { color: inherit; }

.shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 52px;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 12px;
  left: 12px;
  transform: translateY(-160%);
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--text);
  color: var(--page);
  text-decoration: none;
}

.skip-link:focus { transform: translateY(0); }

.topbar, .control-bar, .section-heading, .detail-symbol-row, .refresh-controls, .toggle, .header-actions, .quote-meta {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--quiet);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.13em;
}

h1, h2, p { margin-top: 0; }

h1, h2 {
  margin-bottom: 0;
  letter-spacing: -0.045em;
}

h1 { font-size: clamp(31px, 4vw, 44px); line-height: 1; }

h2 { font-size: 19px; line-height: 1.1; }

.brand-subtitle, .map-note, .section-heading > p, .earnings-heading > p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions { gap: 14px; }

.quote-meta {
  align-items: flex-end;
  flex-direction: column;
  gap: 1px;
  color: var(--muted);
  font-size: 12px;
}

.quote-meta strong { color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; }

.icon-button, .refresh-button, .mode-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  font-size: 19px;
}

.icon-button:hover, .refresh-button:hover { background: var(--surface-soft); border-color: var(--line-strong); }

.summary-grid {
  display: grid;
  grid-template-columns: 1.03fr 0.94fr 1.35fr;
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card, .detail-panel, .earnings-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.summary-card {
  min-height: 119px;
  padding: 18px 20px;
}

.summary-card > span {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.summary-card > strong {
  display: block;
  font-size: clamp(22px, 2.7vw, 31px);
  font-weight: 720;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.summary-card > small { display: block; margin-top: 9px; color: var(--muted); font-size: 12px; }
.summary-card > small.is-up { color: var(--mint-bright); }
.summary-card > small.is-down { color: var(--red-bright); }

.primary-card { background: linear-gradient(126deg, rgba(73, 162, 125, 0.16), var(--surface) 57%); }

.impact-card { padding-bottom: 14px; }

.impact-list { display: flex; flex-wrap: wrap; gap: 7px; }

.impact-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-raised);
  font-size: 12px;
  font-weight: 670;
  font-variant-numeric: tabular-nums;
}

.impact-chip.is-up { border-color: color-mix(in srgb, var(--mint) 44%, var(--line)); color: var(--mint-bright); }
.impact-chip.is-down { border-color: color-mix(in srgb, var(--red) 44%, var(--line)); color: var(--red-bright); }
.placeholder-text { color: var(--muted); font-size: 12px; }

.control-bar {
  gap: 12px;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.search-field {
  display: flex;
  flex: 1 1 250px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 10px;
  color: var(--quiet);
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.search-field input::placeholder { color: var(--quiet); }

.mode-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-raised);
}

.mode-button {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.mode-button.is-active { background: var(--surface-soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.refresh-controls { gap: 12px; margin-left: auto; }

.toggle { gap: 7px; color: var(--muted); font-size: 12px; font-weight: 620; white-space: nowrap; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle-track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--quiet);
  transition: background 160ms ease;
}

.toggle-track::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 160ms ease;
}

.toggle input:checked + .toggle-track { background: var(--mint); }
.toggle input:checked + .toggle-track::after { transform: translateX(13px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--focus); outline-offset: 3px; }

.refresh-button { min-height: 34px; padding: 0 12px; border-radius: 8px; font-size: 12px; font-weight: 690; white-space: nowrap; }
.refresh-button:disabled { cursor: progress; opacity: 0.58; }

.status-line {
  min-height: 24px;
  padding: 2px 1px 10px;
  color: var(--muted);
  font-size: 12px;
}

.status-line.is-warning { color: var(--red-bright); }
.status-line.is-fresh { color: var(--mint-bright); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 282px;
  align-items: start;
  gap: 16px;
}

.section-heading { justify-content: space-between; gap: 12px; margin: 0 4px 11px; }
.section-heading > p, .earnings-heading > p { text-align: right; }

.map-frame {
  position: relative;
  min-height: clamp(430px, 52vw, 664px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101a17;
  box-shadow: var(--shadow);
}

:root[data-theme="light"] .map-frame { background: #e6eeea; }

.treemap { position: absolute; inset: 0; }

.map-empty {
  display: grid;
  position: absolute;
  z-index: 1;
  inset: 0;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.map-empty[hidden] { display: none; }

.tile {
  position: absolute;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  color: #f7fcf9;
  text-align: left;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  transition: filter 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

:root[data-theme="light"] .tile { border-color: rgba(255, 255, 255, 0.54); }
.tile:hover { z-index: 2; filter: brightness(1.08); transform: scale(1.012); }
.tile:focus-visible { z-index: 3; outline: 3px solid var(--focus); outline-offset: -2px; }
.tile.is-selected { z-index: 2; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.94); }

.tile.is-up { background: rgba(37, 143, 104, var(--tone-strength)); }
.tile.is-down { background: rgba(179, 70, 77, var(--tone-strength)); }
.tile.is-flat { background: rgba(92, 113, 106, 0.8); }

.tile-symbol, .tile-price, .tile-change {
  display: block;
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-symbol { font-weight: 800; letter-spacing: 0.01em; }
.tile-price, .tile-change { font-variant-numeric: tabular-nums; }
.tile-price { opacity: 0.91; }
.tile-change { font-weight: 690; }

.tile.size-xl { padding: 14px; font-size: 15px; }
.tile.size-xl .tile-symbol { font-size: 19px; }
.tile.size-lg { padding: 11px; font-size: 13px; }
.tile.size-lg .tile-symbol { font-size: 16px; }
.tile.size-md { padding: 8px; font-size: 11px; }
.tile.size-md .tile-symbol { font-size: 14px; }
.tile.size-sm { padding: 5px; font-size: 10px; }
.tile.size-sm .tile-price, .tile.size-sm .tile-change { display: none; }
.tile.size-xs { justify-content: center; padding: 3px; font-size: 9px; }
.tile.size-xs .tile-price, .tile.size-xs .tile-change { display: none; }

.map-note { margin: 9px 4px 0; }

.detail-panel { min-height: 300px; padding: 20px; }
.detail-heading { margin-bottom: 22px; }
.detail-empty { color: var(--muted); font-size: 13px; }
.detail-symbol-row { justify-content: space-between; gap: 10px; }
.detail-symbol { font-size: 21px; font-weight: 790; letter-spacing: -0.04em; }
.sector-tag { padding: 3px 7px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font-size: 10px; font-weight: 690; }
.detail-name { margin: 4px 0 18px; color: var(--muted); font-size: 13px; }
.detail-price { margin: 0; font-size: 31px; font-weight: 740; letter-spacing: -0.05em; font-variant-numeric: tabular-nums; line-height: 1; }
.detail-change { margin: 8px 0 20px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.detail-change.is-up { color: var(--mint-bright); }
.detail-change.is-down { color: var(--red-bright); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 10px; margin: 0; }
.detail-grid div { min-width: 0; }
.detail-grid dt { color: var(--quiet); font-size: 10px; font-weight: 690; }
.detail-grid dd { overflow: hidden; margin: 3px 0 0; color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.yahoo-link { display: inline-flex; gap: 5px; margin-top: 23px; color: var(--mint-bright); font-size: 12px; font-weight: 690; text-underline-offset: 3px; }

.earnings-section { margin-top: 16px; padding: 18px; overflow: hidden; }
.earnings-heading { margin: 0 2px 13px; }
.earnings-rail { display: flex; gap: 8px; overflow-x: auto; padding: 0 2px 4px; scrollbar-color: var(--line-strong) transparent; }

.earnings-item {
  display: flex;
  width: 130px;
  min-width: 130px;
  min-height: 72px;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-raised);
}

.earnings-item strong { font-size: 13px; }
.earnings-item span { color: var(--muted); font-size: 11px; }
.earnings-item.is-upcoming { border-color: color-mix(in srgb, var(--mint) 42%, var(--line)); }
.earnings-item.is-recent { border-color: color-mix(in srgb, var(--focus) 35%, var(--line)); }
.earnings-item.is-missing { opacity: 0.72; }

.noscript { margin: 24px; color: #131d1b; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

@media (max-width: 860px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .impact-card { grid-column: 1 / -1; min-height: auto; }
  .workspace { grid-template-columns: 1fr; }
  .detail-panel { min-height: auto; }
  .detail-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); column-gap: 22px; }
  .detail-symbol-row, .detail-name, .detail-price, .detail-change, .yahoo-link { grid-column: 1; }
  .detail-grid { grid-column: 2; grid-row: 1 / span 4; align-content: start; }
  .yahoo-link { align-self: end; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 24px, 1440px); padding-top: 22px; }
  .topbar { align-items: flex-start; }
  .quote-meta { display: none; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary-card { min-height: 108px; padding: 15px; }
  .impact-card { grid-column: 1 / -1; }
  .control-bar { flex-wrap: wrap; gap: 8px; }
  .search-field { flex-basis: 100%; height: 32px; padding: 0 4px; }
  .refresh-controls { margin-left: auto; }
  .toggle { font-size: 11px; }
  .refresh-button { padding: 0 9px; }
  .section-heading { align-items: flex-end; }
  .section-heading > p, .earnings-heading > p { max-width: 140px; font-size: 11px; }
  .map-frame { min-height: 470px; }
  .tile.size-xl { padding: 10px; font-size: 12px; }
  .tile.size-xl .tile-symbol { font-size: 16px; }
  .tile.size-lg { padding: 7px; font-size: 11px; }
  .tile.size-lg .tile-symbol { font-size: 14px; }
  .detail-content { display: block; }
  .detail-grid { margin-top: 20px; }
  .earnings-section { padding: 15px; }
}

@media (max-width: 390px) {
  .shell { width: min(100% - 20px, 1440px); }
  h1 { font-size: 32px; }
  .summary-card > strong { font-size: 23px; }
  .refresh-controls { width: 100%; justify-content: space-between; }
  .map-frame { min-height: 450px; }
  .tile.size-md { padding: 5px; font-size: 10px; }
  .tile.size-md .tile-symbol { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
