/* ============================================================
   Create — the step-by-step postcard wizard. Mobile-first.

   The wizard panel is kraft paper (light in both themes). The
   creation overlay is the "after-hours" dark scrim in both
   themes, so its text uses the --on-dark-* tokens.
   ============================================================ */

.wizard-shell { padding: 2rem 0 4rem; }
@media (min-width: 640px) { .wizard-shell { padding: 3rem 0 6rem; } }

.wizard-intro { max-width: 640px; margin-bottom: 1.75rem; }
.wizard-intro h1 { font-size: var(--step-3); margin: 0.9rem 0 0; }

.wizard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (min-width: 920px) {
  .wizard-grid { grid-template-columns: 240px minmax(0, 1fr); gap: 2.25rem; }
}

/* ---- Step rail — reads as a row of tickets on mobile, a stack on desktop ---- */
.step-rail {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0 0 0.5rem;
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.step-rail-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-md);
  border-left: 2px solid transparent;
  cursor: default;
  flex-shrink: 0;
}
.step-rail-item.is-done { cursor: pointer; }
.step-rail-item.is-done:hover { background: var(--postal-red-tint); }
.step-rail-dot {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  background: transparent;
  border: 1.5px solid var(--text-faint);
  color: var(--text-faint);
}
.step-rail-text { display: flex; flex-direction: column; gap: 0.1rem; padding-top: 0.05rem; }
.step-rail-text strong { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); white-space: nowrap; }
.step-rail-text small { display: none; font-size: 0.76rem; color: var(--text-faint); }

.step-rail-item.is-current .step-rail-dot { background: var(--postal-red); border-color: var(--postal-red); color: var(--on-dark); }
.step-rail-item.is-current .step-rail-text strong { color: var(--text); }
.step-rail-item.is-current { border-left-color: var(--postal-red); }
.step-rail-item.is-done .step-rail-dot { border-color: var(--airmail-blue-bright); color: var(--airmail-blue-bright); }
.step-rail-item.is-done .step-rail-dot::before { content: "\2713"; }

@media (min-width: 920px) {
  .step-rail {
    position: sticky;
    top: 5.5rem;
    flex-direction: column;
    overflow-x: visible;
    gap: 0.15rem;
    border-bottom: 0;
    padding: 0;
    margin: 0;
  }
  .step-rail-text small { display: block; }
  .step-rail-text strong { white-space: normal; }
}

/* ---- Panel + steps — a sheet of kraft on the counter ---- */
.wizard-panel {
  position: relative;
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem 1.25rem 1.5rem;
}
.wizard-panel::before {
  /* faint paper fiber, kept well under the text */
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: var(--radius-lg);
  background-image: var(--grain);
  background-size: 150px 150px;
  opacity: 0.12;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.wizard-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius-lg);
  pointer-events: none;
}
.wizard-panel > * { position: relative; z-index: 1; }
.wizard-panel .btn-primary { --stamp-punch: var(--surface); }
@media (min-width: 640px) { .wizard-panel { padding: 2.25rem 2.25rem 1.75rem; } }

.step-panel { display: none; }
.step-panel.is-active { display: block; animation: step-in 0.28s ease; }
@keyframes step-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Headings default to --text (light-on-dark in dark mode); inside the
   kraft panel that's near-invisible, so force dark ink here. */
.step-panel-title { font-size: 1.5rem; margin-bottom: 0.35rem; color: var(--ink); }
.step-panel-hint { color: var(--ink-soft); font-size: 0.94rem; max-width: 56ch; margin-bottom: 1.5rem; }

.hint { font-size: 0.82rem; color: var(--ink-soft); margin: 0.4rem 0 0; line-height: 1.5; }

input[type="text"], input:not([type]), input[type="file"], textarea, .address-grid input {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border-on-surface);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  width: 100%;
}
textarea { font-family: var(--font-body); font-size: 1rem; resize: vertical; line-height: 1.5; min-height: 9rem; }
input:focus, textarea:focus { border-color: var(--airmail-blue); outline: 2px solid color-mix(in srgb, var(--airmail-blue) 40%, transparent); outline-offset: 1px; }

