:root {
  --forest: #1f3a2e;
  --forest-deep: #142a20;
  --forest-soft: #2d5040;
  --linen: #f3eee4;
  --linen-deep: #e7dfcf;
  --amber: #c98a2b;
  --amber-soft: #e8c47e;
  --ink: #1b2a23;
  --muted: #5d6a62;
  --line: rgba(31, 58, 46, 0.12);
  --glass: rgba(255, 252, 245, 0.66);
  --glass-edge: rgba(255, 255, 255, 0.75);
  --plus: #2f7a4f;
  --danger: #a5402c;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 10px 30px -18px rgba(20, 42, 32, 0.45);
  --display: "Iowan Old Style", "New York", ui-serif, "Palatino Linotype", Georgia, serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --tabbar-h: 64px;
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--linen);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--linen);
  color: var(--ink);
  font: 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.no-scroll {
  overflow: hidden;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 40% at 100% 0%, rgba(201, 138, 43, 0.22), transparent 70%),
    radial-gradient(70% 45% at 0% 35%, rgba(31, 58, 46, 0.14), transparent 70%),
    radial-gradient(60% 40% at 90% 95%, rgba(31, 58, 46, 0.12), transparent 70%),
    var(--linen);
}

button,
input {
  font: inherit;
  color: inherit;
}

h1,
h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h1 {
  font-size: 1.75rem;
}

h2 {
  font-size: 1.1rem;
}

p {
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(243, 238, 228, 0.78);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--forest);
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
}

.brand-mark {
  width: 26px;
  height: 26px;
}

.demo-badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--amber);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* ---------- экран ---------- */

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
  outline: none;
}

body.in-app .screen {
  padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}

.view {
  display: grid;
  gap: 16px;
  animation: view-in 0.42s var(--ease) both;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}

.loader {
  display: grid;
  place-items: center;
  min-height: 50vh;
}

.loader span {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--forest);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

/* ---------- кнопки и поля ---------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background-color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  cursor: default;
  opacity: 0.6;
}

.btn.primary {
  width: 100%;
  background: var(--forest);
  color: var(--linen);
  box-shadow: 0 10px 20px -12px rgba(20, 42, 32, 0.8);
}

.btn.primary:hover:not(:disabled) {
  background: var(--forest-soft);
}

.btn.secondary {
  min-height: 48px;
  padding: 0 16px;
  background: rgba(31, 58, 46, 0.08);
  color: var(--forest);
}

.btn.ghost {
  background: transparent;
  color: var(--forest);
  border: 1px solid var(--line);
}

.btn.busy {
  color: transparent;
}

.btn.busy::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid currentColor;
  border-color: var(--linen) var(--linen) transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn.secondary.busy::after,
.btn.ghost.busy::after {
  border-color: var(--forest) var(--forest) transparent;
}

.link {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--forest);
  font-size: 0.92rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(31, 58, 46, 0.35);
  cursor: pointer;
}

.link:disabled {
  color: var(--muted);
  text-decoration: none;
  cursor: default;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--muted);
  font-size: 0.9rem;
}

input[type="tel"],
input[type="text"],
input[type="date"] {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid rgba(31, 58, 46, 0.18);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.85);
  font-size: 1.1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 4px rgba(31, 58, 46, 0.12);
}

input[type="date"] {
  font-size: 1rem;
  -webkit-appearance: none;
  appearance: none;
}

.code-input {
  font-size: 1.6rem !important;
  letter-spacing: 0.45em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 44px;
  padding: 4px 0;
  font-size: 0.95rem;
  cursor: pointer;
}

.check input {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  accent-color: var(--forest);
}

.form-error {
  min-height: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.form-error:empty {
  display: none;
}

/* ---------- вход ---------- */

.login {
  display: grid;
  gap: 20px;
  padding-top: 8px;
}

.login-hero {
  display: grid;
  gap: 10px;
  justify-items: start;
}

.login-hero .card-art {
  width: 96px;
  height: 64px;
  color: var(--forest);
  margin-bottom: 4px;
}

.login-hero.compact {
  padding-top: 12px;
}

