:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #6d5dfc;
  --primary-soft: rgba(109, 93, 252, 0.12);
  --positive: #0f9f6e;
  --positive-soft: rgba(15, 159, 110, 0.11);
  --negative: #e5484d;
  --negative-soft: rgba(229, 72, 77, 0.11);
  --warning: #d97706;
  --shadow: 0 16px 42px rgba(15, 23, 42, 0.08);
  --radius: 20px;
}

[data-theme="dark"] {
  --bg: #0a0f1d;
  --surface: #111827;
  --surface-alt: #172033;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #243147;
  --primary: #8b7cff;
  --primary-soft: rgba(139, 124, 255, 0.16);
  --positive: #34d399;
  --positive-soft: rgba(52, 211, 153, 0.12);
  --negative: #fb7185;
  --negative-soft: rgba(251, 113, 133, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .25s, color .25s;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 16px; top: -60px; z-index: 999; padding: 12px 16px; background: var(--primary); color: #fff; border-radius: 10px; transition: top .2s; }
.skip-link:focus { top: 16px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: 74px; padding: 0 max(20px, calc((100vw - 1440px) / 2));
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: #fff; font-size: 22px; font-weight: 800; background: linear-gradient(145deg, #8b7cff, #5b45ed); box-shadow: 0 10px 22px rgba(109,93,252,.28); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font-size: 21px; transition: transform .2s, border-color .2s, background .2s; }
.icon-button:hover { transform: translateY(-2px); border-color: var(--primary); background: var(--primary-soft); }
.status-badge { padding: 8px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--positive); background: var(--positive-soft); }
.status-badge.error { color: var(--negative); background: var(--negative-soft); }
.status-badge.loading { color: var(--warning); background: rgba(217,119,6,.12); }

.app-shell { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0 64px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: 26px; }
.hero h1 { max-width: 760px; margin: 6px 0 10px; font-size: clamp(29px, 4vw, 48px); line-height: 1.08; letter-spacing: -0.04em; }
.hero p:not(.eyebrow) { max-width: 760px; margin: 0; color: var(--muted); line-height: 1.6; }
.eyebrow { margin: 0; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
.last-update { min-width: 220px; padding: 16px 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); text-align: right; }
.last-update span, .last-update strong, .last-update small { display: block; }
.last-update span, .last-update small { color: var(--muted); font-size: 11px; }
.last-update strong { margin: 4px 0; font-size: 14px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card, .card { border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
.kpi-card { min-height: 138px; padding: 22px; border-radius: var(--radius); position: relative; overflow: hidden; }
.kpi-card::after { content:""; position:absolute; width:88px; height:88px; right:-30px; top:-30px; border-radius:50%; background:var(--primary-soft); }
.kpi-card span, .kpi-card small { display: block; color: var(--muted); }
.kpi-card span { font-size: 12px; font-weight: 600; }
.kpi-card strong { display: block; margin: 14px 0 8px; font-size: clamp(20px,2vw,27px); letter-spacing: -.03em; }
.kpi-card small { font-size: 11px; }

.card { border-radius: var(--radius); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px; margin-bottom: 20px; box-shadow: none; }
.search-field { flex: 1; min-width: 220px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-alt); color: var(--muted); }
.search-field input { width: 100%; height: 44px; border: 0; outline: 0; background: transparent; color: var(--text); }
.search-field input::placeholder { color: var(--muted); }
.toolbar-controls { display: flex; gap: 10px; }
select { height: 44px; padding: 0 38px 0 12px; border: 1px solid var(--border); border-radius: 12px; outline: 0; background: var(--surface-alt); color: var(--text); }
select:focus, input:focus { box-shadow: 0 0 0 3px var(--primary-soft); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(310px, .8fr); gap: 20px; align-items: start; }
.table-card { padding: 22px; min-width: 0; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.section-header h2 { margin: 5px 0 0; font-size: 20px; letter-spacing: -.02em; }
.section-header.compact { margin-bottom: 14px; }
.counter { padding: 7px 10px; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 11px; font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 10px; color: var(--muted); font-size: 11px; font-weight: 600; text-align: left; white-space: nowrap; }
td { padding: 13px 10px; border-top: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
tbody tr { transition: background .2s; }
tbody tr:hover { background: var(--surface-alt); }
.numeric { text-align: right; }
.coin-cell { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.coin-cell img { width: 32px; height: 32px; }
.coin-cell strong, .coin-cell span { display: block; }
.coin-cell span { margin-top: 2px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.coin-button { border: 0; padding: 0; background: none; color: inherit; text-align: left; }
.favorite-button { border: 0; background: transparent; color: var(--muted); font-size: 19px; }
.favorite-button.active { color: #f59e0b; }
.change { font-weight: 700; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding-top: 20px; }
.pagination button { padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-alt); color: var(--text); }
.pagination button:disabled { opacity: .42; cursor: not-allowed; }
.pagination span { color: var(--muted); font-size: 12px; }
.empty-state { padding: 50px 16px; text-align: center; }
.empty-state > span { font-size: 34px; color: var(--muted); }
.empty-state h3 { margin: 12px 0 6px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 13px; }

.side-column { display: grid; gap: 20px; }
.movers-card, .favorites-card { padding: 20px; box-shadow: none; }
.movers-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.movers-columns h3 { margin: 0 0 8px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.movers-list, .favorites-list { display: grid; gap: 4px; }
.mover-item, .favorite-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 8px; border-radius: 12px; }
.mover-item:hover, .favorite-item:hover { background: var(--surface-alt); }
.mover-coin, .favorite-coin { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mover-coin img, .favorite-coin img { width: 25px; height: 25px; }
.mover-coin strong, .favorite-coin strong { overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.mover-item > strong, .favorite-price { font-size: 11px; }
.favorite-price { text-align: right; }
.favorite-price span { display: block; margin-top: 2px; }
.empty-mini { padding: 20px 6px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }

.portfolio-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 28px max(20px, calc((100% - 1440px) / 2)); border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.footer-brand, .footer-signature { display: grid; gap: 5px; }
.footer-brand strong { color: var(--text); font-size: 15px; letter-spacing: -.01em; }
.footer-brand span { font-size: 11px; }
.footer-signature { justify-items: end; text-align: right; }
.footer-signature > span { color: var(--text); font-weight: 600; }
.footer-links { display: flex; align-items: center; gap: 8px; }
.footer-links a { color: var(--primary); font-weight: 700; text-decoration: none; transition: opacity .2s ease; }
.footer-links a:hover { opacity: .75; text-decoration: underline; }
.footer-links a:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 4px; }

.coin-modal { width: min(900px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); color: var(--text); box-shadow: 0 30px 100px rgba(0,0,0,.35); overflow: auto; }
.coin-modal::backdrop { background: rgba(3,7,18,.66); backdrop-filter: blur(4px); }
.modal-header { position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); }
.coin-heading { display: flex; align-items: center; gap: 13px; }
.coin-heading img { width: 45px; height: 45px; }
.coin-heading h2 { display: inline; margin: 0 8px 0 0; font-size: 21px; }
.coin-heading > div > span:not(.rank-pill) { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.rank-pill { display: block; width: fit-content; margin-bottom: 4px; padding: 3px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 9px; font-weight: 800; }
.modal-loading { padding: 70px 24px; color: var(--muted); text-align: center; }
#modalContent { padding: 24px; }
.modal-price-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-price-row span { color: var(--muted); font-size: 12px; }
.modal-price-row strong { display: block; margin-top: 4px; font-size: 30px; }
.change-pill { padding: 8px 11px; border-radius: 999px; font-weight: 800; }
.change-pill.positive { background: var(--positive-soft); }
.change-pill.negative { background: var(--negative-soft); }
.chart-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.chart-toolbar h3, .about-coin h3 { margin: 0; font-size: 14px; }
.range-buttons { display: flex; gap: 5px; }
.range-buttons button { padding: 6px 9px; border: 0; border-radius: 8px; background: var(--surface-alt); color: var(--muted); font-size: 10px; font-weight: 700; }
.range-buttons button.active { background: var(--primary); color: #fff; }
.chart-container { height: 280px; padding: 12px 0 20px; }
.details-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.details-grid div { padding: 15px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-alt); }
.details-grid span, .details-grid strong { display: block; }
.details-grid span { margin-bottom: 6px; color: var(--muted); font-size: 10px; }
.details-grid strong { font-size: 13px; }
.about-coin { margin-top: 22px; }
.about-coin p { max-height: 150px; overflow: auto; margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 10px; }
.toast { min-width: 260px; max-width: 360px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); font-size: 12px; animation: slideIn .25s ease; }
.toast.error { border-left: 4px solid var(--negative); }
.toast.success { border-left: 4px solid var(--positive); }
@keyframes slideIn { from { transform: translateY(15px); opacity:0; } }

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .topbar { padding: 0 14px; }
  .status-badge { display: none; }
  .app-shell { width: min(100% - 24px, 1440px); padding-top: 24px; }
  .hero { display: block; }
  .last-update { margin-top: 18px; text-align: left; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-controls { display: grid; grid-template-columns: 1fr; }
  .toolbar-controls select { width: 100%; }
  .desktop-column { display: none; }
  .side-column { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: repeat(2,1fr); }
  .chart-toolbar { align-items: flex-start; flex-direction: column; }
  .range-buttons { width: 100%; overflow-x: auto; }
  .portfolio-footer { align-items: flex-start; flex-direction: column; }
  .footer-signature { justify-items: start; text-align: left; }
}
@media (max-width: 480px) {
  .brand span { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card { min-height: 118px; }
  .table-card { padding: 15px; }
  th, td { padding-left: 7px; padding-right: 7px; }
  .movers-columns { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: 1fr; }
  .modal-header, #modalContent { padding: 17px; }
  .modal-price-row strong { font-size: 24px; }
}
