/* ============================================
   Keepsake — Design System
   Product register · Restrained color strategy
   Mood: quiet evening with a polaroid — tender, warm, precious
   ============================================ */

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- Design Tokens --- */
:root {
  /* Surfaces - playful, bright, and soft */
  --bg:              oklch(0.980 0.012 210);
  --surface:         oklch(1.000 0.000 0);
  --surface-elevated: oklch(0.965 0.025 85);

  /* Ink - warm charcoal, not pure black */
  --ink:             oklch(0.200 0.010 30);
  --ink-muted:       oklch(0.500 0.010 40);
  --ink-dim:         oklch(0.680 0.008 55);
  --ink-on-primary:  oklch(1.000 0.000 0);

  /* Primary - berry sticker red */
  --primary:         oklch(0.540 0.145 22);
  --primary-hover:   oklch(0.480 0.150 22);
  --primary-subtle:  oklch(0.935 0.045 22);

  /* Accent set */
  --accent:          oklch(0.820 0.125 82);
  --accent-subtle:   oklch(0.955 0.045 82);
  --sky:             oklch(0.910 0.055 230);
  --mint:            oklch(0.925 0.055 155);
  --peach:           oklch(0.925 0.070 52);
  --lilac:           oklch(0.925 0.055 310);

  /* Semantic */
  --danger:          oklch(0.530 0.170 22);
  --danger-subtle:   oklch(0.940 0.030 22);
  --success:         oklch(0.530 0.140 160);
  --divider:         oklch(0.830 0.018 65);

  /* Typography — one family, system stack */
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  --font-display: 'Times New Roman', 'Georgia', serif;

  /* Scale — fixed rem, tighter ratio (1.125–1.2) */
  --text-xs:     0.750rem;   /* 12px */
  --text-sm:     0.8125rem;  /* 13px */
  --text-base:   1rem;       /* 16px */
  --text-md:     1.125rem;   /* 18px */
  --text-lg:     1.3125rem;  /* 21px */
  --text-xl:     1.5rem;     /* 24px */
  --text-2xl:    1.75rem;    /* 28px */
  --text-3xl:    2rem;       /* 32px */

  --leading-tight:  1.15;
  --leading-base:   1.5;
  --leading-relaxed: 1.65;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  --tracking-tight: 0;
  --tracking-normal: 0;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radii — product: 12px cards, pill for tags/buttons */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Motion — product: 150-250ms, state-change only */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;

  /* Shadows - sticker-like, no fuzzy glass */
  --shadow-sm: 0 2px 0 oklch(0.200 0.010 30 / 0.12);
  --shadow-md: 0 5px 0 oklch(0.200 0.010 30 / 0.14);
  --shadow-lg: 0 8px 0 oklch(0.200 0.010 30 / 0.15);

  /* Z-index scale */
  --z-base: 0;
  --z-sticky: 100;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* --- Base --- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  line-height: var(--leading-base);
  font-size: var(--text-base);
  letter-spacing: var(--tracking-normal);
}

/* --- App Container --- */
.app-container {
  max-width: 448px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    linear-gradient(180deg, var(--bg) 0%, oklch(0.992 0.012 75) 100%);
  overflow: hidden;
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  padding: var(--space-4);
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: oklch(1.000 0.000 0 / 0.92);
  border-bottom: 2px solid var(--divider);
}
.app-header.is-hidden { display: none; }

.back-btn {
  background: var(--surface);
  border: 2px solid var(--ink);
  color: var(--ink);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: background var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}
.back-btn:active {
  background: var(--accent-subtle);
  box-shadow: 0 1px 0 oklch(0.200 0.010 30 / 0.12);
  transform: translateY(1px);
}
.back-btn.hidden { visibility: hidden; opacity: 0; }

.header-progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.progress-bar {
  height: 10px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.4s var(--ease-out);
  width: 20%;
}
.progress-label {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
}
.header-spacer { width: 44px; flex-shrink: 0; }

/* --- Steps --- */
.step {
  display: none;
  flex: 1;
  flex-direction: column;
  animation: stepIn 280ms var(--ease-out);
}
.step.active { display: flex; }

@keyframes stepIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.step-content {
  flex: 1;
  padding: var(--space-6) var(--space-5) var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* --- Home --- */
.home-screen {
  display: none;
  flex: 1;
  animation: stepIn 280ms var(--ease-out);
}
.home-screen.active { display: flex; }

.home-content {
  flex: 1;
  padding: var(--space-6) var(--space-5) var(--space-10);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-4);
}

.home-mark { margin-top: 0 !important; }

.home-showcase {
  width: 100%;
  height: 244px;
  position: relative;
  margin: 0 auto var(--space-2);
}

.mini-phone {
  width: 150px;
  height: 230px;
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%) rotate(4deg);
  background: oklch(0.145 0.010 260);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 8px 8px 0 var(--sky);
  padding: 22px 12px 14px;
}

