:root {
  /* Warm paper + Hespress Immobilier brand blue accent. */
  --paper: #fcfaf8;
  --ink: #1c1a17;
  --ink-soft: #6f6b64;
  --accent: #1c22bf;
  --accent-deep: #151a99;
  --accent-rgb: 28, 34, 191;
  --line: rgba(28, 26, 23, 0.12);
  --card: rgba(252, 250, 248, 0.72);
  --glass-blur: saturate(130%) blur(12px);
  --radius: 22px;
  --shadow: 0 24px 60px -30px rgba(40, 34, 22, 0.5);
  --display: "Leckerli One", "Brush Script MT", cursive;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- Subtle paper texture (fixed behind everything) ---- */
.paper-texture {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.17;
  background-image:
    radial-gradient(circle at 14% 18%, rgba(0,0,0,0.13) 0 1px, transparent 1.5px),
    radial-gradient(circle at 76% 64%, rgba(0,0,0,0.10) 0 1px, transparent 1.5px),
    linear-gradient(110deg, rgba(0,0,0,0.04), transparent 35%, rgba(0,0,0,0.03));
  background-size: 34px 34px, 48px 48px, 100% 100%;
  mix-blend-mode: multiply;
}

.shell {
  position: relative;
  z-index: 2;
  max-width: 1040px;
  margin: 0 auto;
  padding: 72px 28px 96px;
}

/* ---- Login page ---- */
.login-shell {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px 36px 36px;
  background: var(--card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: clamp(2rem, 5vw, 2.8rem); margin: 6px 0 10px; }
.login-lede {
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 0.98rem;
  line-height: 1.55;
}
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-submit { width: 100%; margin-top: 4px; }
.login-error {
  margin: 0 0 20px;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  color: #8c2f22;
  background: rgba(169, 68, 47, 0.12);
  border: 1px solid rgba(169, 68, 47, 0.3);
}

/* ---- Brand bar (session) ---- */
.brandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 18px;
  margin-bottom: 30px;
  border-bottom: 1px solid var(--line);
}
.brand-user { font-size: 0.9rem; color: var(--ink-soft); }
.brand-user strong { color: var(--ink); font-weight: 600; }
.brand-logout {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent-deep);
  text-decoration: none;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  transition: background 0.2s, transform 0.15s;
}
.brand-logout:hover { background: rgba(var(--accent-rgb), 0.1); transform: translateY(-1px); }

/* ---- Masthead ---- */
.masthead { margin-bottom: 40px; }
.kicker {
  display: inline-block;
  font-size: 0.74rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-deep);
  font-weight: 600;
  margin-bottom: 14px;
}
h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.6rem, 6vw, 4.4rem);
  line-height: 1.08;
  margin: 0 0 18px;
  color: var(--ink);
  letter-spacing: 0.005em;
}
.lede {
  max-width: 54ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.6;
  background: rgba(252, 250, 248, 0.55);
  border-radius: 12px;
  padding: 2px 0;
}

/* ---- Dropzone ---- */
.dropzone {
  margin-top: 8px;
  border: 1.6px dashed rgba(28, 34, 191, 0.4);
  border-radius: var(--radius);
  background: var(--card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.25s, transform 0.25s, background 0.25s;
}
.dropzone:hover, .dropzone:focus-visible { outline: none; border-color: var(--accent); transform: translateY(-2px); }
.dropzone.is-drag { border-color: var(--accent-deep); background: rgba(252,250,248,0.9); transform: scale(1.006); }

.dropzone-inner {
  padding: 56px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}
.dropzone-icon {
  width: 68px; height: 68px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--accent-deep);
  background: linear-gradient(135deg, rgba(28,34,191,0.16), rgba(28,26,23,0.08));
  margin-bottom: 10px;
}
.dropzone-title { font-size: 1.15rem; font-weight: 500; margin: 0; }
.dropzone-hint { margin: 0; color: var(--ink-soft); font-size: 0.92rem; }
.link { color: var(--accent-deep); font-weight: 600; }

/* ---- Action bar ---- */
.actionbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 10px;
  flex-wrap: wrap;
}
.actionbar[hidden] { display: none; }
.btn {
  font-family: var(--sans);
  font-size: 0.94rem;
  font-weight: 500;
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  box-shadow: 0 14px 30px -14px rgba(28, 34, 191, 0.55);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 18px 34px -14px rgba(28,34,191,0.5); }
.btn-ghost {
  background: rgba(252,250,248,0.7);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: rgba(252,250,248,0.95); }
.counter { margin-left: auto; color: var(--ink-soft); font-size: 0.88rem; }

