:root {
  --primary: #6C63FF;
  --accent: #00D4AA;
  --danger: #FF6B6B;
  --warning: #FFB347;
  --success: #00D4AA;
  --bg: #0F0F1A;
  --surface: #1A1A2E;
  --surface-2: #22223B;
  --text: #FFFFFF;
  --text-muted: #A0A0C0;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 4px 24px rgba(108, 99, 255, 0.15);
  --radius-card: 16px;
  --radius-btn: 12px;
  --radius-chip: 8px;
  --radius-full: 9999px;
  --t: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F8F8FF;
  --surface-2: #EBEEFF;
  --text: #11122A;
  --text-muted: #5F6284;
  --border: rgba(15, 15, 26, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  color: var(--text);
  background: var(--bg);
  font-family: Inter, system-ui, sans-serif;
  transition: all 0.3s ease;
}

.brand-gradient {
  position: fixed; inset: 0 auto auto 0; width: 100%; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  z-index: 60;
}

.top-nav {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between;
  padding: 16px; background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.logo-wrap { display: flex; gap: 10px; align-items: center; }
.owl-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--surface); display: grid; place-items: center; }
.logo-wrap h1 { margin: 0; font-size: 1.05rem; }
.logo-wrap p { margin: 0; color: var(--text-muted); font-size: 0.77rem; }
.top-actions { display: flex; gap: 8px; }

.bento-grid {
  display: grid; grid-template-columns: 1fr; gap: 12px;
}

.bento {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow);
}
.app-shell { width: min(100%, 1100px); margin: 0 auto; padding: 16px 16px 90px; }

.hero-card { background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 68%, var(--primary)), var(--surface-2)); }
.hero-head, .row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.label { color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.72rem; font-weight: 700; }
.safe-value { font-family: "Space Grotesk", "DM Mono", monospace; font-size: clamp(2rem, 8vw, 3.5rem); margin: 6px 0; }
.hero-main { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hero-sub, .hint { color: var(--text-muted); font-size: 0.85rem; margin: 0; }
.ring-wrap { position: relative; width: 96px; height: 96px; flex: 0 0 auto; }
.progress-ring { width: 96px; height: 96px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,0.2); stroke-width: 10; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: var(--t); }
.ring-percent { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 0.8rem; }

.text-input {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 12px; outline: none; transition: var(--t);
}
.text-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2); }
.input-label { color: var(--text-muted); font-size: 0.75rem; font-weight: 600; }

.primary-btn, .danger-btn, .subtle-btn, .chip {
  border: 1px solid transparent; border-radius: var(--radius-btn); padding: 12px 14px;
  font-weight: 600; transition: var(--t); cursor: pointer;
}
.primary-btn { background: var(--primary); color: #fff; }
.subtle-btn, .chip { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.danger-btn { background: var(--danger); color: #fff; }
.primary-btn:active, .subtle-btn:active, .chip:active, .quick-add-btn:active { transform: scale(0.98); }
.chip--active { border-color: var(--accent); color: var(--accent); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }

.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.quick-add-btn {
  min-height: 56px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  padding: 10px; text-align: left;
}
.quick-title { font-size: 0.85rem; font-weight: 700; }
.quick-price, .hint { color: var(--text-muted); font-size: 0.78rem; }
.streak-badge { background: rgba(255, 107, 107, 0.14); color: #ffb6b6; border-radius: var(--radius-full); padding: 6px 10px; font-weight: 700; box-shadow: 0 0 16px rgba(255, 107, 107, 0.2); }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat-mini { background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); padding: 10px; display: grid; gap: 4px; }
.stat-mini span { color: var(--text-muted); font-size: 0.75rem; }
.stat-mini strong { font-family: "Space Grotesk", "DM Mono", monospace; }
.stat-mini i { color: var(--accent); }

.forecast-banner { font-weight: 600; }
.forecast-ok { border-color: rgba(0,212,170,0.4); }
.forecast-warn { border-color: rgba(255,179,71,0.45); }
.forecast-danger { border-color: rgba(255,107,107,0.45); }

.history-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px;
  animation: slideIn .25s ease;
}
.history-list { max-height: 340px; overflow: auto; display: grid; gap: 8px; }
.history-label { font-weight: 700; font-size: 0.9rem; }
.history-meta { color: var(--text-muted); font-size: 0.76rem; }
.history-amount, .money-negative { color: var(--danger); font-weight: 700; }
.money-positive { color: var(--success); }

.modal {
  position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.6); padding: 16px; z-index: 100;
}
.modal.hidden { display: none; }

.modal-card {
  width: min(520px, 100%); max-height: min(92vh, 760px); overflow: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-card); padding: 20px;
}
.tab-panel.hidden { display: none; }

.desktop-nav { display: none; gap: 8px; }
.mobile-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: grid; grid-template-columns: repeat(5,1fr);
  gap: 4px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--border);
}
.tabbar-btn { border: none; background: transparent; color: var(--text-muted); font-size: 0.72rem; display: grid; place-items: center; gap: 4px; padding: 6px; border-bottom: 2px solid transparent; }
.tabbar-btn--active { color: var(--accent); border-bottom-color: var(--accent); }
.tabbar-btn i { font-size: 0.95rem; }
.goals-list, .breakdown-list, .streak-calendar { display: grid; gap: 8px; }

