:root {
  --bg: #f3edf5;
  --bg-2: #efe8f3;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --panel-soft: #f7f3f8;
  --ink: #1e1324;
  --muted: #9d95a5;
  --line: rgba(93, 72, 107, 0.1);
  --accent: #f48a68;
  --accent-strong: #ef7f5a;
  --accent-2: #9e73b4;
  --accent-3: #4f285d;
  --button-primary: #7c34a0;
  --button-primary-strong: #682a87;
  --danger: #ae3a2f;
  --shadow: 0 24px 60px rgba(116, 93, 133, 0.14);
  --radius: 34px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 18%, rgba(255, 255, 255, 0.95) 0 2.2rem, transparent 2.25rem),
    radial-gradient(circle at 88% 28%, rgba(255, 255, 255, 0.92) 0 2.35rem, transparent 2.4rem),
    radial-gradient(circle at 82% 76%, rgba(255, 255, 255, 0.7) 0 2.8rem, transparent 2.85rem),
    radial-gradient(circle at 50% 50%, rgba(234, 206, 255, 0.42), transparent 38%),
    linear-gradient(180deg, #f5f0f7 0%, var(--bg) 52%, var(--bg-2) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 22% 72%, rgba(255, 255, 255, 0.55) 0 4rem, transparent 4.1rem),
    radial-gradient(circle at 66% 12%, rgba(255, 255, 255, 0.4) 0 6rem, transparent 6.1rem);
  pointer-events: none;
}

.app-shell {
  position: relative;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 128px;
}

.auth-gate {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: 28px 0 48px;
}

.auth-shell {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 24px;
  align-items: start;
}

.auth-copy {
  padding: 44px 6px;
}

