@font-face {
  font-family: "Advercase";
  src: url("/assets/fonts/new-font/AdvercaseFont-Regular.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "Cocogoose Condensed";
  src: url("/assets/fonts/new-font/Cocogoose-Condensed-Regular-trial.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Finder";
  src: url("/assets/fonts/new-font/Finder.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "Neutral Face";
  src: url("/assets/fonts/new-font/NeutralFace-Bold.otf") format("opentype");
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Rockwell";
  src: url("/assets/fonts/new-font/Rockwell.ttc") format("truetype");
  font-display: swap;
}

:root {
  --page-bg: #171817;
  --panel-bg: #222321;
  --panel-muted: #2b2c29;
  --cream: #f6f0df;
  --muted: #a7a79f;
  --accent: #ef503c;
  --line: rgba(246, 240, 223, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background: var(--page-bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 12% 4%, rgba(239, 80, 60, 0.11), transparent 30rem),
    var(--page-bg);
  font-family: "Neutral Face", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.editor-page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px 24px 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 24px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--cream);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.back-link::before {
  content: "←";
  font-size: 20px;
  line-height: 1;
}

.intro {
  max-width: 760px;
  margin: 0 auto 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.intro h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 52px);
  line-height: 1;
  letter-spacing: -0.035em;
  text-transform: uppercase;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 720px);
  justify-content: center;
  align-items: start;
  gap: 18px;
}

.preview-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.025);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.32);
}

.jcard {
  position: relative;
  width: 100%;
  aspect-ratio: 3334 / 5000;
  overflow: hidden;
  container-type: inline-size;
  background: #eee8d5;
  isolation: isolate;
}

