/* ============================================================
   PumpOS — Core stylesheet
   iOS 17 inspired: translucency, blur, rounded cards, motion
   Theme palettes live in themes/dark.css & themes/light.css
   ============================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overscroll-behavior-y: none;
}

:root {
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --gap: 14px;
  --tabbar-h: 64px;
  --nav-h: 52px;
  --font-display: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
             system-ui, Roboto, Helvetica, Arial, sans-serif;
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.01em;
  transition: background 0.4s var(--ease-ios), color 0.4s var(--ease-ios);
}

/* Ambient gradient mesh behind the translucent UI */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -2;
  background:
    radial-gradient(40% 35% at 12% 8%, color-mix(in srgb, var(--tint) 26%, transparent), transparent 70%),
    radial-gradient(36% 32% at 88% 4%, color-mix(in srgb, var(--purple) 24%, transparent), transparent 70%),
    radial-gradient(48% 40% at 70% 92%, color-mix(in srgb, var(--teal) 18%, transparent), transparent 72%);
  filter: saturate(1.05);
  opacity: 0.85;
  pointer-events: none;
}
/* subtle film grain */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

#app {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------------- Navigation bar ---------------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: var(--safe-top);
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 0.5px solid var(--hairline);
}
.navbar-inner {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 10px;
}
.nav-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.nav-title .brand-os { color: var(--tint); }
.nav-back {
  appearance: none;
  border: none;
  background: none;
  color: var(--tint);
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  padding: 6px 6px 6px 0;
}
.nav-actions { display: flex; gap: 6px; align-items: center; }
.nav-icon-btn {
  appearance: none;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s var(--ease-ios), background 0.2s;
}
.nav-icon-btn:active { transform: scale(0.88); }
.nav-icon-btn svg { width: 19px; height: 19px; }

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  font-family: var(--font-display);
}
.live-dot i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 70%, transparent);
  animation: pulse 1.8s infinite;
}
.live-dot.paused i { background: var(--text-3); animation: none; box-shadow: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* large title */
.large-title {
  padding: 6px 18px 4px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.subhead {
  padding: 0 18px 8px;
  color: var(--text-3);
  font-size: 13px;
}

/* ---------------- Main scroll area ---------------- */
.view {
  flex: 1;
  padding: 4px 0 calc(var(--tabbar-h) + var(--safe-bottom) + 22px);
  animation: viewIn 0.42s var(--ease-ios);
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.container { padding: 0 14px; }

/* segmented control */
.segmented {
  display: flex;
  gap: 2px;
  margin: 8px 14px 10px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 11px;
}
.segmented button {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, background 0.25s var(--ease-ios), transform 0.1s;
}
.segmented button.active {
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}
.segmented button:active { transform: scale(0.96); }

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.card.pressable { cursor: pointer; transition: transform 0.16s var(--ease-ios); }
.card.pressable:active { transform: scale(0.975); }

.list {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* coin row card */
.coin {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
}
.coin .avatar {
  width: 46px; height: 46px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.coin .avatar::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(160deg, rgba(255,255,255,0.28), transparent 55%);
}
.coin .meta { min-width: 0; }
.coin .name {
  font-size: 15.5px; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.coin .ticker { color: var(--text-3); font-weight: 500; font-size: 13px; }
.coin .sub {
  margin-top: 3px;
  color: var(--text-2);
  font-size: 12px;
  font-family: var(--font-display);
  display: flex; gap: 10px; flex-wrap: wrap;
}
.coin .sub b { color: var(--text); font-weight: 600; }
.coin .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.chg { font-family: var(--font-display); font-size: 13px; font-weight: 600; }
.chg.up { color: var(--green); }
.chg.down { color: var(--red); }
.chg.flat { color: var(--text-3); }

/* tags */
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 3px 8px;
  border-radius: 7px;
  white-space: nowrap;
}
.tag.momentum { color: var(--green); background: color-mix(in srgb, var(--green) 16%, transparent); }
.tag.stable   { color: var(--teal); background: color-mix(in srgb, var(--teal) 16%, transparent); }
.tag.risk     { color: var(--red); background: color-mix(in srgb, var(--red) 16%, transparent); }
.tag.suspicious { color: var(--orange); background: color-mix(in srgb, var(--orange) 16%, transparent); }
.tag.fresh    { color: var(--purple); background: color-mix(in srgb, var(--purple) 16%, transparent); }
.tag.neutral  { color: var(--text-2); background: var(--surface-2); }

/* score ring */
.score-ring { position: relative; width: 46px; height: 46px; }
.score-ring svg { transform: rotate(-90deg); display: block; }
.score-ring .val {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700; font-size: 14px;
}

/* sparkline */
.spark { display: block; width: 100%; height: 38px; }

/* section header */
.section-h {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px 6px 8px;
}
.section-h h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.section-h .more { color: var(--tint); font-size: 14px; font-weight: 500; cursor: pointer; }

/* grouped settings list */
.group {
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}
.group + .group { margin-top: 18px; }
.group-title {
  padding: 16px 6px 7px;
  color: var(--text-3);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.group-footnote { padding: 7px 8px 0; color: var(--text-3); font-size: 12px; line-height: 1.45; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  min-height: 46px;
  border-bottom: 0.5px solid var(--hairline);
}
.row:last-child { border-bottom: none; }
.row .label { flex: 1; font-size: 15px; }
.row .label small { display: block; color: var(--text-3); font-size: 12px; margin-top: 2px; font-weight: 400; }
.row .value { color: var(--text-2); font-family: var(--font-display); font-size: 14px; }
.row.tappable { cursor: pointer; }
.row.tappable:active { background: var(--surface-2); }
.row .chev { color: var(--text-3); }

/* iOS switch */
.switch {
  position: relative;
  width: 51px; height: 31px;
  flex: 0 0 auto;
  border-radius: 16px;
  background: var(--surface-2);
  border: none;
  cursor: pointer;
  transition: background 0.28s var(--ease-ios);
  padding: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.28);
  transition: transform 0.28s var(--ease-ios);
}
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(20px); }

/* inputs */
.field { display: flex; flex-direction: column; gap: 7px; padding: 13px 15px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.input, .select, .textarea {
  width: 100%;
  font-family: var(--font-display);
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 0.5px solid var(--hairline);
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--tint);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tint) 22%, transparent);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }

/* buttons */
.btn {
  appearance: none;
  border: none;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.14s var(--ease-ios), filter 0.2s, opacity 0.2s;
  user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--tint); color: #fff; }
.btn.primary:active { filter: brightness(1.08); }
.btn.tinted { background: color-mix(in srgb, var(--tint) 16%, transparent); color: var(--tint); }
.btn.danger { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.full { width: 100%; }
.btn.sm { padding: 8px 14px; font-size: 13.5px; border-radius: 11px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* detail header */
.detail-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
}
.detail-hero .avatar {
  width: 60px; height: 60px; border-radius: 18px;
  display: grid; place-items: center; color: #fff;
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
  position: relative; overflow: hidden;
}
.detail-hero .avatar::after {
  content:""; position:absolute; inset:0;
  background: linear-gradient(160deg, rgba(255,255,255,0.3), transparent 55%);
}
.detail-hero h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.detail-hero .addr {
  color: var(--text-3); font-size: 12px; font-family: var(--font-display);
  margin-top: 3px; cursor: pointer;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 2px;
}
.metric {
  background: var(--surface);
  border: 0.5px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 13px 14px;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.metric .k { color: var(--text-3); font-size: 12px; font-weight: 600; }
.metric .v { margin-top: 4px; font-family: var(--font-display); font-size: 19px; font-weight: 700; }
.metric .v.up { color: var(--green); }
.metric .v.down { color: var(--red); }

/* big chart */
.chart-card { padding: 14px; }
.chart-card .chart-head {
  display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px;
}
.chart-card .price { font-family: var(--font-display); font-size: 26px; font-weight: 800; }
.big-chart { width: 100%; height: 150px; display: block; }

/* score bars */
.bars { display: flex; flex-direction: column; gap: 11px; padding: 14px; }
.bar-item .bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar-item .bar-top b { font-family: var(--font-display); }
.bar-track { height: 7px; border-radius: 4px; background: var(--ring-track); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.7s var(--ease-ios); }

/* prediction card */
.pred {
  padding: 15px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 14px;
  align-items: center;
}
.pred .dir {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
}
.pred .dir.up { color: var(--green); }
.pred .dir.down { color: var(--red); }
.pred .dir.flat { color: var(--text-2); }
.pred .conf-ring { justify-self: end; }
.pred .pred-meta { grid-column: 1 / -1; display: flex; gap: 18px; flex-wrap: wrap; }
.pred .pred-meta .pm { font-size: 12px; color: var(--text-3); }
.pred .pred-meta .pm b { display: block; font-family: var(--font-display); font-size: 15px; color: var(--text); margin-top: 2px; }

/* csv table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.csv {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-display);
  font-size: 12.5px;
}
table.csv th, table.csv td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 0.5px solid var(--hairline);
  white-space: nowrap;
}
table.csv th { color: var(--text-3); font-weight: 700; position: sticky; top: 0; background: var(--surface-solid); }
table.csv tr:last-child td { border-bottom: none; }

/* skeletons */
.skel {
  border-radius: 8px;
  background: linear-gradient(100deg, var(--skeleton-1) 30%, var(--skeleton-2) 50%, var(--skeleton-1) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skel-coin { display: grid; grid-template-columns: 46px 1fr 60px; gap: 12px; align-items: center; padding: 13px 14px; }
.skel-line { height: 12px; }

/* empty / banner states */
.empty {
  text-align: center;
  padding: 50px 24px;
  color: var(--text-3);
}
.empty .emoji { font-size: 40px; margin-bottom: 8px; }
.empty h3 { color: var(--text-2); margin: 0 0 4px; font-size: 17px; }
.empty p { margin: 0; font-size: 13.5px; line-height: 1.5; }

.banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.5;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner.info { background: color-mix(in srgb, var(--tint) 12%, transparent); color: var(--text-2); }
.banner.warn { background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--text-2); }
.banner svg { flex: 0 0 auto; margin-top: 1px; }
.banner b { color: var(--text); }

/* ---------------- Tab bar ---------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--tabbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-top: 0.5px solid var(--hairline);
}
.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: none;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--tint); }
.tab:active svg { transform: scale(0.86); }
.tab svg { transition: transform 0.15s var(--ease-ios); }

/* ---------------- Toast ---------------- */
.toast-wrap {
  position: fixed;
  left: 0; right: 0;
  top: calc(var(--safe-top) + 8px);
  z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  padding: 0 14px;
}
.toast {
  pointer-events: auto;
  max-width: 460px; width: 100%;
  background: var(--blur-bg);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 0.5px solid var(--hairline-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 15px;
  display: flex; gap: 11px; align-items: center;
  animation: toastIn 0.45s var(--ease-ios);
}
.toast.out { animation: toastOut 0.35s var(--ease-ios) forwards; }
.toast .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.toast .t-body { min-width: 0; }
.toast .t-title { font-size: 14px; font-weight: 700; }
.toast .t-msg { font-size: 12.5px; color: var(--text-2); margin-top: 1px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-22px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-22px) scale(0.96); } }

/* haptic-like tap feedback flash */
.tap-flash { animation: tapflash 0.4s var(--ease-ios); }
@keyframes tapflash { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tint) 40%, transparent); } 100% { box-shadow: 0 0 0 16px transparent; } }

/* desktop scaling */
@media (min-width: 720px) {
  #app { max-width: 760px; margin: 0 auto; }
  .tabbar { max-width: 760px; left: 50%; transform: translateX(-50%); border-radius: 0; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1024px) {
  #app { max-width: 900px; }
  .tabbar { max-width: 900px; }
  .list.feed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
