:root {
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

/* ---------- Theme tokens ---------- */

html,
html[data-theme="dark"] {
  --bg: #050609;
  --bg-grid: rgba(255, 255, 255, 0.035);
  --card-bg: #0d0f14;
  --card-bg-soft: #12141a;
  --card-border: rgba(255, 255, 255, 0.14);
  --card-border-hover: rgba(255, 255, 255, 0.26);
  --text: #f3f4f6;
  --text-soft: #93989f;
  --text-faint: #52565d;
  --accent: #3b82f6;
  --accent-ink: #ffffff;
  --positive: #60a5fa;
  --negative: #f87171;
  --overlay: rgba(0, 0, 0, 0.7);
  --shadow-card: none;
  --shadow-pop: 0 30px 70px -30px rgba(0, 0, 0, 0.8);
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-grid: rgba(37, 99, 235, 0.035);
  --card-bg: #ffffff;
  --card-bg-soft: #f6f8fb;
  --card-border: rgba(15, 23, 42, 0.08);
  --card-border-hover: rgba(15, 23, 42, 0.16);
  --text: #0b0f19;
  --text-soft: #667085;
  --text-faint: #b0b5c0;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --positive: #2563eb;
  --negative: #dc2626;
  --overlay: rgba(15, 23, 42, 0.5);
  --shadow-card: 0 12px 30px -16px rgba(15, 23, 42, 0.14);
  --shadow-pop: 0 30px 70px -24px rgba(15, 23, 42, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', sans-serif;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease);
}

body {
  position: relative;
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse 100% 60% at 50% 0%, #000 40%, transparent 90%);
}

h1, h2, h3,
.brand-name,
.balance-amount,
.wish-price,
.income-amount,
.lock-title {
  font-family: 'Bricolage Grotesque', sans-serif;
}

button, input, select {
  font-family: inherit;
  font-size: 1rem;
}

a { color: inherit; }

/* ---------- Lock screen ---------- */

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #060606;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 42px 42px;
  padding: 24px;
}

.lock-card {
  width: min(380px, 100%);
  background: #0e0e0e;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg);
  padding: 44px 32px;
  text-align: center;
  box-shadow: var(--shadow-pop);
}

.lock-flourish {
  color: var(--accent);
  font-size: 1.4rem;
  margin-bottom: 8px;
  font-weight: 700;
}

.lock-title {
  color: #f3f3f1;
  font-weight: 700;
  font-size: 2.2rem;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.lock-sub {
  color: #8f8f88;
  font-size: 0.92rem;
  margin: 0 0 28px;
}

#lockForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lock-card input {
  background: #161616;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  color: #f3f3f1;
  outline: none;
  transition: border-color 0.2s;
}

.lock-card input::placeholder { color: #5a5a54; }
.lock-card input:focus { border-color: var(--accent); }

.lock-card button[type="submit"] {
  margin-top: 6px;
  background: var(--accent);
  border: none;
  color: var(--accent-ink);
  font-weight: 700;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.lock-card button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px -10px rgba(59, 130, 246, 0.45);
}

.lock-error {
  min-height: 1.2em;
  color: #ff6b7d;
  font-size: 0.85rem;
  margin: 14px 0 0;
}

/* ---------- App shell ---------- */

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 18px;
  margin-bottom: 20px;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  color: var(--accent-ink);
  background: var(--accent);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.today {
  color: var(--text-faint);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 4px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.icon-btn:hover { border-color: var(--card-border-hover); color: var(--text); }

.theme-toggle .theme-icon-dark { display: none; }
.theme-toggle .theme-icon-light { display: inline; }
html[data-theme="light"] .theme-toggle .theme-icon-dark { display: inline; }
html[data-theme="light"] .theme-toggle .theme-icon-light { display: none; }

/* ---------- Balance ---------- */

.balance-bar {
  text-align: left;
  padding: 6px 0 28px;
}

.balance-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-faint);
  margin: 0 0 8px;
}

.balance-amount {
  font-weight: 700;
  font-size: clamp(2.6rem, 8vw, 4.2rem);
  margin: 0;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- Tab bar ---------- */

.tab-bar {
  display: flex;
  gap: 6px;
  padding-bottom: 24px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--card-border);
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.tab:hover { color: var(--text); background: var(--card-bg-soft); }
.tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.page { display: none; }
.page.active { display: block; animation: page-in 0.3s var(--ease); }

@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-page {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  box-shadow: var(--shadow-card);
  padding: 60px 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.95rem;
}

/* ---------- Panels ---------- */

.panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.panel:hover { border-color: var(--card-border-hover); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-header h2 {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-soft);
  margin: 0;
}

.btn-add {
  background: none;
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.btn-add:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.empty-hint {
  color: var(--text-faint);
  font-size: 0.9rem;
  text-align: center;
  padding: 10px 0 4px;
}

/* ---------- Income list ---------- */

.income-list { display: flex; flex-direction: column; gap: 8px; }

.income-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card-bg-soft);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
}

.income-info { display: flex; flex-direction: column; gap: 2px; }
.income-name { font-weight: 600; }
.income-meta { font-size: 0.8rem; color: var(--text-faint); }

.income-amount {
  color: var(--positive);
  font-weight: 700;
  white-space: nowrap;
}

.income-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--card-border);
  color: var(--text-soft);
  white-space: nowrap;
}