.mini-phone-bar {
  width: 54px;
  height: 12px;
  border-radius: var(--radius-full);
  background: oklch(0.040 0.000 0);
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
}

.mini-wallet-card,
.mini-pass {
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 6px 6px 0 oklch(0.200 0.010 30 / 0.14);
  overflow: hidden;
}

.mini-wallet-card {
  height: 176px;
  background: var(--peach);
  padding: 10px;
  color: var(--ink);
}

.mini-photo,
.mini-pass-photo {
  display: block;
  border: 2px solid oklch(1.000 0.000 0 / 0.8);
  border-radius: 12px;
  background:
    linear-gradient(145deg, oklch(0.795 0.105 58), oklch(0.650 0.075 28));
}

.mini-photo {
  height: 102px;
  margin-bottom: 10px;
}

.mini-wallet-card b,
.mini-pass b {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  line-height: 1;
  letter-spacing: 0;
}

.mini-wallet-card small,
.mini-pass small {
  display: block;
  margin-top: 5px;
  font-size: 0.68rem;
  color: var(--ink-muted);
  font-weight: var(--weight-semibold);
}

.mini-pass {
  width: 102px;
  height: 142px;
  position: absolute;
  background: var(--surface);
  padding: 8px;
}

.mini-pass-left {
  left: 14px;
  top: 44px;
  transform: rotate(-9deg);
  background: var(--mint);
}

.mini-pass-right {
  right: 12px;
  top: 80px;
  transform: rotate(10deg);
  background: var(--lilac);
}

.mini-pass-photo {
  height: 78px;
  margin-bottom: 8px;
}

.home-title {
  font-family: var(--font);
  font-size: var(--text-3xl);
  line-height: 1.08;
  font-weight: var(--weight-bold);
  letter-spacing: 0;
  color: var(--ink);
  text-align: center;
  text-wrap: balance;
}

.home-desc {
  font-size: var(--text-base);
  color: var(--ink-muted);
  line-height: var(--leading-base);
  text-align: center;
  text-wrap: pretty;
}

.home-notes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  padding-top: var(--space-1);
}

.home-notes span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 2px solid var(--ink);
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-sm);
  line-height: 1;
  color: var(--ink);
  font-weight: var(--weight-semibold);
}

/* --- Step 1: Upload --- */
.hero-icon {
  width: 82px;
  height: 82px;
  margin: var(--space-4) auto 0;
  background: var(--accent-subtle);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--sky);
  transform: rotate(-3deg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}
.upload-mark { background: var(--primary-subtle); }

.step-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  text-align: center;
  line-height: var(--leading-tight);
  letter-spacing: 0;
  text-wrap: balance;
}

.step-desc {
  font-size: var(--text-base);
  color: var(--ink-muted);
  text-align: center;
  line-height: var(--leading-base);
  text-wrap: balance;
}

.upload-zone {
  margin-top: var(--space-1);
  border: 3px dashed var(--ink);
  border-radius: 18px;
  padding: var(--space-10) var(--space-5);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--duration-base) var(--ease-out),
              background var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  background: var(--surface);
  box-shadow: 8px 8px 0 var(--mint);
}
.upload-zone:active,
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--accent-subtle);
  box-shadow: 4px 4px 0 var(--mint);
  transform: translate(2px, 2px);
}
.upload-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-4);
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--sky);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration-base) var(--ease-out);
}
.upload-zone:active .upload-icon { background: var(--primary-subtle); }
.upload-text {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--ink);
}
.upload-hint {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin-top: var(--space-2);
  font-weight: var(--weight-medium);
}

.upload-mini-card {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 2px solid var(--ink);
  border-radius: var(--radius-full);
  background: var(--peach);
  box-shadow: var(--shadow-sm);
  padding: var(--space-2) var(--space-3);
  transform: rotate(1deg);
}

.upload-mini-card span {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--surface);
}

.upload-mini-card b {
  font-size: var(--text-sm);
  letter-spacing: 0;
}

/* --- Step 2: Crop --- */
.crop-step { padding-top: var(--space-4) !important; }
.crop-container {
  flex: 1;
  min-height: 300px;
  max-height: 55vh;
  background: #000;
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 8px 8px 0 var(--lilac);
  overflow: hidden;
  position: relative;
  -webkit-user-select: none;
  user-select: none;
}

.guide-pill {
  align-self: center;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-4);
  border: 2px solid var(--ink);
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.step-actions {
  display: flex;
  gap: var(--space-3);
  padding-top: var(--space-2);
}
.step-actions .btn { flex: 1; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 15px 24px;
  border-radius: var(--radius-full);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  border: 3px solid var(--ink);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  font-family: var(--font);
  min-height: 54px;
  letter-spacing: var(--tracking-normal);
  -webkit-user-select: none;
  user-select: none;
  box-shadow: var(--shadow-md);
}
.btn:active {
  box-shadow: 0 2px 0 oklch(0.200 0.010 30 / 0.14);
  transform: translateY(3px);
}
.btn:focus-visible,
.color-swatch:focus-visible {
  outline: 3px solid var(--primary-subtle);
  outline-offset: 3px;
}