.address-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}
.address-grid input:nth-child(1),
.address-grid input:nth-child(2),
.address-grid input:nth-child(3) { grid-column: 1 / -1; }
#return-panel { margin-top: 1rem; }

.warning {
  font-size: 0.85rem;
  color: var(--postal-red-dark);
  background: var(--postal-red-tint);
  border: 1px solid color-mix(in srgb, var(--postal-red) 25%, transparent);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-top: 0.75rem;
}

/* ---- Photo dropzone — a parcel label taped to the counter ---- */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--stamp-gray);
  border-radius: var(--radius-md);
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.4);
}
.dropzone::before, .dropzone::after {
  /* strips of tape at two corners */
  content: "";
  position: absolute;
  width: 46px;
  height: 20px;
  background: repeating-linear-gradient(45deg, var(--tape) 0 6px, var(--tape-stripe) 6px 12px);
  pointer-events: none;
}
.dropzone::before { top: -6px; left: 14px; transform: rotate(-24deg); }
.dropzone::after { bottom: -6px; right: 14px; transform: rotate(-24deg); }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--airmail-blue); }
.dropzone-placeholder svg { margin: 0 auto 0.9rem; width: 40px; height: 40px; color: var(--stamp-gray); }
.dropzone-placeholder p { margin: 0.2rem 0; }
.dropzone-thumb { width: 100%; height: 260px; object-fit: cover; display: block; }
@media (min-width: 640px) { .dropzone { min-height: 240px; } .dropzone-thumb { height: 300px; } }

/* ---- Photo framing editor ---- */
.photo-editor { display: grid; gap: 0.85rem; }

.photo-editor-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background:
    repeating-conic-gradient(var(--surface-dim) 0% 25%, var(--paper) 0% 50%) 0 0 / 22px 22px;
  box-shadow: inset 0 0 0 1px var(--border-on-surface), var(--shadow-lift);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.photo-editor-stage:active { cursor: grabbing; }
.photo-editor-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.photo-editor-stage::after {
  /* rule-of-thirds guides, shown while the pointer is on the stage */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(250, 247, 240, 0.5) 0 0),
    linear-gradient(rgba(250, 247, 240, 0.5) 0 0),
    linear-gradient(rgba(250, 247, 240, 0.5) 0 0),
    linear-gradient(rgba(250, 247, 240, 0.5) 0 0);
  background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
  background-position: 33.33% 0, 66.66% 0, 0 33.33%, 0 66.66%;
  background-repeat: no-repeat;
  mix-blend-mode: difference;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.photo-editor-stage:hover::after,
.photo-editor-stage:active::after { opacity: 0.8; }

.photo-editor-controls { display: grid; gap: 0.7rem; }
.pe-slider {
  display: grid;
  grid-template-columns: 5.2rem 1fr 3rem;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-soft);
}
.pe-slider input[type="range"] { width: 100%; accent-color: var(--postal-red); }
.pe-slider span:last-child { text-align: right; }
.pe-actions { display: flex; flex-wrap: wrap; gap: 0.2rem 1.1rem; }
.photo-editor .hint { margin-top: 0; }

/* ---- Font picker — every option is a stamp; the chosen one is franked ---- */
.font-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.font-option {
  position: relative;
  border: 1.5px dashed var(--border-on-surface);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  padding: 0.6rem 0.7rem 0.7rem;
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.font-option:hover { transform: translateY(-2px) rotate(-0.6deg); border-color: var(--airmail-blue); }
.font-option.is-selected {
  border-style: solid;
  border-color: var(--postal-red);
  box-shadow: 0 0 0 1px var(--postal-red) inset;
}
.font-option.is-selected::after {
  /* cancellation ring across the chosen stamp */
  content: "";
  position: absolute;
  top: 0.1rem;
  right: 0.2rem;
  width: 1.9rem;
  height: 1.9rem;
  border: 2px solid var(--postmark-ink);
  border-radius: 50%;
  transform: rotate(-12deg);
  pointer-events: none;
}
.font-preview-holder { display: block; height: 38px; overflow: hidden; }
.font-preview-holder svg { height: 100%; width: auto; max-width: 100%; }
.font-option-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-top: 0.4rem;
}