.auth-card {
  display: grid;
  gap: 16px;
  background: rgba(255, 255, 255, 0.9);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.auth-tab {
  font: inherit;
  border: 0;
  border-radius: 999px;
  padding: 12px 14px;
  background: var(--panel-soft);
  color: var(--muted);
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.auth-tab.active {
  background: var(--button-primary);
  color: #fff;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-feedback {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(244, 138, 104, 0.14);
  color: var(--ink);
}

.settings-button {
  position: absolute;
  top: 20px;
  right: 0;
  width: 52px;
  height: 52px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--accent-3);
  font: inherit;
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 16px 30px rgba(116, 93, 133, 0.12);
  backdrop-filter: blur(16px);
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow,
.section-label,
.metric-label,
.footnote {
  color: var(--muted);
}

.eyebrow,
.section-label {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: "Inter", sans-serif;
  font-size: clamp(2.8rem, 7vw, 5.4rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.hero-copy {
  margin-top: 12px;
  max-width: 32rem;
  font-size: 1.04rem;
  color: var(--muted);
}

.card,
.expense-form {
  background: var(--panel);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 28px;
}

.balance-card {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(252, 249, 253, 0.92));
  margin-bottom: 20px;
  padding: 28px 29px;
}

body.settle-view .balance-card {
  display: none;
}

.balance-card h2 {
  font-size: clamp(2.6rem, 4.2vw, 3rem);
  line-height: 1;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  font-weight: 700;
}

.balance-context {
  margin: 0 0 8px;
  font-size: 0.75rem;
  line-height: 1.2;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#balance-subtext {
  font-size: 1rem;
  line-height: 1.22;
  color: var(--ink);
}

.balance-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 16px;
  min-width: min(100%, 340px);
}

.balance-meta div,
.summary-box {
  padding: 16px;
  border-radius: 24px;
  background: var(--panel-soft);
  border: 1px solid rgba(124, 104, 138, 0.08);
}

.balance-meta strong,
.summary-box strong {
  display: block;
  margin-top: 8px;
  font-size: 1.25rem;
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
  align-items: center;
  padding: 8px;
  border-radius: 999px;
  background: rgba(233, 231, 236, 0.92);
  border: 1px solid rgba(123, 115, 135, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tab-button,
.tab-add-button,
.primary-button,
.fab,
.icon-button,
.segmented-control span,
.category-option,
.secondary-button {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: 999px;
  background: transparent;
  color: rgba(30, 19, 36, 0.74);
  transition: 180ms ease;
  font-weight: 500;
}

.tab-icon {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.tab-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.tab-label {
  line-height: 1;
}

.tab-add-button {
  display: none;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--button-primary), var(--button-primary-strong));
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 20px 34px rgba(124, 52, 160, 0.35);
  transition: filter 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.tab-button.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow:
    0 1px 2px rgba(30, 19, 36, 0.06),
    0 10px 18px rgba(150, 145, 160, 0.18);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tab-panels {
  position: relative;
}

.tab-panels.animating {
  overflow: hidden;
}

.tab-panel.is-animating {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
}

.home-grid,
.stats-grid,
.settle-grid {
  display: grid;
  gap: 20px;
}

.home-grid,
.settle-grid {
  grid-template-columns: 1.2fr 1fr;
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.section-heading,
.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.summary-box.accent {
  background: linear-gradient(135deg, rgba(244, 138, 104, 0.18), rgba(255, 255, 255, 0.9));
}

.activity-list {
  display: grid;
  gap: 12px;
}

.activity-item {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.activity-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.activity-icon {
  width: 48px;
  height: 48px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  background: #f5f1f8;
}

.activity-copy {
  flex: 1;
  min-width: 0;
}

.activity-topline {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.activity-title,
.activity-amount {
  font-size: 1rem;
}

.activity-amount {
  white-space: nowrap;
}

.activity-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

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

input,
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(124, 104, 138, 0.12);
  background: rgba(249, 246, 251, 0.96);
  color: var(--ink);
  font: inherit;
}

.chart-wrap {
  display: grid;
  gap: 20px;
  align-items: center;
}

.pie-chart {
  width: min(280px, 70vw);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(#e6ddd4 0 360deg);
  position: relative;
}

.pie-chart::after {
  content: "";
  position: absolute;
  inset: 23%;
  border-radius: 50%;
  background: rgba(255, 250, 245, 0.96);
  box-shadow: inset 0 0 0 1px rgba(30, 29, 27, 0.06);
}

.legend,
.bars,
.archive-list,
.settle-breakdown {
  display: grid;
  gap: 12px;
}

.legend-item,
.bar-row,
.archive-item,
.settle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.legend-item {
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--panel-soft);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  margin-right: 10px;
  flex: 0 0 auto;
}

.legend-label {
  display: flex;
  align-items: center;
}

.bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 80px;
  align-items: center;
}

.bar-track {
  height: 14px;
  border-radius: 999px;
  background: rgba(124, 104, 138, 0.1);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.settle-card {
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.18), transparent 34%),
    linear-gradient(180deg, #4d2859, #482552);
  color: #fff;
}

.settle-card .section-label,
.settle-card .footnote {
  color: rgba(255, 255, 255, 0.62);
}

.settle-card .settle-row {
  border-bottom-color: rgba(255, 255, 255, 0.12);
}

.settle-note {
  margin-top: 14px;
  text-align: center;
  font-size: 0.84rem;
  line-height: 1.4;
}

.settle-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.settle-row:last-child {
  border-bottom: 0;
}

.archive-item {
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--panel-soft);
}

.primary-button,
.secondary-button,
.fab {
  background: var(--button-primary);
  color: #fff;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  padding: 16px 20px;
  border-radius: 18px;
  font-weight: 600;
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary-button {
  width: 100%;
  padding: 16px 20px;
  border-radius: 18px;
  background: var(--panel-soft);
  color: var(--accent-3);
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.fab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-radius: 999px;
  box-shadow: 0 20px 34px rgba(124, 52, 160, 0.24);
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.fab span {
  font-size: 1.35rem;
  line-height: 1;
}

.expense-modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(560px, calc(100% - 24px));
}

.expense-modal::backdrop {
  background: rgba(52, 34, 61, 0.34);
  backdrop-filter: blur(6px);
}

.expense-form {
  display: grid;
  gap: 16px;
  padding: 24px;
}

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

.modal-actions .primary-button,
.modal-actions .secondary-button {
  margin-top: 0;
}

.invite-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 20px;
  background: var(--panel-soft);
}

.invite-actions {
  display: grid;
  gap: 10px;
}

.invite-code {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(158, 115, 180, 0.12);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--accent-3);
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(158, 115, 180, 0.1);
  color: var(--accent-3);
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

label,
fieldset {
  display: grid;
  gap: 10px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
  font-weight: 500;
}

.segmented-control,
.category-grid {
  display: grid;
  gap: 10px;
}

.segmented-control {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented-control label,
.category-option {
  position: relative;
}

.segmented-control input,
.category-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span,
.category-option span {
  display: block;
  padding: 14px;
  border-radius: 18px;
  background: rgba(249, 246, 251, 0.96);
  border: 1px solid transparent;
  text-align: center;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.segmented-control input:checked + span,
.category-option input:checked + span {
  background: rgba(158, 115, 180, 0.14);
  border-color: rgba(158, 115, 180, 0.28);
  color: var(--accent-3);
}

.category-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.category-option span {
  text-align: left;
}

.hidden {
  display: none;
}

.empty-state {
  padding: 18px;
  border-radius: 18px;
  color: var(--muted);
  background: var(--panel-soft);
}

@media (hover: hover) and (pointer: fine) {
  .auth-tab:hover:not(.active) {
    background: #ece6f0;
    color: rgba(30, 19, 36, 0.8);
  }

  .auth-tab.active:hover,
  .primary-button:hover:not(:disabled),
  .fab:hover {
    background: var(--button-primary-strong);
    box-shadow: 0 18px 30px rgba(124, 52, 160, 0.26);
  }

  .settings-button:hover {
    background: rgba(244, 240, 247, 0.98);
    box-shadow: 0 18px 32px rgba(116, 93, 133, 0.16);
    transform: translateY(-1px);
  }

  .tab-button:hover:not(.active) {
    background: #dfdbe4;
    color: rgba(30, 19, 36, 0.88);
  }

  .tab-add-button:hover {
    filter: brightness(0.92);
    box-shadow: 0 22px 38px rgba(124, 52, 160, 0.4);
  }

  .secondary-button:hover {
    background: #ede7f1;
    color: #432154;
    box-shadow: 0 12px 24px rgba(116, 93, 133, 0.12);
  }

  .icon-button:hover {
    background: rgba(124, 52, 160, 0.16);
    color: #432154;
  }

  .segmented-control label:hover span,
  .category-option:hover span {
    background: #f1eaf5;
    border-color: rgba(124, 52, 160, 0.18);
  }
}

@media (max-width: 860px) {
  .auth-shell,
  .hero,
  .balance-card,
  .home-grid,
  .stats-grid,
  .settle-grid,
  .filter-row {
    grid-template-columns: 1fr;
    display: grid;
    align-items: stretch;
  }

  .hero {
    gap: 18px;
  }

  .fab-desktop {
    display: none;
  }

  .balance-meta,
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .auth-gate {
    width: min(100% - 20px, 100%);
    padding-top: 20px;
  }

  .app-shell {
    width: min(100% - 20px, 100%);
    padding-top: 20px;
    padding-bottom: calc(128px + env(safe-area-inset-bottom, 0px));
  }

  .card {
    padding: 18px;
  }

  .auth-tabs,
  .invite-actions {
    grid-template-columns: 1fr;
  }

  .settings-button {
    top: 20px;
    right: 0;
  }

  .eyebrow,
  .hero-copy {
    display: none;
  }

  .hero {
    margin-bottom: 40px;
  }

  h1 {
    font-size: clamp(2.24rem, 5.6vw, 4.32rem);
  }

  .tab-bar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 10;
    margin-bottom: 0;
    background: rgba(233, 231, 236, 0.96);
    backdrop-filter: blur(18px);
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    border-radius: 30px;
    border: 1px solid rgba(123, 115, 135, 0.08);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.8),
      0 20px 40px rgba(150, 145, 160, 0.2);
  }

  .tab-button {
    flex-direction: column;
    gap: 5px;
    font-size: 0.92rem;
    padding: 10px 6px;
    background: transparent;
    color: rgba(30, 19, 36, 0.58);
  }

  .tab-icon {
    width: 22px;
    height: 22px;
  }

  .tab-label {
    font-size: 0.84rem;
    font-weight: 500;
  }

  .tab-button.active {
    background: #ffffff;
    color: var(--ink);
    box-shadow:
      0 1px 2px rgba(30, 19, 36, 0.06),
      0 10px 18px rgba(150, 145, 160, 0.18);
  }

  .tab-add-button {
    display: inline-grid;
    place-items: center;
    transform: translateY(-20px) scale(1.15);
  }

  .balance-meta,
  .summary-grid,
  .filters,
  .category-grid,
  .modal-actions {
    grid-template-columns: 1fr;
  }
}
