:root {
  --bg: #0a0a0a;
  --bg-elevated: #121212;
  --bg-row: #141414;
  --bg-row-hover: #1a1a1a;
  --border: #222;
  --text: #f5f5f5;
  --muted: #8a8a8a;
  --green: #00c805;
  --green-dim: rgba(0, 200, 5, 0.15);
  --red: #ff5000;
  --red-dim: rgba(255, 80, 0, 0.15);
  --peach: #ff8a5c;
  --peach-soft: rgba(255, 138, 92, 0.18);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

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

.peach { font-size: 28px; line-height: 1; }

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#searchInput {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0 14px;
  font-size: 16px; /* avoid iOS zoom */
  outline: none;
}
#searchInput:focus { border-color: var(--peach); }
#searchInput::placeholder { color: #666; }

.add-btn {
  height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  background: var(--peach);
  color: #111;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.add-btn:active { transform: scale(0.97); }

.hint {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--red);
}

.status {
  min-height: 1.2em;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.watchlist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  background: var(--bg-row);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}
.row:active { background: var(--bg-row-hover); }
.row.private { cursor: default; opacity: 0.92; }

.row-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ticker {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.name {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spark {
  width: 72px;
  height: 28px;
  margin-top: 6px;
  opacity: 0.9;
}

.row-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.price-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.price {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.05rem;
  white-space: nowrap;
}

.pct {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.pct.up { color: var(--green); background: var(--green-dim); }
.pct.down { color: var(--red); background: var(--red-dim); }
.pct.flat { color: var(--muted); background: #1c1c1c; }

.change-abs {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
}

.badge-private {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--peach);
  background: var(--peach-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.row-actions {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.remove-btn {
  border: none;
  background: transparent;
  color: #555;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 4px;
}
.remove-btn:hover { color: var(--red); }

.footer {
  margin-top: 18px;
  text-align: center;
  font-size: 0.72rem;
  color: #555;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.dot { opacity: 0.5; }

/* Detail sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: min(88dvh, 720px);
  overflow-y: auto;
  background: #111;
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 12px 20px calc(28px + var(--safe-bottom));
  animation: slideUp 0.22s ease;
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #333;
  margin: 0 auto 12px;
}
.sheet-close {
  position: absolute;
  top: 10px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #1c1c1c;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.detail-header { margin-bottom: 8px; padding-right: 40px; }
.detail-ticker { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: -0.02em; }
.detail-name { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }

.detail-price-block {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0 8px;
}
.detail-price {
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  letter-spacing: -0.03em;
}
.detail-pct {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  padding: 5px 10px;
  border-radius: 8px;
}
.detail-pct.up { color: var(--green); background: var(--green-dim); }
.detail-pct.down { color: var(--red); background: var(--red-dim); }
.detail-pct.flat { color: var(--muted); background: #1c1c1c; }

.detail-change {
  color: var(--muted);
  font-size: 0.9rem;
  font-family: var(--mono);
  margin-bottom: 16px;
}

.range-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.range-tab {
  flex: 1;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}
.range-tab.active {
  background: var(--peach-soft);
  color: var(--peach);
  border-color: transparent;
}

.chart-wrap {
  background: var(--bg-elevated);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 12px;
  margin-bottom: 16px;
}
.chart-wrap svg { width: 100%; height: 140px; display: block; }

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.meta-item {
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}
.meta-label { font-size: 0.7rem; color: var(--muted); margin-bottom: 4px; }
.meta-value {
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 0.95rem;
}

.skeleton {
  height: 78px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #141414 25%, #1c1c1c 50%, #141414 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
