:root {
  --ink: #1e1e1e;
  --paper: #fffdf8;
  --shadow: 0 10px 30px rgba(0, 0, 0, .15);
  --muted: #6b7280;
  --cta: #00a99c;

  /* This is set dynamically in the page as:
     :root { --viewer-bg: <?php echo htmlspecialchars($viewerBg, ENT_QUOTES); ?>; } */
  --viewer-bg: #004766;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #fff;
}

.hidden {
  display: none !important;
}

/* ========================================================================== */
/*                                 BUILDER                                    */
/* ========================================================================== */

.mode-builder .app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
}

.mode-builder .panel {
  background: #fff;
  padding: 16px;
}

.mode-builder .builder-panel {
  flex: 0 0 380px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mode-builder .preview-panel {
  flex: 1 1 0;
  min-width: 260px;
  position: relative;
}

.mode-builder .stepper {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
}

.mode-builder .chip {
  display: inline-flex;
  align-items: flex-start;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, .12);
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
  max-width: 180px;
}

.mode-builder .chip-num {
  flex: 0 0 auto;
  margin-top: 1px;
  font-weight: 600;
}

.mode-builder .chip-text {
  flex: 0 1 auto;
  white-space: normal;
}

.mode-builder .chip.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* Step 1 layout: scrollable gallery with bottom-fixed buttons + gradient */
.mode-builder #step1 {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mode-builder .step1-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.mode-builder .hint {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.mode-builder .gallery {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 4px;
  padding-bottom: 110px; /* room under scroll for buttons */
  overflow-y: auto;
}

.mode-builder .card-thumb {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: #0002;
}

.mode-builder .card-thumb img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
}

.mode-builder .card-thumb .name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.mode-builder .card-thumb.selected {
  border-color: var(--cta);
}

.mode-builder .step1-bottom {
  position: sticky;
  bottom: 10px;
  padding-top: 0;
  margin-top: auto;
}

.mode-builder .step1-gradient {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 49px;
  height: 75px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, #ffffff 80%);
}

.mode-builder .step1-bottom-inner {
  position: relative;
  z-index: 2;
  padding-top: 8px;
  background: #fff;
}

.mode-builder .status-line {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  margin-bottom: 4px;
}

.mode-builder label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
}

.mode-builder input[type="text"],
.mode-builder input[type="email"],
.mode-builder textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}

.mode-builder textarea {
  min-height: 110px;
}

.mode-builder .row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.mode-builder .btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.mode-builder button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-family: inherit;
  font-size: 14px;
}

.mode-builder .btn {
  background: #111;
  color: #fff;
}

.mode-builder .btn.secondary {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .12);
  color: #111;
  box-shadow: none;
}

.mode-builder .btn.cta {
  background: var(--cta);
  color: #fff;
}

.mode-builder .canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.mode-builder canvas,
.mode-builder #frontPreview {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  border-radius: 24px;
  box-shadow: var(--shadow);
  background: var(--paper);
}

.mode-builder #frontPreview {
  object-fit: cover;
}

.mode-builder #frontMini {
  position: absolute;
  top: -32px;
  right: 16px;
  width: 150px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 3px solid #fff;
  background: #000;
}

.mode-builder .placeholder-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 32px;
  color: var(--muted);
  font-size: 15px;
  background: var(--paper);
  border-radius: 24px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  min-height: 260px;
}

.mode-builder .placeholder-card h1 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #111827;
}

.mode-builder .placeholder-card p {
  margin: 0;
  max-width: 360px;
}

.mode-builder .front-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}

.mode-builder .mt-container {
  margin-top: 12px;
}

.mode-builder .message-type-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0 4px;
}

.mode-builder .mt-pill {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid rgba(0, 0, 0, .14);
  background: #fff;
  cursor: pointer;
}

.mode-builder .mt-pill.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.mode-builder .question-area {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f9fafb;
  border: 1px solid rgba(0, 0, 0, .05);
}

.mode-builder .question-label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.mode-builder #qInput,
.mode-builder #qTextarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, .12);
  font-family: inherit;
  font-size: 14px;
}

.mode-builder #qTextarea {
  min-height: 100px;
  resize: vertical;
}

.mode-builder #anonRow {
  font-size: 12px;
  margin: 0;
}

/* Typography hierarchy inside the card */
.mode-builder .note-legend {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* Mobile-specific layout: stack preview above builder, add preview hint & zoom */
.mode-builder .mobile-preview-hint {
  display: none;
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity .25s ease, transform .25s ease;
  z-index: 5;
}

.mode-builder .mobile-preview-hint.visible {
  opacity: 1;
  transform: translateY(0);
}

.mode-builder .preview-zoom-icon {
  display: none;
  position: absolute;
  right: 12px;
  top: 12px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 6;
}

.mode-builder .preview-fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

.mode-builder .preview-fullscreen-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.mode-builder .preview-fullscreen-inner {
  width: 100%;
  max-width: 900px;
  padding: 16px;
}

.mode-builder .preview-fullscreen-inner canvas,
.mode-builder .preview-fullscreen-inner img {
  width: 100%;
  height: auto;
  border-radius: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  background: var(--paper);
}

.mode-builder #sendEmail {
  margin-top: 9px !important;
}

