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

:root {
  --bg: #0f0f0f;
  --card: #1a1a1a;
  --card2: #242424;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --muted: #888;
  --accent: #6366f1;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --nav-h: 64px;
  --nav-margin: 10px;

  /* Liquid Glass */
  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-bg-strong: rgba(30, 30, 34, 0.55);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-highlight: rgba(255, 255, 255, 0.5);
  --glass-blur: 26px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ─── View Transitions (screen navigation) ──────── */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: .22s;
    animation-timing-function: cubic-bezier(.32,.72,0,1);
  }
}

/* ─── List entrance animation ───────────────────── */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: no-preference) {
  .bucket-card, .holding-row, .tx-row {
    animation: rise-in .35s cubic-bezier(.32,.72,0,1) backwards;
    animation-delay: calc(var(--i, 0) * 40ms);
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal-backdrop, .modal-sheet, .toast, .bucket-card, .holding-row, .tx-row, .nav-btn, .nav-btn svg {
    transition: none !important;
    animation: none !important;
  }
}

button, select, .nav-btn, .bucket-card, .holding-row, .fab {
  -webkit-touch-callout: none;
}

/* ─── Ambient glow behind glass surfaces ─────────── */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 12%, rgba(99, 102, 241, .35), transparent 42%),
    radial-gradient(circle at 85% 18%, rgba(16, 185, 129, .28), transparent 40%),
    radial-gradient(circle at 50% 95%, rgba(245, 158, 11, .20), transparent 45%);
  filter: blur(70px);
  transform: translateZ(0);
}

#auth-screen, #app { position: relative; z-index: 1; }

/* ─── Auth ─────────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.auth-card {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: inset 0 1px 0 var(--glass-highlight), 0 12px 40px rgba(0,0,0,.4);
}

.auth-card h1 { font-size: 22px; font-weight: 700; }
.auth-hint { color: var(--muted); font-size: 14px; }

#auth-screen input {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  width: 100%;
  outline: none;
}

#auth-screen input:focus { border-color: var(--accent); }

#token-submit {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  width: 100%;
}

.error { color: var(--red); font-size: 13px; text-align: center; }

/* ─── App shell ─────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.screen-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--nav-margin) * 2 + env(safe-area-inset-bottom, 0px) + 76px);
}

/* ─── Nav (floating Liquid Glass tab bar) ───────── */
.bottom-nav {
  position: fixed;
  left: var(--nav-margin);
  right: var(--nav-margin);
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--nav-margin));
  height: var(--nav-h);
  border-radius: 22px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-highlight), 0 10px 32px rgba(0,0,0,.45);
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  transition: color .15s, transform .15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transition: transform .15s;
}

.nav-btn:active { transform: scale(.92); }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: translateY(-1px); }

/* ─── Page header ───────────────────────────────── */
.page-header {
  padding: max(20px, calc(env(safe-area-inset-top, 0px) + 12px)) 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.total-label { color: var(--muted); font-size: 13px; width: 100%; }

.total-value {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  width: 100%;
}

/* ─── Allocation bar ────────────────────────────── */
.allocation-bar-wrap { padding: 0 16px 16px; }

.allocation-bar {
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  gap: 1px;
  background: var(--border);
  margin-bottom: 10px;
}

.allocation-bar .seg {
  height: 100%;
  transition: width .4s ease;
}

.allocation-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Bucket cards ──────────────────────────────── */
.buckets-list { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }

.bucket-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .15s;
  border-left: 3px solid transparent;
}

.bucket-card:active { background: rgba(255,255,255,.11); transform: scale(.98); }

.bucket-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.bucket-card-name { font-weight: 600; font-size: 16px; }
.bucket-card-platform { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bucket-card-amount { font-size: 20px; font-weight: 700; text-align: right; }
.bucket-card-pct { color: var(--muted); font-size: 12px; text-align: right; margin-top: 2px; }

.bucket-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.bucket-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .4s ease;
}

/* ─── Bucket screen ─────────────────────────────── */
.back-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.back-btn svg { width: 24px; height: 24px; fill: currentColor; display: block; }