/* .link-btn defaults to a link blue tuned for the page background; inside
   the kraft panel keep it the mid ink-blue in both themes. */
.wizard-panel .link-btn { color: var(--airmail-blue); }
.wizard-panel .link-btn:hover { color: var(--postal-red-dark); }

.custom-font-panel { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--border-on-surface); }
.custom-font-status { font-family: var(--font-mono); font-size: 0.82rem; color: var(--postal-red-dark); margin-top: 0.5rem; min-height: 1.2em; }
.custom-font-preview { margin-top: 0.6rem; padding: 0.7rem 0.9rem; background: var(--paper); border: 1px solid var(--border-on-surface); border-radius: var(--radius-sm); }
.custom-font-preview svg { height: 42px; width: auto; max-width: 100%; }

/* ---- Note step ---- */
.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.size-slider-label { display: flex; align-items: center; gap: 0.5rem; }
.size-slider-label input[type="range"] { accent-color: var(--postal-red); }

/* ---- Review step ---- */
.review-grid { display: flex; flex-direction: column; gap: 0.85rem; }
.review-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--paper);
  border: 1px solid var(--border-on-surface);
  border-radius: var(--radius-md);
}
.review-row-media {
  flex-shrink: 0;
  width: 58px;
  height: 58px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-dim);
  display: flex;
  align-items: center;
  justify-content: center;
}
.review-row-media img { width: 100%; height: 100%; object-fit: cover; }
.review-row-media svg { width: 90%; }
.review-row-body { flex: 1; min-width: 0; }
.review-row-body h3 { font-size: 0.88rem; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin: 0 0 0.3rem; }
.review-row-body p { margin: 0; font-size: 0.95rem; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.review-row-body p.is-muted { color: var(--ink-soft); font-style: italic; }
.review-edit {
  flex-shrink: 0;
  align-self: flex-start;
  background: none;
  border: 1px solid var(--border-on-surface);
  color: var(--airmail-blue);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.review-edit:hover { background: var(--airmail-blue); color: var(--paper); border-color: var(--airmail-blue); }

/* ---- Wizard controls bar ---- */
.wizard-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-on-surface);
}
.wizard-controls .btn-ghost { color: var(--ink-soft); }
.wizard-controls .btn-ghost:hover { color: var(--ink); }
.wizard-controls #wizard-error { order: 3; flex-basis: 100%; margin: 0; text-align: left; }
.wizard-controls .btn-primary { margin-left: auto; }
@media (min-width: 560px) {
  .wizard-controls #wizard-error { order: 0; flex-basis: auto; flex: 1; text-align: right; }
}

/* ============================================================
   Creation overlay — the "after-hours" reveal. Dark scrim in
   both themes; text uses --on-dark-*.
   ============================================================ */
.creation-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 14, 17, 0.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  overflow-y: auto;
}

.creation-stage {
  width: 100%;
  max-width: 640px;
}

.creation-animate { text-align: center; }

.postcard-3d {
  width: 100%;
  aspect-ratio: 3 / 2;
  perspective: 1800px;
  margin: 0 auto;
}
.postcard-3d-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.5, 0.1, 0.15, 1);
}
.postcard-3d.is-flipped .postcard-3d-inner { transform: rotateY(180deg); }

.postcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 4px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.65);
}
.postcard-face-back { transform: rotateY(180deg); }

.anim-front-img, .anim-back-img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.55s ease, transform 0.55s var(--ease-pop);
}
.anim-front-img.is-in, .anim-back-img.is-in { opacity: 1; transform: scale(1); }