.goal-item,
.breakdown-item {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: grid; gap: 6px;
}
.goal-row, .row { display: flex; gap: 8px; align-items: center; }
.goal-row { justify-content: space-between; }
.goal-title { font-weight: 800; }
.goal-meta { font-size: 0.8rem; color: var(--text-muted); }

.progress {
  height: 9px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,0.12); border: 1px solid var(--border);
}
.progress > div { height: 100%; background: var(--accent); width: 0%; transition: width .35s ease; }
.status-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.status-pill {
  font-size: 0.75rem; font-weight: 700; border-radius: 999px; padding: 4px 9px;
}
.status-pill--ok { background: rgba(0,212,170,.2); color: #8ff0dd; }
.status-pill--warn { background: rgba(255,179,71,.2); color: #ffd6a0; }
.status-pill--danger { background: rgba(255,107,107,.2); color: #ffb3b3; }
.status-pill--neutral { background: rgba(160,160,192,.2); color: #d9daef; }

.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 120; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: .85rem;
}
.toast.hidden { display: none; }

.onboarding-owl { width: 72px; height: 72px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 2rem; margin: 0 auto; animation: float 2s ease-in-out infinite; }
.onboarding-dots { display: flex; gap: 8px; justify-content: center; margin: 10px 0; }
.on-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--surface-2); }
.on-dot--active { background: var(--primary); }
.donut-wrap { display: grid; place-items: center; min-height: 180px; }
.streak-calendar { grid-template-columns: repeat(10, 1fr); }
.streak-dot { width: 100%; aspect-ratio: 1/1; border-radius: 6px; background: #4a4b66; }
.streak-dot.good { background: var(--success); } .streak-dot.bad { background: var(--danger); }
.rank-badge { color: var(--accent); font-weight: 700; }
.segments { height: 16px; border-radius: 999px; overflow: hidden; display: flex; background: var(--surface-2); }
.option-row { display: flex; gap: 8px; align-items: center; color: var(--text-muted); }
.mt8 { margin-top: 8px; }

@keyframes slideIn { from { opacity: 0; transform: translateX(10px);} to {opacity:1; transform:none;} }
@keyframes float { 50% { transform: translateY(-4px);} }

@media (min-width: 640px) { .app-shell { padding-bottom: 24px; } }
@media (min-width: 1024px) {
  .mobile-nav { display: none; }
  .desktop-nav { display: flex; }
  .top-nav { padding-left: 24px; padding-right: 24px; }
  .bento-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-card, .forecast-banner, .tip-card, .tile-history { grid-column: span 2; }
}
