:root {
  color-scheme: dark;
  --bg: #000000;
  --bg2: #0b0b0d;
  --card: #151517;
  --card-hover: #1e1e21;
  --border: #232326;
  --text: #ffffff;
  --text-dim: #8e8e93;
  --accent: #ff9f0a;
  --green: #30d158;
  --red: #ff453a;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: contain;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

button, input {
  font-family: inherit;
  color: inherit;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

.list-wrap, .detail-panel {
  overscroll-behavior: contain;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 0;
  border-bottom: 1px solid var(--border);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-btn, .icon-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  height: 34px;
  min-width: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn {
  padding: 0;
  width: 34px;
  font-size: 15px;
}

.pill-btn:active, .icon-btn:active { background: var(--card-hover); }

.market-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  overflow-x: auto;
  padding: 10px 0 8px;
  font-size: 12px;
  color: var(--text-dim);
  scrollbar-width: none;
}

.market-strip::-webkit-scrollbar { display: none; }

.market-item { white-space: nowrap; }
.market-item strong { color: var(--text); font-weight: 600; margin-left: 4px; }

.updated {
  margin-left: auto;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.search-bar { padding: 4px 0 10px; }

.search-bar input {
  width: 100%;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  outline: none;
}

.search-bar input:focus { border-color: var(--accent); }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  color: #1a1000;
}

/* ---------- Body layout ---------- */

.body-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.list-wrap {
  padding: 10px 12px calc(24px + env(safe-area-inset-bottom));
}

.status-msg {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-dim);
  font-size: 14px;
}

.status-msg button {
  margin-top: 10px;
  border: none;
  background: var(--card);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.coin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.coin-row {
  display: grid;
  grid-template-columns: 24px 1fr 62px minmax(76px, auto) 30px;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 14px;
  cursor: pointer;
}

.coin-row:hover, .coin-row:active { background: var(--card); }

.rank {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

.coin-id {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.coin-id img { border-radius: 50%; flex: none; }

.coin-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.coin-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.coin-symbol {
  font-size: 12px;
  color: var(--text-dim);
}

.spark { width: 62px; height: 28px; display: block; }

.coin-price-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.coin-price {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.coin-price sub { font-size: 9px; }

.change-badge {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral, .change-badge:empty { color: var(--text-dim); }

.star-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.star-btn.active { color: var(--accent); }

/* ---------- Skeleton ---------- */

.skeleton { pointer-events: none; }

.sk {
  background: linear-gradient(90deg, var(--card) 25%, var(--card-hover) 37%, var(--card) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 8px;
}

.sk-avatar { width: 28px; height: 28px; border-radius: 50%; grid-column: 2; justify-self: start; }
.sk-line { height: 12px; grid-column: 2; }
.sk-spark { width: 62px; height: 20px; }
.sk-star { width: 18px; height: 18px; justify-self: end; }

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------- Detail panel ---------- */

.detail-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 90vh;
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(.32,.72,0,1);
  z-index: 40;
  overflow-y: auto;
  padding: 14px 18px calc(28px + env(safe-area-inset-bottom));
}

.detail-panel.open { transform: translateY(0); }

.detail-empty {
  display: none;
  color: var(--text-dim);
  text-align: center;
  padding: 60px 20px;
}

.back-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  margin-bottom: 10px;
}

.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-head img { border-radius: 50%; }

.detail-title { flex: 1; min-width: 0; }
.detail-title h2 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.symbol { font-size: 12px; color: var(--text-dim); }

.star-btn.detail-star, #detailStar {
  font-size: 24px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
}
#detailStar.active { color: var(--accent); }

.detail-price-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 16px 0 10px;
}

.detail-price { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.detail-price sub { font-size: 15px; }

.timeframes {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.timeframes button {
  flex: none;
  border: none;
  background: var(--card);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.timeframes button.active { background: var(--accent); color: #1a1000; }

.chart-wrap {
  position: relative;
  touch-action: none;
  margin-bottom: 20px;
}

.chart-wrap.loading svg { opacity: 0.35; }

#chartSvg { width: 100%; height: 220px; display: block; }

.chart-tooltip {
  position: absolute;
  top: 6px;
  transform: translateX(-50%);
  background: #1c1c1e;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chart-tooltip strong { font-size: 13px; }
.chart-tooltip span { color: var(--text-dim); }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label { font-size: 11px; color: var(--text-dim); }
.stat-value { font-size: 14px; font-weight: 600; }

/* ---------- Desktop layout ---------- */

@media (min-width: 900px) {
  .body-row { flex-direction: row; }

  .list-wrap {
    width: 420px;
    flex: 0 0 420px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    height: calc(100vh - 118px);
  }

  .detail-panel {
    position: static;
    height: auto;
    flex: 1;
    transform: none !important;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg);
    overflow-y: auto;
    padding: 24px 32px;
    max-height: calc(100vh - 118px);
  }

  .detail-empty { display: flex; align-items: center; justify-content: center; height: 100%; }

  .back-btn { display: none; }

  .stats-grid { grid-template-columns: repeat(3, 1fr); }

  #chartSvg { height: 320px; }
}
