:root {
  color-scheme: light;
  --bg: #f3f0eb;
  --surface: rgba(255, 255, 255, 0.82);
  --ink: #1f211f;
  --muted: #77766f;
  --line: rgba(28, 30, 28, 0.1);
  --accent: #ec5d3f;
  --shadow: 0 20px 60px rgba(39, 34, 28, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  background:
    radial-gradient(circle at 10% -10%, rgba(255,255,255,.9), transparent 38%),
    var(--bg);
  color: var(--ink);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.app-shell {
  width: min(100%, 430px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(104px + env(safe-area-inset-bottom));
}
.topbar, .section-heading, .sheet-header, .form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .18em;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 30px; letter-spacing: -.04em; }
.icon-button {
  position: fixed;
  z-index: 12;
  right: max(18px, calc((100vw - 430px) / 2 + 18px));
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: #202320;
  color: white;
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 12px 30px rgba(31, 33, 31, .28);
  -webkit-tap-highlight-color: transparent;
}
.total-panel {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin: 24px 0 28px;
  padding: 20px;
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 25px;
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(47, 42, 35, .08);
  backdrop-filter: blur(18px);
}
.total-panel p { margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.total-panel strong { font-size: clamp(30px, 9vw, 40px); letter-spacing: -.05em; }
.total-panel span { padding-bottom: 5px; color: var(--muted); font-size: 12px; }
.section-heading { align-items: flex-end; margin-bottom: 14px; }
.section-heading h2 { margin-bottom: 0; font-size: 18px; }
.section-heading p { margin-bottom: 1px; color: var(--muted); font-size: 12px; }
.card-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  transition: padding-bottom .48s cubic-bezier(.22, 1, .36, 1);
}

.wallet-item {
  grid-area: 1 / 1;
  align-self: start;
  min-width: 0;
  transform: translateY(calc(var(--stack-index) * 68px));
  opacity: 1;
  visibility: visible;
  will-change: transform, opacity;
  transition:
    transform .48s cubic-bezier(.22, 1, .36, 1),
    opacity .24s ease,
    visibility 0s linear;
}
.card-list.has-expanded .wallet-item { transform: translateY(22px) scale(.96); }
.card-list.has-expanded .wallet-item.expanded {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}
.card-list.has-expanded .wallet-item:not(.expanded) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    transform .42s cubic-bezier(.4, 0, 1, 1),
    opacity .2s ease,
    visibility 0s linear .42s;
}
.wallet-card-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform .18s ease;
}
.wallet-card-button:active { transform: scale(.985); }
.wallet-card-button:focus-visible { outline: 3px solid rgba(236,93,63,.4); outline-offset: 4px; border-radius: 24px; }
.wallet-details {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transform: translateY(-12px);
  transition:
    grid-template-rows .45s cubic-bezier(.22, 1, .36, 1),
    opacity .28s ease .04s,
    transform .45s cubic-bezier(.22, 1, .36, 1);
}
.expanded .wallet-details {
  grid-template-rows: 1fr;
  opacity: 1;
  transform: translateY(0);
}
.details-inner { min-height: 0; overflow: hidden; }
.full-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  aspect-ratio: 1.586;
  padding: 22px;
  overflow: hidden;
  border-radius: 23px;
  background-position: center;
  background-size: cover;
  color: white;
  box-shadow: 0 15px 34px rgba(23, 26, 25, .22), 0 0 0 1px rgba(0,0,0,.08);
}
.full-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, rgba(255,255,255,.2), transparent 38%, rgba(0,0,0,.15));
  pointer-events: none;
}
.full-card > * { position: relative; z-index: 1; }
.card-face-content { display: flex; flex: 1; flex-direction: column; justify-content: space-between; }
.card-face-content small { font-weight: 600; letter-spacing: .08em; opacity: .8; }
.card-face-content strong { font-size: 25px; }
.card-face-footer { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.uploaded-card .card-face-content { opacity: 0; }
.uploaded-card::after { background: linear-gradient(180deg, rgba(0,0,0,.04), transparent 25%, rgba(0,0,0,.08)); }
.brand-card .card-face-content small { opacity: 0; }
.brand-card .card-face-content { text-shadow: 0 2px 8px rgba(0,0,0,.24); }
.brand-card::after { background: linear-gradient(180deg, transparent 35%, rgba(0,0,0,.16)); }
.card-meta {
  display: grid;
  gap: 13px;
  margin-top: 12px;
  padding: 20px;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 22px;
  background: rgba(255,255,255,.82);
  box-shadow: 0 9px 30px rgba(40,36,31,.08);
}
.balance-row { display: flex; align-items: flex-end; justify-content: space-between; }
.balance-row p, .note { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.balance-row strong { font-size: 28px; }
.edit-button, .text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 650;
}
.empty-state { padding: 8px 0 30px; text-align: center; }
.demo-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  aspect-ratio: 1.586;
  margin-bottom: 26px;
  padding: 24px;
  border-radius: 23px;
  background: linear-gradient(145deg, #f57455, #b92328);
  color: white;
  text-align: left;
  box-shadow: 0 18px 40px rgba(179, 45, 45, .23);
}
.demo-card strong { font-size: 28px; }
.empty-state h3 { margin-bottom: 8px; }
.empty-state p { margin-bottom: 22px; color: var(--muted); font-size: 14px; }

.access-screen {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
  background: #ece8e1;
}
.access-screen.hidden { display: none; }
.access-card {
  width: min(100%, 400px);
  padding: 28px 24px;
  border-radius: 26px;
  background: rgba(255,255,255,.8);
  box-shadow: var(--shadow);
}
.access-card > p:not(.eyebrow, .form-message) { color: var(--muted); font-size: 14px; }
.app-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin-bottom: 24px;
  border-radius: 20px;
  background: linear-gradient(145deg, #f57455, #bd2c2e);
  color: white;
  font-size: 26px;
  font-weight: 750;
}

.sheet {
  width: min(100%, 430px);
  max-height: 94vh;
  max-height: 94dvh;
  margin: auto auto 0;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: #faf9f6;
  color: var(--ink);
}
.sheet::backdrop { background: rgba(18, 18, 17, .38); backdrop-filter: blur(4px); }
.sheet form { padding: 10px 18px max(18px, env(safe-area-inset-bottom)); }
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 16px; border-radius: 5px; background: #d4d1cc; }
.sheet-header {
  position: sticky;
  z-index: 3;
  top: 0;
  padding: 4px 0 12px;
  background: rgba(250,249,246,.96);
  backdrop-filter: blur(12px);
}
.sheet-header h2 { margin-bottom: 0; font-size: 21px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 14px; }
.form-grid label, fieldset { color: #66655f; font-size: 12px; font-weight: 600; }
.form-grid input, .form-grid select, .form-grid textarea, .access-card input {
  display: block;
  width: 100%;
  margin-top: 7px;
  min-height: 50px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: white;
  color: var(--ink);
  font-size: 16px;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus, .access-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(236,93,63,.12); }
.full-width { grid-column: auto; }
.color-fieldset { margin: 0; padding: 0; border: 0; }
.color-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.color-options input { position: absolute; opacity: 0; pointer-events: none; }
.swatch { display: grid; place-items: end start; aspect-ratio: 1.586; padding: 7px; border: 2px solid transparent; border-radius: 10px; color: white; font-size: 10px; }
.color-options input:checked + .swatch { border-color: #1f211f; box-shadow: 0 0 0 2px #faf9f6 inset; }
.coral { background: linear-gradient(145deg, #f57455, #ad2229); }
.navy { background: linear-gradient(145deg, #3a567a, #111a2a); }
.jade { background: linear-gradient(145deg, #42a983, #075a50); }
.violet { background: linear-gradient(145deg, #9b75dd, #4c2b79); }
.upload-field { padding: 15px; border: 1px dashed #c8c3ba; border-radius: 14px; background: white; }
.upload-field span, .upload-field small { display: block; }
.upload-field small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.upload-field input { padding: 8px 0 0; border: 0; }
.form-actions {
  position: sticky;
  z-index: 3;
  bottom: 0;
  gap: 10px;
  margin: 20px -18px calc(-18px - env(safe-area-inset-bottom));
  padding: 12px 18px max(18px, env(safe-area-inset-bottom));
  background: rgba(250,249,246,.96);
  backdrop-filter: blur(12px);
}
.primary-button, .danger-button {
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 15px;
  font-weight: 700;
}
.primary-button { flex: 1; background: #202320; color: white; }
.access-card .primary-button { width: 100%; margin-top: 14px; }
.danger-button { background: #f7e5e2; color: #b5322c; }
.form-message { min-height: 18px; margin: 10px 0 0; color: #b5322c; font-size: 12px; }
.hidden { display: none !important; }

@media (max-width: 370px) {
  .color-fieldset { grid-column: 1 / -1; }
  .wallet-item { transform: translateY(calc(var(--stack-index) * 60px)); }
  .full-card { padding: 18px; border-radius: 20px; }
  .card-face-content strong { font-size: 22px; }
}

@media (min-width: 700px) {
  body { background-color: #e8e4dd; }
  .app-shell { box-shadow: 0 0 70px rgba(38,34,29,.08); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