.anim-stamp {
  position: absolute;
  top: 9%;
  right: 6%;
  width: 20%;
  aspect-ratio: 0.85;
  opacity: 0;
  transform: translateY(-46px) rotate(-8deg) scale(0.7);
  transition: opacity 0.4s ease, transform 0.5s var(--ease-pop);
}
.anim-stamp.is-in { opacity: 1; transform: translateY(0) rotate(-4deg) scale(1); }
.anim-stamp svg { width: 100%; height: 100%; }

.anim-postmark {
  position: absolute;
  top: 6%;
  right: 3%;
  width: 26%;
  aspect-ratio: 1;
  border: 2px solid rgba(206, 96, 80, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  color: rgba(206, 96, 80, 0.8);
  line-height: 1.15;
  opacity: 0;
  transform: rotate(-12deg) scale(1.8);
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.3, 1.6, 0.4, 1);
}
.anim-postmark.is-in { opacity: 1; transform: rotate(-12deg) scale(1); }

.anim-msg-wrap { position: absolute; }
.anim-msg-wrap svg { width: 100%; height: 100%; display: block; overflow: visible; }
.anim-msg-wrap path { fill: none; stroke: #1e1b17; stroke-linecap: round; stroke-linejoin: round; }

.creation-status {
  margin: 1.75rem 0 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--on-dark-dim);
  min-height: 1.4em;
}
#creation-skip { color: var(--on-dark-faint); }
#creation-skip:hover { color: var(--on-dark); }

/* ---- Result ---- */
.creation-result { text-align: center; }
.creation-result h2 { font-size: var(--step-2); margin-bottom: 1.25rem; color: var(--on-dark); }
.creation-overlay .warning {
  color: #f1cec7;
  background: rgba(181, 57, 44, 0.22);
  border-color: rgba(224, 120, 105, 0.4);
  text-align: left;
}

.side-toggle {
  display: inline-flex;
  border: 1px solid rgba(242, 236, 224, 0.28);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 1.1rem;
}
.side-tab {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.55rem 1.1rem;
  min-height: 2.4rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--on-dark-dim);
}
.side-tab.is-active { background: var(--on-dark); color: var(--ink); }

.postcard-stage {
  aspect-ratio: 3 / 2;
  border-radius: 4px;
  background: #fff;
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}
.postcard-image { width: 100%; height: 100%; object-fit: cover; display: block; }

#reshuffle-btn { margin-top: 1rem; color: var(--on-dark-dim); }
#reshuffle-btn:hover { color: var(--on-dark); }

.files-section { margin-top: 2rem; text-align: left; }
.files-title {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.74rem;
  color: var(--on-dark-faint);
  margin: 0 0 0.3rem;
}
.files-section .hint { color: var(--on-dark-dim); }
.files-list { list-style: none; margin: 0.8rem 0 0; padding: 0; }
.files-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid rgba(242, 236, 224, 0.14);
  font-size: 0.87rem;
}
.files-list-text strong { font-family: var(--font-mono); color: var(--on-dark); }
.files-list-text span { display: block; color: var(--on-dark-faint); font-size: 0.78rem; margin-top: 0.15rem; }
.files-list a {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #7aa2c6;
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid #7aa2c6;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  min-height: 2.2rem;
  display: inline-flex;
  align-items: center;
}
.files-list a:hover { background: #7aa2c6; color: var(--ink); }

.result-actions { margin-top: 2rem; }

@media (max-width: 560px) {
  .review-row { flex-wrap: wrap; }
  .review-edit { margin-left: auto; }
}

/* ============================================================
   Style step — "learn my handwriting" entry points
   ============================================================ */
.style-more-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  margin-top: 0.4rem;
}
.hand-traced-summary {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0.9rem 0 0.2rem;
  padding: 0.7rem 0.9rem;
  background: var(--paper);
  border: 1.5px dashed var(--postal-red);
  border-radius: var(--radius-sm);
}
.hand-traced-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.hand-traced-info strong { font-size: 0.9rem; color: var(--ink); }
.hand-traced-summary svg { height: 34px; width: auto; max-width: 100%; }