@media (max-width: 768px) {
  .mode-builder .app {
    flex-direction: column;
  }

  .mode-builder .preview-panel {
    order: -1;
  }

  .mode-builder .builder-panel {
    flex: 1 1 auto;
  }

  .mode-builder .gallery {
    grid-template-columns: 1fr;
  }

  .mode-builder .preview-zoom-icon {
    display: flex;
  }

  .mode-builder .mobile-preview-hint {
    display: block;
  }
}

/* ========================================================================== */
/*                         VIEWER / INVALID MODES                             */
/* ========================================================================== */

.mode-view .wrapper,
.mode-invalid .wrapper {
  max-width: 1000px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  justify-content: center;
}

.mode-view h1,
.mode-invalid h1 {
  margin: 0;
  font-size: 24px;
  text-align: center;
}

.mode-view .subtitle,
.mode-invalid .subtitle {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.mode-view .viewer-stack,
.mode-invalid .viewer-stack {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 16px auto 0;
  min-height: 520px;
}

.mode-view .view-intro,
.mode-view .card-stage,
.mode-invalid .view-intro,
.mode-invalid .card-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.mode-view .view-intro,
.mode-invalid .view-intro {
  background: var(--viewer-bg);
  border-radius: 24px;
  padding: 24px 20px 28px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
  gap: 16px;
  transition: opacity .4s ease;
}

.mode-view .view-intro.fade-out,
.mode-invalid .view-intro.fade-out {
  opacity: 0;
  pointer-events: none;
}

.mode-view .intro-cover,
.mode-invalid .intro-cover {
  width: 100%;
  max-width: 480px;
  border-radius: 18px;
  overflow: hidden;
  background: var(--viewer-bg);
  box-shadow: 0 12px 26px rgba(0, 0, 0, .3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-view .intro-cover img,
.mode-invalid .intro-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.mode-view .card-stage,
.mode-invalid .card-stage {
  opacity: 0;
  transform: translateY(0);
  pointer-events: none;
  transition: opacity .4s ease;
}

.mode-view .card-stage.visible,
.mode-invalid .card-stage.visible {
  opacity: 1;
  pointer-events: auto;
}

.mode-view .card-3d-wrapper,
.mode-invalid .card-3d-wrapper {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.mode-view .card-3d,
.mode-invalid .card-3d {
  position: relative;
  width: 100%;
  perspective: 1200px;
  z-index: 2;
}

.mode-view .card-3d canvas,
.mode-invalid .card-3d canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 24px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, .18);
  background: #004766;
  position: relative;
  z-index: 2;
}

.mode-view .card-front-overlay,
.mode-invalid .card-front-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 24px;
  overflow: hidden;
  transform-origin: top center;
  transform-style: preserve-3d;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
  background: var(--viewer-bg);
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-view .card-front-overlay img,
.mode-invalid .card-front-overlay img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.mode-view .card-front-overlay.jiggle,
.mode-invalid .card-front-overlay.jiggle {
  animation: jiggleCard .55s ease;
}

.mode-view .card-front-overlay.swing,
.mode-invalid .card-front-overlay.swing {
  animation: swingCard 2.5s ease-out forwards;
}

.mode-view .card-front-final,
.mode-invalid .card-front-final {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 16px 32px rgba(0, 0, 0, .18);
  background: var(--viewer-bg);
  transform: translateY(0);
  opacity: 0;
  z-index: 1;
  transition: transform .9s ease, opacity .4s ease;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-view .card-front-final img,
.mode-invalid .card-front-final img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.mode-view .card-front-final.slide-out,
.mode-invalid .card-front-final.slide-out {
  transform: translateY(105%);
  opacity: 1;
}

@keyframes jiggleCard {
  0% {
    transform: rotateZ(0deg);
  }
  20% {
    transform: rotateZ(-2deg);
  }
  40% {
    transform: rotateZ(2deg);
  }
  60% {
    transform: rotateZ(-1deg);
  }
  80% {
    transform: rotateZ(1deg);
  }
  100% {
    transform: rotateZ(0deg);
  }
}

@keyframes swingCard {
  0% {
    transform: rotateX(0deg);
  }
  25% {
    transform: rotateX(-110deg);
  }
  45% {
    transform: rotateX(-80deg);
  }
  65% {
    transform: rotateX(-100deg);
  }
  85% {
    transform: rotateX(-88deg);
  }
  100% {
    transform: rotateX(-90deg);
  }
}

.mode-view .actions,
.mode-invalid .actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 18px;
}

.mode-view button,
.mode-invalid button {
  appearance: none;
  border-radius: 999px;
  border: 0;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, .18);
  font-family: inherit;
}

.mode-view .btn-primary,
.mode-invalid .btn-primary {
  background: #00a99c;
  color: #fff;
}

.mode-view .btn-secondary,
.mode-invalid .btn-secondary {
  background: #fff;
  color: #111;
  border: 1px solid rgba(0, 0, 0, .12);
}

.mode-view .small-note,
.mode-invalid .small-note {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  max-width: 600px;
  margin-top: 10px;
}

.mode-view .error,
.mode-invalid .error {
  color: #b91c1c;
  font-size: 14px;
  margin-top: 12px;
  text-align: center;
}
