@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Gujarati:wght@400;500;600;700;800&display=swap');

:root {
  --wine: #941b20;
  --wine-dark: #6e1317;
  --wine-light: #b92b30;
  --gold: #c58a35;
  --gold-dark: #9f6920;
  --gold-light: #f3e2ca;
  --cream: #fff9f0;
  --ink: #30221d;
  --muted: #786c64;
  --line: #ebdcc9;
  --card-bg: #fffdf9;
  --success: #2e7d32;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

/* Crucial: ensure hidden elements are strictly hidden regardless of layout */
[hidden],
.screen[hidden],
#formScreen[hidden],
#resultScreen[hidden],
.sheet-backdrop[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at top, #fffdf8 0%, #fff6e9 55%, #f6e7d4 100%);
  font-family: "Noto Sans Gujarati", "Gujarati Sangam MN", "Nirmala UI", "Shruti", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font: inherit;
}

.app-shell {
  width: min(100% - 32px, 860px);
  margin: 0 auto;
  padding: 24px 0 28px;
}

/* Site Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-bottom: 20px;
}
.site-logo {
  display: block;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 18px rgba(122, 75, 36, 0.16);
  border: 2px solid var(--line);
  transition: transform 0.2s ease;
}
.site-logo:hover {
  transform: scale(1.03);
}

/* Stepper Navigation */
.step-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 480px;
  margin: 0 auto 24px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 2px 8px #7a4b240a;
}
.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
}
.step-badge {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ecdccb;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}
.step-item.active {
  color: var(--wine);
}
.step-item.active .step-badge {
  background: var(--wine);
  color: #fff;
}
.step-item.completed {
  color: var(--success);
}
.step-item.completed .step-badge {
  background: var(--success);
  color: #fff;
}
.step-divider {
  width: 32px;
  height: 2px;
  background: var(--line);
  border-radius: 2px;
}

/* Screens */
.screen {
  animation: appear 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.intro {
  text-align: center;
  margin: 0 auto 22px;
  max-width: 540px;
}
.intro h2, .result-heading h2 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--wine-dark);
  font-weight: 800;
}
.intro p, .result-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

/* Screen 1: Layout Grid (Raw Design + Form) */
.form-layout-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 520px;
  margin: 0 auto;
}

/* Raw Template Card */
.template-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 8px 24px #7a4b2410;
  text-align: center;
}

.template-img-wrap {
  width: min(100%, 250px);
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 14px #7a4b2415;
  border: 1px solid var(--line);
}
.template-img-wrap img {
  display: block;
  width: 100%;
  height: auto;
}
.template-caption {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

/* Form Card */
.form-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 10px 30px #7a4b2410;
}
.form-title {
  margin: 0 0 18px;
  font-size: 17px;
  color: var(--wine-dark);
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}
.field-group {
  margin-bottom: 18px;
}
.field-group > label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}
label span {
  color: var(--wine);
}
.field-hint {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}

.form-card input[type="text"],
.form-card input[type="tel"] {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #dfd1c1;
  border-radius: 11px;
  outline: none;
  font-size: 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-card input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px #c58a3520;
}

/* Upload Button & Photo Thumbnail */
.upload-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  border: 1.5px dashed #cca877;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.upload-button:hover,
.upload-button:focus-visible {
  background: #fffaf3;
  border-color: var(--gold);
}
.upload-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: var(--wine);
  background: #fbefe2;
  font-size: 24px;
  font-weight: 700;
  flex-shrink: 0;
}
.photo-thumb-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.photo-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.upload-text {
  flex: 1;
  min-width: 0;
}
.upload-text strong {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-text small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}
.chevron {
  color: var(--muted);
  font-size: 22px;
  flex-shrink: 0;
}
.photo-status {
  min-height: 20px;
  margin-top: 6px;
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
}

/* Buttons */
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 12px 20px;
  color: #fff;
  background: linear-gradient(135deg, var(--wine), #b0262c);
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 6px 18px #941b202c;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.primary-button:hover {
  box-shadow: 0 8px 22px #941b203c;
  transform: translateY(-1px);
}
.primary-button:active {
  transform: translateY(1px);
}
.primary-button:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: 10px 18px;
  color: var(--wine);
  background: #fff;
  border: 1.5px solid #dfbeae;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.secondary-button:hover {
  background: #fdf5ef;
  border-color: var(--wine);
}



.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  padding: 8px 16px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.ghost-button:hover {
  color: var(--ink);
  background: #f5ebe0;
}


.error {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* SCREEN 2: Result Screen */
.result-screen {
  max-width: 440px;
  margin: 0 auto;
}
.result-heading {
  text-align: center;
  margin-bottom: 16px;
}
.success-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 10px;
  border-radius: 50%;
  color: #fff;
  background: var(--success);
  font-size: 24px;
  font-weight: 800;
  box-shadow: 0 4px 12px #2e7d3230;
}
.result-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  box-shadow: 0 10px 32px #7a4b2414;
  margin-bottom: 18px;
}
.preview-wrap {
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px #57391b10;
}
#resultCanvas {
  display: none;
}
.result-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 11px;
}
.preview-tip {
  margin: 10px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}
.download-action {
  font-size: 16px;
  padding: 14px 20px;
}

/* Photo Picker Bottom Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: #20171370;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.picker-sheet {
  width: min(100%, 460px);
  padding: 16px 20px 20px;
  background: #fffdf9;
  border-radius: 22px;
  box-shadow: 0 -8px 40px #00000030;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}
.sheet-handle {
  width: 44px;
  height: 4px;
  margin: 0 auto 16px;
  border-radius: 5px;
  background: #ddd0c4;
}
.picker-sheet h2 {
  margin: 0 0 14px;
  font-size: 17px;
  color: var(--wine-dark);
}
.picker-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 10px;
  text-align: left;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid #eee5dc;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.15s ease;
}
.picker-option:hover {
  background: #fbf5ee;
}
.picker-option > span:first-child {
  font-size: 26px;
}
.picker-option strong {
  display: block;
  font-size: 14px;
}
.picker-option small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}
.cancel-option {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  color: var(--wine);
  background: #f8eee6;
  border: 0;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.cancel-option:hover {
  background: #f2e2d5;
}

/* Desktop layout (>= 860px) */
@media (min-width: 860px) {
  .app-shell {
    width: min(100% - 48px, 900px);
    padding-top: 32px;
  }
  .form-screen:not([hidden]) .form-layout-grid {
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
    max-width: none;
  }
  .template-card {
    position: sticky;
    top: 24px;
  }
  .template-img-wrap {
    width: 100%;
  }
}

/* Mobile responsive adjustments */
@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 24px, 480px);
    padding-top: 18px;
  }
  .form-card {
    padding: 18px;
  }
}

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