.btn-mini {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.2s;
}
.btn-mini:hover { filter: brightness(1.08); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
}
.btn-icon:hover { color: var(--negative); }

/* ---------- Wishlist grid ---------- */

.wishlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.wish-card {
  background: var(--card-bg-soft);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s var(--ease), border-color 0.2s;
}
.wish-card:hover { transform: translateY(-3px); border-color: var(--card-border-hover); }

.wish-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--card-bg);
  display: block;
}

.wish-image-fallback {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 700;
}

.wish-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.wish-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
}

.wish-link {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-decoration: none;
}
.wish-link:hover { color: var(--text-soft); }

.wish-price {
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
  margin-top: auto;
}

.wish-actions { display: flex; gap: 8px; align-items: center; }

.btn-buy {
  flex: 1;
  background: var(--accent);
  border: none;
  color: var(--accent-ink);
  font-weight: 700;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.2s;
}
.btn-buy:hover { filter: brightness(1.08); }
.btn-buy:disabled {
  background: var(--card-border);
  color: var(--text-faint);
  cursor: not-allowed;
}

.fulfilled-grid .wish-card {
  opacity: 0.6;
}

.fulfilled-badge {
  font-size: 0.72rem;
  color: var(--positive);
  font-weight: 600;
}

/* ---------- Activity ---------- */

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 0.9rem;
}
.activity-item:last-child { border-bottom: none; }

.activity-text { color: var(--text); }
.activity-time { color: var(--text-faint); font-size: 0.78rem; white-space: nowrap; }
.activity-amount.positive { color: var(--positive); font-weight: 700; }
.activity-amount.negative { color: var(--negative); font-weight: 700; }

/* ---------- Modals ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  width: min(420px, 100%);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-pop);
}

.modal h3 {
  font-weight: 700;
  color: var(--text);
  margin: 0 0 18px;
  font-size: 1.15rem;
}

.modal form { display: flex; flex-direction: column; gap: 14px; }

.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-soft);
}

.modal input, .modal select {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  background: var(--card-bg-soft);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }

.wish-preview-status {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin: -6px 0 0;
  min-height: 1.1em;
}

.radio-group { display: flex; gap: 10px; }
.radio-pill {
  flex: 1;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  text-align: center;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  position: relative;
  color: var(--text-soft);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.radio-pill input { position: absolute; opacity: 0; }
.radio-pill:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.btn-secondary {
  background: none;
  border: 1px solid var(--card-border);
  color: var(--text-soft);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-secondary:hover { border-color: var(--card-border-hover); color: var(--text); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.2s;
}
.btn-primary:hover { filter: brightness(1.08); }

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(340px, calc(100vw - 40px));
}

.toast {
  position: relative;
  overflow: hidden;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.35s var(--ease);
  font-size: 0.9rem;
  font-weight: 600;
}

.toast.toast-error {
  border-left-color: var(--negative);
}

.toast-sparkle { display: none; }

@keyframes toast-in {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  to { transform: translateX(40px); opacity: 0; }
}

/* ---------- Responsive ---------- */

@media (max-width: 520px) {
  .app { padding: 18px 14px 70px; }
  .panel { padding: 18px 16px; }
  .wishlist-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .income-row { flex-wrap: wrap; }
  .today { display: none; }
}

[hidden] { display: none !important; }
