:root {
  --gold: #c9a96a;
  --ink: #232323;
  --white: #ffffff;
  --sand: #dfdbd2;
  --panel: #f4f1ea;
  --line: rgba(35, 35, 35, 0.12);
  --flyer-w: 1080px;
  --flyer-h: 1202px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "DM Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(201, 169, 106, 0.28), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(35, 35, 35, 0.08), transparent 50%),
    linear-gradient(160deg, #ebe6db 0%, var(--sand) 45%, #d4cfc4 100%);
}

body {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  min-height: 100vh;
}

/* —— Controls —— */
.controls {
  background: rgba(244, 241, 234, 0.92);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--line);
  padding: 28px 22px 40px;
  overflow-y: auto;
  max-height: 100vh;
}

.controls h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.controls .sub {
  margin: 0 0 24px;
  font-size: 0.85rem;
  opacity: 0.65;
}

.group {
  margin-bottom: 22px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.group:last-of-type { border-bottom: 0; }

.group h2 {
  margin: 0 0 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(35, 35, 35, 0.55);
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin: 0 0 6px;
}

.field { margin-bottom: 12px; }

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 169, 106, 0.25);
}

textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.45;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn, .file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, opacity 0.15s;
}

.btn:active, .file-btn:active { transform: scale(0.98); }

.file-btn {
  background: var(--ink);
  color: var(--white);
}

.file-btn:hover { background: #3a3a3a; }

.btn-export {
  background: var(--gold);
  color: var(--ink);
  margin-top: 4px;
}

.btn-export:hover { filter: brightness(1.05); }

.btn-export:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  margin-top: 8px;
}

.btn-ghost:hover { background: rgba(35, 35, 35, 0.04); }

input[type="file"] { display: none; }

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

.hint {
  margin: 6px 0 0;
  font-size: 0.75rem;
  opacity: 0.55;
  line-height: 1.35;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.switch-row span {
  font-size: 0.9rem;
  font-weight: 600;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch .slider {
  position: absolute;
  inset: 0;
  background: rgba(35, 35, 35, 0.2);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .slider { background: var(--gold); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-row input[type="color"] {
  width: 44px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
}

.swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
}

.swatch.active { border-color: var(--ink); }

/* —— Preview stage —— */
.stage {
  display: grid;
  place-items: center;
  padding: 32px 24px 16px;
  overflow: auto;
}

.stage-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.preview-label {
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.5;
}

.flyer-scale {
  width: min(540px, calc(100vw - 420px));
  aspect-ratio: 1080 / 1202;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 24px 60px rgba(35, 35, 35, 0.18),
    0 2px 8px rgba(35, 35, 35, 0.08);
}

/* Scales preview only — #flyer itself stays full-size for clean export */
.flyer-scaler {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--flyer-w);
  height: var(--flyer-h);
  transform-origin: top left;
  transform: scale(var(--preview-scale, 0.5));
}

/* —— Flyer —— */
.flyer {
  position: relative;
  width: var(--flyer-w);
  height: var(--flyer-h);
  background: var(--sand) center / cover no-repeat;
  overflow: hidden;
  color: var(--ink);
  user-select: none;
}

.flyer-pad {
  position: absolute;
  inset: 52px 52px 12px;
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.photo-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: rgba(35, 35, 35, 0.08);
  cursor: grab;
  flex-shrink: 0;
}

.photo-frame:active { cursor: grabbing; }

.photo-frame .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: rgba(35, 35, 35, 0.4);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.photo-frame img.property {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center center;
  pointer-events: none;
  will-change: transform;
}

/* Corner ribbon — centered on the TL diagonal, clipped cleanly to the photo */
.ribbon-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 360px;
  height: 360px;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}

.ribbon-wrap[hidden] { display: none !important; }

.ribbon {
  position: absolute;
  top: 0;
  left: 0;
  width: 420px;
  padding: 18px 0;
  text-align: center;
  background: var(--gold);
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
  /* Place band center on the corner diagonal, then rotate */
  transform: translate(-50%, -50%) translate(120px, 120px) rotate(-45deg);
}

.location-badge {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 3;
  background: var(--ink);
  color: var(--white);
  padding: 14px 22px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  max-width: 70%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.details {
  flex: 1;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 40px;
  align-items: start;
  min-height: 0;
}

.details-left {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 8px;
}

.price {
  font-size: 52px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 0;
  word-break: break-word;
}

.blurb {
  margin: 0;
  font-size: 18px;
  line-height: 1.45;
  font-weight: 400;
  max-width: 520px;
  white-space: pre-wrap;
}

.is-placeholder {
  opacity: 0.38;
}

.specs {
  display: flex;
  align-items: center;
  gap: 28px;
  margin-top: 8px;
  font-size: 22px;
  font-weight: 600;
}

.spec {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.spec svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  padding-top: 68px;
  margin-right: 58px;
}

.brand img {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .controls {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .flyer-scale {
    width: min(540px, calc(100vw - 48px));
  }
}