/* ---- Gallery ---- */
.gallery {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
}
.card {
  background: var(--card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: rise 0.4s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #ece5da;
  overflow: hidden;
  cursor: zoom-in;
}
.card-img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-veil {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  color: #fff;
  background: linear-gradient(180deg, rgba(28,26,23,0.28), rgba(28,26,23,0.55));
  backdrop-filter: blur(2px);
  transition: opacity 0.35s;
}
.card-status { font-size: 0.82rem; letter-spacing: 0.04em; text-shadow: 0 1px 6px rgba(0,0,0,0.4); text-align: center; padding: 0 10px; }

.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* State variants */
.card[data-state="ready"] .spinner { display: none; }
.card[data-state="done"] .card-veil { opacity: 0; pointer-events: none; }
.card[data-state="error"] .spinner { display: none; }
.card[data-state="error"] .card-veil { background: linear-gradient(180deg, rgba(169,95,47,0.6), rgba(120,54,40,0.8)); }

/* Remove (×) button — top-right of the media, above the veil. */
.card-remove {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 3;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  border-radius: 50%;
  color: #fff;
  background: rgba(28, 26, 23, 0.55);
  backdrop-filter: blur(3px);
  cursor: pointer;
  transition: background 0.18s ease, transform 0.15s ease;
}
.card-remove:hover { background: rgba(169, 68, 47, 0.9); transform: scale(1.08); }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 15px;
}
.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.card-download {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent-deep);
  text-decoration: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(28,34,191,0.32);
  transition: background 0.2s, transform 0.15s;
  flex: none;
}
.card-download:hover { background: rgba(28,34,191,0.1); transform: translateY(-1px); }

/* "Send to" transfer control */
.card-transfer { position: relative; }
.card-send {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 0.82rem; font-weight: 500;
  color: var(--ink-soft);
  background: none;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}
.card-send:hover { background: rgba(28,26,23,0.05); border-color: rgba(28,26,23,0.22); }
.card-send-menu {
  position: fixed;
  z-index: 60; /* above the hover-preview (50) */
  display: flex; flex-direction: column;
  min-width: 150px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: rise 0.14s ease both;
}
.card-send-opt {
  text-align: left;
  font: inherit; font-size: 0.85rem;
  color: var(--ink);
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.card-send-opt:hover { background: rgba(28,34,191,0.1); }

/* ---- Hover zoom preview ---- */
.hover-preview {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  padding: 8px;
  background: rgba(252, 250, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 30px 70px -24px rgba(40, 34, 22, 0.6);
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.14s ease, transform 0.14s ease;
}
.hover-preview.is-visible { opacity: 1; transform: scale(1); }
.hover-preview img {
  display: block;
  max-width: 42vw;
  max-height: 62vh;
  border-radius: 10px;
}

/* ---- Paste-a-link row ---- */
.url-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.url-input {
  flex: 1 1 260px;
  min-width: 0;
  padding: 11px 14px;
  font: inherit;
  color: var(--ink, #2c2620);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.url-input::placeholder { color: #9a9086; }
.url-input:focus {
  border-color: #9aa0e6;
  box-shadow: 0 0 0 3px rgba(28, 34, 191, 0.2);
}

/* ---- Reel maker section ---- */
.section-break {
  margin-top: 64px;
  padding-top: 40px;
  border-top: 1px solid var(--line);
}
.section-break h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.2rem, 4.5vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: 0.005em;
  color: var(--ink);
  margin: 8px 0 14px;
}
/* Reel outputs are 9:16 — show the cards in that portrait ratio. */
.gallery-reels {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.gallery-reels .card-media { aspect-ratio: 9 / 16; }

/* Feed outputs are 4:5 — slightly taller than square. */
.gallery-feeds {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.gallery-feeds .card-media { aspect-ratio: 4 / 5; }

/* Story outputs are 9:16 portrait. */
.gallery-stories {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.gallery-stories .card-media { aspect-ratio: 9 / 16; }

/* ---- Logo opacity slider ---- */
.slider {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 0.92rem;
  color: var(--ink, #2c2620);
}
.slider-label { color: var(--ink-soft); white-space: nowrap; }
.slider input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 116px; height: 4px;
  border-radius: 999px;
  background: #d8cfc3;
  outline: none;
  cursor: pointer;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #1c22bf;
  border: 2px solid var(--paper);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #1c22bf;
  border: 2px solid var(--paper);
}
.slider-value {
  font-variant-numeric: tabular-nums;
  min-width: 2.6em;
  color: var(--ink);
}

/* ---- Story listing fields ---- */
.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 4px;
  margin-bottom: 22px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.field input {
  padding: 11px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.field input:focus {
  border-color: #9aa0e6;
  box-shadow: 0 0 0 3px rgba(28, 34, 191, 0.2);
}

/* ---- Keep-logo toggle ---- */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: 0.92rem;
  color: var(--ink, #2c2620);
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: relative;
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: #d8cfc3;
  border: 1px solid var(--line);
  transition: background 0.18s ease;
  flex: none;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}
.toggle input:checked + .toggle-track { background: #1c22bf; }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(17px); }
.toggle input:focus-visible + .toggle-track {
  box-shadow: 0 0 0 3px rgba(28, 34, 191, 0.32);
}

@media (max-width: 560px) {
  .shell { padding: 48px 18px 72px; }
  .counter { width: 100%; margin: 4px 0 0; }
  .hover-preview { display: none; } /* no hover on touch */
}