.btn-primary {
  background: var(--primary);
  color: var(--ink-on-primary);
}
.btn-primary:disabled {
  background: oklch(0.800 0.030 20);
  color: oklch(1.000 0.000 0 / 0.6);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
}
.btn-secondary:active { background: var(--surface-elevated); }

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  min-height: 48px;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  border-width: 2px;
  box-shadow: var(--shadow-sm);
}

.btn-full { width: 100%; }

/* Wallet button — black pill, Apple-style */
.btn-wallet {
  background: oklch(0.120 0.000 0);
  color: oklch(1.000 0.000 0);
  border-radius: 16px;
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  padding: 16px 28px;
  letter-spacing: var(--tracking-normal);
  box-shadow: 0 7px 0 oklch(0.200 0.010 30 / 0.20);
}
.btn-wallet:active {
  background: oklch(0.200 0.000 0);
  transform: translateY(3px);
  box-shadow: 0 3px 0 oklch(0.200 0.010 30 / 0.20);
}
.btn-wallet svg { width: 22px; height: 22px; }

/* --- Form Fields --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
}
.form-group label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink-muted);
  letter-spacing: 0;
}

.required { color: var(--danger); }
.optional {
  color: var(--ink-dim);
  font-weight: var(--weight-normal);
}

.form-group input,
.form-group textarea,
.form-group select {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: var(--text-base);
  color: var(--ink);
  font-family: var(--font);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  outline: none;
  letter-spacing: var(--tracking-normal);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--ink-dim);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
  line-height: var(--leading-relaxed);
}

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23808080' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.char-count {
  font-size: var(--text-xs);
  color: var(--ink-dim);
  text-align: right;
}

/* --- Pass Preview --- */
.pass-preview {
  display: flex;
  justify-content: center;
  margin: var(--space-1) 0 var(--space-2);
  perspective: 900px;
}

.pass-card {
  --pass-bg: rgb(255, 255, 255);
  width: 100%;
  max-width: 312px;
  border: 3px solid var(--ink);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transition: background var(--duration-slow) var(--ease-out),
              color var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
  background: var(--pass-bg);
  transform: rotate(-1.5deg);
}

.pass-logo-row {
  min-height: 58px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--pass-bg);
}

.pass-logo-row img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.pass-strip {
  width: 100%;
  aspect-ratio: 375 / 144;
  overflow: hidden;
  background: var(--sky);
  border-top: 3px solid var(--ink);
}
.pass-photo-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
}

/* --- Color Picker --- */
.color-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 8px 8px 0 var(--accent-subtle);
  padding: var(--space-4);
}

.color-picker h3 {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  letter-spacing: 0;
  text-align: center;
}

.color-picker p {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  text-align: center;
  margin-top: 2px;
}

.color-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.color-swatch {
  min-height: 54px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: border-color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
  box-shadow: var(--shadow-sm);
}
.color-swatch:active {
  box-shadow: 0 1px 0 oklch(0.200 0.010 30 / 0.12);
  transform: translateY(2px);
}
.color-swatch.selected {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--ink);
  box-shadow: 0 0 0 3px oklch(0.540 0.145 22 / 0.20),
              var(--shadow-sm);
}
.color-swatch span {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px oklch(1.000 0.000 0 / 0.62);
  flex-shrink: 0;
}
.color-swatch b {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: 0;
}

/* --- Error Messages --- */
.error-msg {
  font-size: var(--text-sm);
  color: var(--danger);
  text-align: center;
  min-height: 20px;
  transition: opacity var(--duration-fast) var(--ease-out);
}
.error-msg:empty { opacity: 0; }

/* --- Loading Overlay --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: oklch(1.000 0.000 0 / 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease-out);
}
.loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.loading-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 2.5px solid var(--divider);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-card p {
  font-size: var(--text-md);
  color: var(--ink);
  font-weight: var(--weight-medium);
}
.loading-sub {
  font-size: var(--text-sm) !important;
  color: var(--ink-dim) !important;
  font-weight: var(--weight-normal) !important;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .step.active { animation: none; }
}

/* --- Tablet+ --- */
@media (min-width: 520px) {
  .app-container { padding: var(--space-6) 0; }
  .app-header { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .step-content { padding: var(--space-10) var(--space-8) var(--space-16); }
  .crop-container { max-height: 380px; }
}

/* iOS safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .step-content {
    padding-bottom: calc(var(--space-12) + env(safe-area-inset-bottom));
  }
}