.template-base,
.template-overlay {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.template-base {
  z-index: 0;
}

.template-overlay {
  z-index: 3;
}

.upload-box {
  position: absolute;
  z-index: 2;
  overflow: hidden;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.upload-box[data-shape="circle"] {
  border-radius: 50%;
}

.upload-box[data-shape="round"] {
  border-radius: 15%;
}

.upload-box::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 0 6px 8px;
  color: #fff;
  background: linear-gradient(transparent 68%, rgba(0, 0, 0, 0.48));
  font-family: Arial, sans-serif;
  font-size: clamp(7px, 1.35cqw, 13px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 160ms ease;
}

.upload-box:hover::after,
.upload-box:focus-visible::after {
  opacity: 1;
}

.upload-box:focus-visible {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.upload-box img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.editable-text {
  position: absolute;
  z-index: 4;
  top: 29.1%;
  left: 2.25%;
  width: 7.2%;
  height: 36.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 0;
  padding: 0;
  color: #f8f2df;
  background: transparent;
  writing-mode: vertical-rl;
  text-orientation: sideways;
  white-space: nowrap;
  text-align: center;
  line-height: 1;
  letter-spacing: 0.02em;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.editable-text:hover,
.editable-text:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: rgba(239, 80, 60, 0.1);
}

.jcard[data-template="1"] .editable-text {
  font-family: "Cocogoose Condensed", sans-serif;
  font-size: 2.45cqw;
  font-weight: 700;
}

.jcard[data-template="2"] .editable-text {
  font-family: "Rockwell", serif;
  font-size: 2.2cqw;
}

.jcard[data-template="3"] .editable-text {
  font-family: "Finder", sans-serif;
  font-size: 2.3cqw;
}

.jcard[data-template="4"] .editable-text {
  font-family: "Advercase", sans-serif;
  font-size: 2.35cqw;
}

/* Template 1 — rounded photo windows */
.jcard[data-template="1"] .slot-main {
  top: 28.8%;
  left: 13.2%;
  width: 65%;
  height: 35.5%;
}

.jcard[data-template="1"] .slot-1,
.jcard[data-template="1"] .slot-2,
.jcard[data-template="1"] .slot-3 {
  top: 69.2%;
  width: 29.1%;
  height: 20.1%;
}

/* Template 2 — circular photo windows */
.jcard[data-template="2"] .slot-main {
  top: 27.8%;
  left: 12.9%;
  width: 65.4%;
  height: 37.4%;
}

.jcard[data-template="2"] .slot-1,
.jcard[data-template="2"] .slot-2,
.jcard[data-template="2"] .slot-3 {
  top: 69.7%;
  width: 28.6%;
  height: 19%;
}

/* Template 3–4 — rectangular photo windows */
.jcard[data-template="3"] .slot-main {
  top: 25.4%;
  left: 12.6%;
  width: 65.2%;
  height: 42.1%;
}

.jcard[data-template="3"] .slot-1,
.jcard[data-template="3"] .slot-2,
.jcard[data-template="3"] .slot-3 {
  top: 69.3%;
  width: 29.8%;
  height: 19.9%;
}

.jcard[data-template="4"] .slot-main {
  top: 29.2%;
  left: 14.3%;
  width: 63%;
  height: 34.8%;
}

.jcard[data-template="4"] .slot-1,
.jcard[data-template="4"] .slot-2,
.jcard[data-template="4"] .slot-3 {
  top: 69%;
  width: 29.1%;
  height: 20.8%;
}

.jcard[data-template="1"] .slot-1 {
  left: 2.9%;
}

.jcard[data-template="1"] .slot-2 {
  left: 35.5%;
}

.jcard[data-template="1"] .slot-3 {
  left: 67.8%;
}

.jcard[data-template="3"] .slot-1 {
  left: 2.8%;
}

.jcard[data-template="3"] .slot-2 {
  left: 35.1%;
}

.jcard[data-template="3"] .slot-3 {
  left: 67.3%;
}

.jcard[data-template="2"] .slot-1 {
  left: 3.3%;
}

.jcard[data-template="2"] .slot-2 {
  left: 35.7%;
}

.jcard[data-template="2"] .slot-3 {
  left: 68.1%;
}

.jcard[data-template="4"] .slot-1 {
  left: 2.85%;
}

.jcard[data-template="4"] .slot-2 {
  left: 35.5%;
}

.jcard[data-template="4"] .slot-3 {
  left: 68.2%;
}

.control-panel {
  width: 100%;
}

.generate {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  color: var(--cream);
  background: var(--accent);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.035em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 14px 32px rgba(239, 80, 60, 0.22);
  transition: transform 150ms ease, filter 150ms ease;
}

.generate:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.generate:disabled {
  cursor: wait;
  opacity: 0.62;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 220ms ease,
    visibility 0s linear 300ms;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.sheet {
  width: min(520px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  background: #f5f0e4;
  color: #171817;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition:
    transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 180ms ease;
}

.overlay.show .sheet {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.sheet h2 {
  margin: 0 0 20px;
  font-size: 22px;
  text-transform: uppercase;
}

.field {
  margin-bottom: 15px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: #6c6b65;
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input[type="text"],
.field select {
  width: 100%;
  height: 46px;
  border: 1px solid #cfcbc0;
  border-radius: 10px;
  padding: 0 13px;
  color: #171817;
  background: #fff;
  outline: none;
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 48px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23171817' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 16px;
  cursor: pointer;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239, 80, 60, 0.13);
}

.field input.invalid {
  border-color: #c7352c;
  box-shadow: 0 0 0 3px rgba(199, 53, 44, 0.12);
}

.field-error {
  min-height: 17px;
  margin: 6px 2px 0;
  color: #a42720;
  font-family: Arial, sans-serif;
  font-size: 12px;
  line-height: 1.4;
}

.name-sheet {
  width: min(480px, 100%);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 14px;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field input[type="color"] {
  width: 100%;
  height: 40px;
  border: 0;
  border-radius: 9px;
  padding: 2px;
  background: #fff;
  cursor: pointer;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.sheet-actions button,
.action-list button,
.crop-actions button {
  min-height: 46px;
  border: 1px solid #171817;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.primary-action {
  color: #fff;
  background: #171817;
}

.primary-action:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.secondary-action {
  color: #171817;
  background: transparent;
}

.action-list {
  display: grid;
  gap: 9px;
}

.action-list button {
  width: 100%;
  color: #171817;
  background: transparent;
  text-align: left;
}

.action-list .danger {
  color: #b22921;
  border-color: #d9aaa5;
}

.crop-sheet {
  width: min(900px, 100%);
}

.crop-stage {
  width: 100%;
  height: min(65vh, 620px);
  overflow: hidden;
  border-radius: 12px;
  background: #101110;
}

.crop-stage img {
  display: block;
  max-width: 100%;
}

body.modal-open {
  overflow: hidden;
}

body.is-processing .back-link,
body.is-processing .upload-box,
body.is-processing .editable-text {
  pointer-events: none;
}

@media (max-width: 600px) {
  .editor-page {
    padding: 14px 12px 52px;
  }

  .topbar {
    padding-bottom: 20px;
  }

  .intro {
    margin-bottom: 22px;
  }

  .preview-card {
    padding: 7px;
    border-radius: 10px;
  }

  .overlay {
    padding: 0;
    align-items: flex-end;
  }

  .sheet {
    max-height: 92vh;
    border-radius: 22px 22px 0 0;
  }

  .crop-sheet {
    padding: 14px;
  }

  .crop-stage {
    height: 62vh;
  }
}

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