:root {
  color-scheme: light dark;
  --page-bg: var(--tg-theme-bg-color, #f3eee5);
  --surface: var(--tg-theme-secondary-bg-color, #fffaf2);
  --text: var(--tg-theme-text-color, #211e1a);
  --muted: var(--tg-theme-hint-color, #746e66);
  --accent: var(--tg-theme-button-color, #b95f3f);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --success: #2f8a61;
  --danger: #b94c4c;
  --border: color-mix(in srgb, var(--text) 12%, transparent);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 40%),
    var(--page-bg);
}

button {
  font: inherit;
}

.shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 21px;
  font-weight: 800;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 30%, transparent);
}

.eyebrow,
.hero__label,
.status-card__label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 2px 0 0;
  font-size: 20px;
  line-height: 1.1;
}

.hero {
  padding: clamp(44px, 12vh, 92px) 0 30px;
}

.hero h2 {
  max-width: 470px;
  margin: 10px 0 14px;
  font-size: clamp(34px, 9vw, 54px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.hero__copy {
  max-width: 470px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.status-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 18px 45px color-mix(in srgb, var(--text) 9%, transparent);
}

.status-card__icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
}

.status-card[data-status="success"] .status-card__icon {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
}

.status-card[data-status="error"] .status-card__icon {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
}

.status-card h2 {
  margin: 5px 0 7px;
  font-size: 19px;
  line-height: 1.25;
}

.status-card__body > p:not(.status-card__label, .user-name) {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.user-name {
  margin: 12px 0 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.retry-button {
  width: 100%;
  margin-top: 14px;
  padding: 14px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 750;
}

.retry-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 38%, transparent);
  outline-offset: 3px;
}

.communities {
  margin-top: 34px;
}

.communities__heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.communities__heading h2 {
  margin: 6px 0 0;
  font-size: 24px;
  letter-spacing: -0.035em;
}

.communities__count {
  display: grid;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  place-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.community-list {
  display: grid;
  gap: 10px;
}

.community-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.community-card--selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}

.community-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
  outline-offset: 2px;
}

.community-card__mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-weight: 850;
}

.community-card__copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.community-card__copy strong,
.community-card__copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-card__copy strong {
  font-size: 15px;
}

.community-card__copy span {
  color: var(--muted);
  font-size: 12px;
}

.community-card__arrow {
  color: var(--muted);
  font-size: 20px;
}

.communities__empty {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.dashboard {
  margin-top: 34px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 18px 45px color-mix(in srgb, var(--text) 7%, transparent);
}

.dashboard__heading,
.summary-section__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.dashboard__heading h2 {
  margin: 6px 0 0;
  font-size: 25px;
  letter-spacing: -0.035em;
}

.dashboard__loader {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
}

.dashboard__error,
.summary-list__empty {
  margin: 16px 0 0;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.dashboard__error {
  color: var(--danger);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.stat-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 16px;
  border-radius: 17px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.stat-card strong {
  color: var(--accent);
  font-size: 27px;
  line-height: 1;
}

.stat-card span {
  color: var(--muted);
  font-size: 12px;
}

.summary-section {
  margin-top: 24px;
}

.summary-section__heading h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.summary-section__heading span {
  display: grid;
  min-width: 27px;
  height: 27px;
  padding: 0 7px;
  place-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-section__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-button,
.back-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.summary-list {
  display: grid;
  gap: 9px;
  margin-top: 11px;
}

.summary-card {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.summary-card h4,
.summary-card p {
  margin: 0;
}

.summary-card h4 {
  font-size: 15px;
  line-height: 1.35;
}

.summary-card__primary {
  padding-top: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
}

.summary-card p:last-child:not(.summary-card__primary) {
  padding-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.summary-card--birthday {
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
  cursor: default;
}

.event-browser,
.profile-browser {
  margin-top: 34px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 18px 45px color-mix(in srgb, var(--text) 7%, transparent);
}

.dashboard__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-button {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.event-browser__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
}

.event-browser__heading h2,
.event-detail__header h2 {
  margin: 6px 0 0;
  font-size: 25px;
  letter-spacing: -0.035em;
}

.event-catalog {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.event-row {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.event-row__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.event-row__status {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
}

.event-row__meta,
.event-detail__muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.event-detail {
  margin-top: 18px;
}

.event-detail__header {
  margin-top: 18px;
}

.event-detail__date {
  margin: 10px 0 4px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 750;
}

.event-detail__muted {
  margin: 0;
}

.event-detail__section {
  margin-top: 24px;
}

.event-detail__section h3 {
  margin: 0 0 11px;
  font-size: 17px;
}

.attendance-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.attendance-button,
.primary-button {
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.attendance-button:disabled {
  border-color: var(--accent);
  color: var(--accent);
  cursor: default;
  opacity: 0.8;
}

.primary-button {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.attendee-list {
  display: grid;
  gap: 7px;
}

.attendee-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--text) 5%, transparent);
  font-size: 13px;
}

.attendee-row__detail {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

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

.bill-total {
  display: grid;
  gap: 4px;
  padding: 13px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.bill-total strong {
  color: var(--accent);
  font-size: 18px;
}

.bill-total span {
  color: var(--muted);
  font-size: 11px;
}

.expense-form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 9px;
  margin-top: 12px;
}

.expense-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.expense-form input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.event-detail__notice {
  margin: 14px 0;
  padding: 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
  font-size: 13px;
}

.event-detail__notice--error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.profile-identity {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-top: 20px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.profile-identity__avatar {
  display: grid;
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(
    145deg,
    var(--accent),
    color-mix(in srgb, var(--accent) 65%, #7c5cff)
  );
  color: var(--accent-text);
  font-size: 25px;
  font-weight: 900;
}

.profile-identity__copy {
  min-width: 0;
}

.profile-identity__copy h2 {
  margin: 0;
  font-size: 21px;
  overflow-wrap: anywhere;
}

.profile-identity__username {
  margin: 3px 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.profile-muted {
  margin: 3px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.profile-section {
  margin-top: 24px;
}

.profile-section > h3,
.profile-section__heading h3 {
  margin: 0 0 11px;
  font-size: 17px;
}

.profile-section__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.profile-count {
  display: grid;
  min-width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

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

.profile-stat {
  display: grid;
  gap: 4px;
  padding: 13px;
  border-radius: 15px;
  background: color-mix(in srgb, var(--text) 5%, transparent);
}

.profile-stat strong {
  color: var(--accent);
  font-size: 19px;
}

.profile-stat span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

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

.favorite-card {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
}

.favorite-card__label,
.favorite-card__count {
  color: var(--muted);
  font-size: 11px;
}

.favorite-card strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.achievement-grid {
  display: grid;
  gap: 9px;
}

.achievement-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.achievement-card__icon {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  font-size: 22px;
}

.achievement-card__copy {
  min-width: 0;
}

.achievement-card__copy p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.achievement-card__date {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 430px) {
  .dashboard__heading {
    align-items: flex-start;
  }

  .profile-button {
    max-width: 105px;
  }

  .favorite-grid {
    grid-template-columns: 1fr;
  }
}

.privacy-note {
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.noscript {
  margin: 20px;
  color: var(--danger);
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}