.bucket-header-info { flex: 1; }
.bucket-title { font-size: 18px; font-weight: 700; }
.bucket-meta { color: var(--muted); font-size: 12px; }
.bucket-total { font-size: 20px; font-weight: 700; }

.holdings-list { padding: 8px 16px; display: flex; flex-direction: column; gap: 2px; }

.holding-row {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 2px;
  transition: background .15s, transform .15s;
}

.holding-row:active { background: rgba(255,255,255,.11); transform: scale(.98); }

.holding-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.holding-ticker { font-weight: 600; font-size: 15px; font-family: monospace; letter-spacing: 0.5px; }
.holding-value { font-weight: 600; font-size: 15px; }
.holding-note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.holding-pct { color: var(--muted); font-size: 12px; }

/* Inline edit */
.holding-edit {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.holding-edit input {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  padding: 9px 11px;
  width: 100%;
  outline: none;
}

.holding-edit input:focus { border-color: var(--accent); }

.edit-actions { display: flex; gap: 8px; }

.btn-save {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  flex: 1;
}

.btn-cancel-edit {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 8px 16px;
}

.snapshot-btn {
  display: block;
  margin: 16px;
  width: calc(100% - 32px);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  padding: 13px;
  -webkit-tap-highlight-color: transparent;
}

.snapshot-btn:active { background: rgba(255,255,255,.11); }

/* ─── Transactions ───────────────────────────────── */
.bucket-filter {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 12px;
  outline: none;
  margin-left: auto;
}

.tx-list { padding: 0 16px; display: flex; flex-direction: column; gap: 2px; }

.tx-row {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: center;
}

.tx-date { color: var(--muted); font-size: 12px; }
.tx-ticker { font-weight: 600; font-size: 13px; font-family: monospace; }
.tx-bucket-name { color: var(--muted); font-size: 11px; }
.tx-type-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.type-buy { background: rgba(16,185,129,.2); color: #10b981; }
.type-sell { background: rgba(239,68,68,.2); color: #ef4444; }
.type-deposit { background: rgba(99,102,241,.2); color: #6366f1; }
.type-withdrawal { background: rgba(245,158,11,.2); color: #f59e0b; }

.tx-amount { font-weight: 600; font-size: 14px; text-align: right; }
.tx-note { color: var(--muted); font-size: 11px; grid-column: 1 / -1; }

/* ─── FAB ───────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--nav-margin) * 2 + env(safe-area-inset-bottom, 0px) + 14px);
  right: calc(var(--nav-margin) + 6px);
  width: 56px;
  height: 56px;
  background: linear-gradient(160deg, rgba(129,132,255,.95), var(--accent) 60%);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 8px 24px rgba(99,102,241,.45);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s;
}

.fab:active { transform: scale(.92); }
.fab svg { width: 24px; height: 24px; fill: currentColor; }

/* ─── Modal ──────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
  opacity: 0;
  transition: opacity .25s ease;
}

.modal.open .modal-backdrop { opacity: 1; }

.modal-sheet {
  position: relative;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 1px 0 var(--glass-highlight), 0 -8px 40px rgba(0,0,0,.4);
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.32,.72,0,1);
}

.modal.open .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  align-self: center;
  margin-bottom: 4px;
}

.modal-sheet h2 { font-size: 18px; font-weight: 700; }

.modal-sheet label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.modal-sheet input,
.modal-sheet select {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 11px 13px;
  width: 100%;
  outline: none;
}

.modal-sheet input:focus,
.modal-sheet select:focus { border-color: var(--accent); }

.form-actions { display: flex; gap: 10px; margin-top: 4px; }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
}

.btn-secondary {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  font-size: 15px;
  padding: 13px;
}

/* ─── Toast ──────────────────────────────────────── */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 50%;
  transform: translate(-50%, -10px);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 var(--glass-highlight), 0 8px 24px rgba(0,0,0,.4);
  color: var(--text);
  font-size: 13px;
  padding: 10px 18px;
  z-index: 300;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .25s ease, transform .25s cubic-bezier(.32,.72,0,1);
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