.h1-sub {
  display: block;
  color: var(--forest-soft);
  font-weight: 500;
}

.nowrap {
  white-space: nowrap;
}

.lead {
  color: var(--muted);
  font-size: 1.02rem;
  max-width: 34ch;
}

.form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.form-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
}

.demo-note {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(201, 138, 43, 0.16);
  border: 1px dashed rgba(201, 138, 43, 0.7);
  color: #6b4610;
  font-size: 0.95rem;
}

.demo-note b {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
}

/* ---------- карта ---------- */

.greet {
  display: grid;
  gap: 2px;
}

.greet p,
.page-head p {
  color: var(--muted);
}

.page-head {
  display: grid;
  gap: 4px;
}

.bonus-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 18px;
  padding: 20px;
  border-radius: 28px;
  color: var(--linen);
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(201, 138, 43, 0.35), transparent 55%),
    linear-gradient(155deg, #2a4b3c 0%, var(--forest) 45%, var(--forest-deep) 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 24px 40px -22px rgba(20, 42, 32, 0.9);
  isolation: isolate;
}

.bonus-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(232, 196, 126, 0.35);
  pointer-events: none;
}

.bonus-card .card-art {
  position: absolute;
  left: -14px;
  bottom: -10px;
  width: 170px;
  height: 114px;
  color: var(--amber-soft);
  opacity: 0.07;
  z-index: -1;
}

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

.bonus-card-brand {
  font-family: var(--display);
  font-size: 1.05rem;
  color: var(--amber-soft);
}

.bonus-card-level {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(243, 238, 228, 0.12);
  border: 1px solid rgba(243, 238, 228, 0.22);
  font-size: 0.85rem;
  font-weight: 600;
}

.bonus-card-body {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 16px;
}

.balance {
  display: grid;
  min-width: 0;
}

.balance-value {
  font-family: var(--display);
  font-size: clamp(2.2rem, 11vw, 3.2rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: lining-nums;
  white-space: nowrap;
}

.balance-frac {
  font-size: 0.5em;
  letter-spacing: 0;
  color: rgba(243, 238, 228, 0.75);
}

.balance-unit {
  margin-top: 4px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--amber-soft);
}

.balance-note {
  margin-top: 10px;
  font-size: 0.82rem;
  color: rgba(243, 238, 228, 0.7);
}

.qr-tile {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: 128px;
  padding: 8px 8px 7px;
  border: 0;
  border-radius: 18px;
  background: #fff;
  color: var(--forest);
  cursor: pointer;
  box-shadow: 0 10px 22px -12px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.qr-tile:active {
  transform: scale(0.97);
}

.qr-tile span {
  font-size: 0.68rem;
  line-height: 1.2;
  font-weight: 600;
  text-align: center;
}

.qr-small {
  width: 112px;
  height: 112px;
  display: block;
}

.level-card {
  display: grid;
  gap: 12px;
  padding: 18px 18px 16px;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: rgba(31, 58, 46, 0.1);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: var(--p);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--amber), #dfa64a);
  transform-origin: left;
  animation: grow 0.9s 0.15s var(--ease) both;
}

@keyframes grow {
  from {
    transform: scaleX(0);
  }
}

.level-hint {
  color: var(--muted);
  font-size: 0.95rem;
}

.invite-cta {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
}

.invite-cta b {
  display: block;
  color: var(--forest);
}

.invite-cta small {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.invite-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(201, 138, 43, 0.16);
  color: #8a5a14;
}

.invite-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

/* ---------- QR на весь экран ---------- */

.qr-full {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: #fff;
  color: var(--ink);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}

.qr-full.open {
  opacity: 1;
}

.qr-full[hidden] {
  display: none;
}

.qr-full-title {
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--forest);
}

.qr-full-code {
  width: min(86vw, 420px);
  transform: scale(0.94);
  transition: transform 0.35s var(--ease);
}

.qr-full.open .qr-full-code {
  transform: none;
}

.qr-big {
  display: block;
  width: 100%;
  height: auto;
}

