:root {
  color-scheme: light;
  --bg: #f5f3ff;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #9ca3af;
  --line: #ede9fe;
  --primary: #6d28d9;
  --up: #059669;
  --down: #e11d48;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, sans-serif;
  font-size: 16px; line-height: 1.35;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: default; }
input { font: inherit; font-size: 18px; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }
.neutral { color: var(--primary); }
.error { color: var(--down); font-weight: 700; font-size: 14px; margin: 8px 0; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; border-radius: 16px; padding: 12px 18px; text-decoration: none; transition: transform .1s; min-height: 48px; }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn-big { width: 100%; font-size: 19px; padding: 16px; border-radius: 20px; }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: 14px; border-radius: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-green { background: #22c55e; color: #fff; box-shadow: 0 6px 16px -6px #22c55e; }
.btn-orange { background: #f97316; color: #fff; box-shadow: 0 6px 16px -6px #f97316; }
.btn-light { background: #f3f4f6; color: var(--ink); width: 100%; justify-content: flex-start; }
.btn-light.danger { color: var(--down); }
.btn-crystal { width: 100%; margin-top: 18px; background: linear-gradient(90deg, #facc15, #f97316); color: #fff; font-size: 16px; letter-spacing: .02em; border-radius: 20px; box-shadow: 0 10px 24px -10px #f97316; }
.chip { min-width: 44px; min-height: 44px; border-radius: 14px; background: rgba(255,255,255,.2); color: #fff; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; }
.chip-light { background: #f3f4f6; color: var(--ink); font-size: 16px; font-weight: 800; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #6366f1, #a855f7 55%, #ec4899); }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 32px; padding: 32px 24px; text-align: center; display: grid; gap: 12px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.4); }
.login-logo { font-size: 64px; }
.login-card h1 { font-size: 34px; font-weight: 900; }
.login-card p { margin: 0 0 8px; }
.login-card input, .stack input { width: 100%; border: 2px solid var(--line); background: #faf5ff; border-radius: 16px; padding: 14px 16px; outline: none; }
.login-card input:focus, .stack input:focus { border-color: #a78bfa; }
.loading { min-height: 100dvh; display: grid; place-items: center; font-size: 64px; animation: spin 2s linear infinite; }

/* ---- hero ---- */
.hero { background: linear-gradient(135deg, #6366f1, #a855f7 55%, #ec4899); color: #fff; border-radius: 0 0 40px 40px; padding: calc(var(--safe-top) + 10px) 18px 26px; box-shadow: 0 20px 40px -24px #7c3aed; }
.hero-inner { max-width: 960px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.brand { font-weight: 900; letter-spacing: .04em; text-transform: uppercase; font-size: 15px; }
.topbar-actions { display: flex; gap: 8px; }
.hero h1 { font-size: 32px; font-weight: 900; }
.tip { display: inline-block; background: rgba(255,255,255,.15); border-radius: 16px; padding: 8px 14px; margin: 10px 0 18px; font-weight: 700; font-size: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25); border-radius: 26px; padding: 14px 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.stat-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.stat-value { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
.pill { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 99px; }
.pill-up { background: rgba(16,185,129,.28); color: #d1fae5; }
.pill-down { background: rgba(244,63,94,.3); color: #ffe4e6; }
.pill-pct { opacity: .75; }
@media (max-width: 420px) {
  .stat-value { font-size: 24px; }
  .hero h1 { font-size: 27px; }
}

/* ---- tabs ---- */
.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 6px; max-width: 520px; margin: -22px auto 0; padding: 6px; background: #fff; border-radius: 22px; box-shadow: 0 10px 30px -12px rgba(76,29,149,.35); width: calc(100% - 32px); }
.tabs button { flex: 1; min-height: 46px; border-radius: 16px; font-weight: 800; font-size: 15px; color: #6b7280; }
.tabs button.active { background: var(--primary); color: #fff; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: #f472b6; color: #fff; font-size: 12px; }

/* ---- content ---- */
.content { max-width: 960px; margin: 0 auto; padding: 18px 16px calc(var(--safe-bottom) + 30px); }
.group { margin-top: 14px; }
.group-head { display: flex; justify-content: space-between; align-items: center; }
.group-head h2 { font-size: 22px; font-weight: 900; }
.tag { background: #ede9fe; color: var(--primary); font-size: 11px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; padding: 4px 10px; border-radius: 99px; }
.group > p { margin: 4px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
@media (max-width: 380px) { .grid { grid-template-columns: 1fr 1fr; gap: 10px; } }

.card { position: relative; background: var(--card); border: 2px solid #f3f4f6; border-radius: var(--radius); padding: 14px 12px 12px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; box-shadow: 0 6px 18px -12px rgba(76,29,149,.4); transition: transform .12s; }
.card:active { transform: scale(.96); }
.card-fav { border-color: #facc15; }
.card-owned { position: absolute; top: 8px; right: 10px; font-size: 16px; }
.card-icon { width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; font-size: 28px; margin-bottom: 6px; }
.card-name { font-weight: 900; font-size: 15px; }
.card-desc { font-size: 11px; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.spark { width: 100%; height: 28px; margin: 6px 0 2px; }
.spark polyline, .chart polyline { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
polyline.up { stroke: var(--up); }
polyline.down { stroke: var(--down); }
.card-price { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
.card-changes { display: flex; gap: 10px; font-size: 12px; font-weight: 800; }
.card-changes small { color: var(--muted); font-size: 10px; text-transform: uppercase; }

/* ---- lists ---- */
.list { display: grid; gap: 10px; margin-top: 6px; }
.row { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 20px; padding: 12px 14px; text-align: left; width: 100%; box-shadow: 0 4px 14px -10px rgba(76,29,149,.4); }
.row:active:not(.row-static) { transform: scale(.98); }
.row-icon { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; font-size: 24px; flex: none; }
.row-icon-soft { background: #f5f3ff; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 900; }
.row-sub { font-size: 12px; color: #6b7280; font-weight: 600; }
.row-right { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.row-value { font-weight: 900; font-size: 17px; }
.row-gain { font-size: 12px; font-weight: 800; }
.gift { display: flex; gap: 6px; }
.empty { text-align: center; padding: 40px 20px; background: #fff; border: 3px dashed var(--line); border-radius: 30px; }
.empty-icon { font-size: 54px; }
.pie-wrap { margin-top: 22px; }
.pie-wrap h3 { font-size: 16px; margin-bottom: 8px; }
.bar { display: flex; height: 34px; border-radius: 14px; overflow: hidden; }
.bar-seg { display: grid; place-items: center; font-size: 16px; min-width: 2px; }
.foot { text-align: center; margin-top: 30px; }

/* ---- sheets (bottom sheet on phone, centered dialog on iPad) ---- */
.backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.55); z-index: 20; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.sheet { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; background: #fff; border-radius: 30px 30px 0 0; padding-bottom: var(--safe-bottom); box-shadow: 0 -20px 40px -20px rgba(0,0,0,.4); overscroll-behavior: contain; }
@media (min-width: 700px) {
  .sheet { left: 50%; bottom: auto; top: 50%; width: 480px; transform: translate(-50%, -50%); border-radius: 30px; max-height: 88dvh; }
}
.sheet-in { animation: up .22s ease-out; }
.sheet-out { animation: up .15s ease-in reverse; }
@keyframes up { from { translate: 0 40px; opacity: 0; } }
.sheet-head { color: #fff; text-align: center; padding: 22px 20px 20px; position: relative; border-radius: inherit; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.sheet-head h2 { font-size: 26px; font-weight: 900; }
.sheet-head p { margin: 4px 0 0; opacity: .9; font-size: 14px; }
.sheet-icon { font-size: 52px; }
.close { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.25); color: #fff; font-size: 16px; }
.sheet-body { padding: 18px 20px 24px; }
.sheet-body h3 { margin: 20px 0 10px; font-size: 17px; }
.price-line { display: flex; align-items: baseline; gap: 8px; }
.price-big { font-size: 32px; font-weight: 900; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 110px; margin-top: 8px; background: linear-gradient(#faf5ff, #fff); border-radius: 14px; }
.chart-legend { display: flex; justify-content: space-between; gap: 6px; margin-top: 4px; }
.owned { background: #f5f3ff; border-radius: 16px; padding: 12px 14px; margin-top: 14px; display: grid; gap: 4px; font-weight: 700; }
.seg { display: flex; background: #f3f4f6; border-radius: 16px; padding: 4px; margin: 16px 0 12px; }
.seg button { flex: 1; min-height: 44px; border-radius: 12px; font-weight: 900; color: #6b7280; }
.seg button.active.buy { background: #22c55e; color: #fff; }
.seg button.active.sell { background: #f97316; color: #fff; }
.amount { display: flex; align-items: center; background: #f3f4f6; border-radius: 18px; padding: 0 18px; }
.amount span { font-size: 28px; font-weight: 900; color: var(--muted); }
.amount input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 34px; font-weight: 900; padding: 12px 8px; outline: none; text-align: center; font-variant-numeric: tabular-nums; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.quick .chip { flex: 1; }
.hint { font-size: 14px; font-weight: 700; color: #6b7280; min-height: 20px; }
.crystal-total { display: flex; justify-content: center; align-items: baseline; gap: 12px; }
.strike { text-decoration: line-through; font-size: 20px; font-weight: 800; }
.pill-wide { text-align: center; font-weight: 900; padding: 10px; border-radius: 16px; }
.pill-wide.pill-up { background: #d1fae5; color: var(--up); }
.pill-wide.pill-down { background: #ffe4e6; color: var(--down); }
.menu { display: grid; gap: 10px; }
.stack { display: grid; gap: 10px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 700; }
.check input { width: 22px; height: 22px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 24px); z-index: 50; background: #111827; color: #fff; padding: 14px 22px; border-radius: 99px; font-weight: 800; border: 3px solid #8b5cf6; box-shadow: 0 10px 30px rgba(0,0,0,.3); white-space: nowrap; }

/* ---- Pip, the voice coach ---- */
.pip-fab { position: fixed; z-index: 15; right: 16px; bottom: calc(var(--safe-bottom) + 16px); display: flex; align-items: center; gap: 8px; padding: 8px 18px 8px 8px; border-radius: 99px; background: linear-gradient(135deg, #f472b6, #a855f7); color: #fff; font-weight: 900; box-shadow: 0 12px 28px -10px #a855f7; }
.pip-fab:active { transform: scale(.95); }
.pip-face { width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.25); display: grid; place-items: center; font-size: 28px; }
.content { padding-bottom: calc(var(--safe-bottom) + 100px); }
.sheet-talk { display: flex; flex-direction: column; height: 92dvh; overflow: hidden; }
@media (min-width: 700px) { .sheet-talk { height: 80dvh; } }
.sheet-talk .sheet-head { padding: 14px 20px 12px; flex: none; }
.sheet-talk .sheet-icon { font-size: 38px; }
.talk-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: 10px; }
.talk-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 10px; -webkit-overflow-scrolling: touch; }
.talk-empty { text-align: center; margin: auto 10px; font-weight: 700; line-height: 1.6; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 20px; font-weight: 600; font-size: 16px; position: relative; }
.bubble.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 6px; }
.bubble.pip { align-self: flex-start; background: #fce7f3; color: #831843; border-bottom-left-radius: 6px; padding-right: 44px; }
.bubble.thinking { padding-right: 14px; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .4; } }
.replay { position: absolute; right: 6px; bottom: 4px; width: 34px; height: 34px; font-size: 16px; }
.mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 4px; flex: none; }
.mic { width: 92px; height: 92px; border-radius: 50%; font-size: 40px; background: linear-gradient(135deg, #f472b6, #a855f7); color: #fff; box-shadow: 0 12px 30px -10px #a855f7; transition: box-shadow .08s, transform .1s; }
.mic:active { transform: scale(.94); }
.mic.rec { background: #f43f5e; }
.mic.think { background: #c4b5fd; animation: pulse .8s infinite alternate; }
.mic.speak { background: #22c55e; }
.mic-label { font-weight: 800; color: #6b7280; font-size: 14px; }
.talk-type { display: flex; gap: 8px; margin-top: 8px; flex: none; }
.talk-type input { flex: 1; min-width: 0; border: 2px solid var(--line); background: #faf5ff; border-radius: 16px; padding: 10px 14px; font-size: 16px; outline: none; }
.link-btn { color: var(--muted); font-weight: 700; font-size: 13px; margin-top: 6px; text-decoration: underline; align-self: center; flex: none; }