.qr-full-id {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.qr-full-hint {
  max-width: 30ch;
  color: var(--muted);
  font-size: 0.95rem;
}

.qr-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(31, 58, 46, 0.08);
  cursor: pointer;
}

.qr-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--forest);
  stroke-width: 2.2;
  stroke-linecap: round;
}

/* ---------- история ---------- */

.list {
  padding: 6px 0;
}

.op {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 16px;
}

.op + .op {
  border-top: 1px solid var(--line);
}

.op-dot {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.1rem;
}

.op.plus .op-dot {
  background: rgba(47, 122, 79, 0.13);
  color: var(--plus);
}

.op.minus .op-dot {
  background: rgba(31, 58, 46, 0.07);
  color: var(--muted);
}

.op-main {
  display: grid;
  min-width: 0;
}

.op-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.op-date {
  color: var(--muted);
  font-size: 0.85rem;
}

.op-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.op.plus .op-amount {
  color: var(--plus);
}

.op.minus .op-amount {
  color: var(--muted);
}

.op.cancelled .op-amount,
.op.cancelled .op-title {
  text-decoration: line-through;
  opacity: 0.6;
}

.skeleton {
  height: 44px;
  margin: 12px 16px;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(31, 58, 46, 0.06), rgba(31, 58, 46, 0.12), rgba(31, 58, 46, 0.06));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
}

.empty b {
  color: var(--ink);
}

.empty svg {
  width: 56px;
  height: 56px;
  fill: none;
  stroke: var(--forest);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
}

/* ---------- уровни ---------- */

.levels {
  margin: 0;
  padding: 6px;
  list-style: none;
}

.level-row {
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 18px;
}

.level-row + .level-row {
  margin-top: 2px;
}

.level-num {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid rgba(31, 58, 46, 0.25);
  color: var(--forest);
  font-weight: 700;
}

.level-row.passed .level-num {
  background: rgba(31, 58, 46, 0.1);
  border-color: transparent;
}

.level-info {
  display: grid;
  min-width: 0;
}

.level-info small {
  color: var(--muted);
  font-size: 0.85rem;
}

.level-pct {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--forest);
  white-space: nowrap;
}

.level-row.current {
  background: var(--forest);
  color: var(--linen);
  padding-top: 24px;
  box-shadow: 0 14px 26px -18px rgba(20, 42, 32, 0.9);
}

.level-row.current .level-num {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}

.level-row.current .level-info small {
  color: rgba(243, 238, 228, 0.72);
}

.level-row.current .level-pct {
  color: var(--amber-soft);
}

.level-you {
  position: absolute;
  top: 6px;
  left: 60px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--amber-soft);
}

.rules {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.rules ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 1.1em;
  color: var(--ink);
}

.rules li::marker {
  color: var(--amber);
}

/* ---------- профиль ---------- */

.block {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.static-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.link-box input {
  font-size: 0.95rem;
  color: var(--forest);
  background: rgba(255, 255, 255, 0.6);
}

.logout {
  justify-self: center;
  min-width: 160px;
  margin-top: 4px;
}

/* ---------- нижняя навигация ---------- */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(calc(100% - 24px), 456px);
  height: var(--tabbar-h);
  padding: 6px;
  border-radius: 22px;
  background: rgba(31, 58, 46, 0.9);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: 0 18px 34px -16px rgba(20, 42, 32, 0.8);
  transform: translateX(-50%);
}

.tabbar[hidden] {
  display: none;
}

.tabbar button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: rgba(243, 238, 228, 0.66);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.25s var(--ease), color 0.25s;
  -webkit-tap-highlight-color: transparent;
}

.tabbar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabbar button[aria-current="page"] {
  background: rgba(243, 238, 228, 0.14);
  color: var(--amber-soft);
}

/* ---------- тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--linen);
  font-size: 0.95rem;
  box-shadow: 0 16px 30px -16px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.toast[data-kind="error"] {
  background: var(--danger);
}

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

@media (min-width: 420px) {
  .qr-tile {
    width: 140px;
  }

  .qr-small {
    width: 124px;
    height: 124px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
