/* Preview-loop judge prototype — see docs/website_builder_prototype_preview_spec.md
   Every brand token below is a CSS custom property living on #preview-root,
   a stable parent that sits OUTSIDE the #hero-slot Turbo Frame (spec §4).
   The frame's freshly server-rendered markup inherits these by cascade —
   nothing here re-applies vars after a swap, on purpose. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #111;
}

/* Brand tokens live on this class, not on #preview-root's selector directly, so the public
   site layout (app/views/layouts/public.html.erb) can pick up the exact same CSS custom
   properties as the editor without inheriting the editor's two-column grid below. */
.brand-tokens {
  --brand-primary: #2a3b4c;
  --brand-secondary: #8a9ba8;
  --brand-accent: #c7a97b;
  --brand-background: #fbfaf8;
  --brand-surface: #ffffff;
  --brand-text: #1a1a1a;
  --brand-muted: #6b6b6b;

  --font-heading: Georgia, "Times New Roman", serif;
  --font-body: "Helvetica Neue", Arial, sans-serif;

  --space-scale: 1.4;
  --radius: 4px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.45);
}

#preview-root {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* ---------- Control panel — deliberately raw, not the brand kit UI ---------- */

.control-panel {
  background: #f4f4f4;
  border-right: 1px solid #ddd;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  font-size: 0.8125rem;
  color: #333;
}

.control-panel__kicker {
  margin: 0;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #999;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  border: none;
  margin: 0;
  padding: 0;
}

.control legend {
  font-weight: 600;
  padding: 0;
  margin-bottom: 0.25rem;
}

.control label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: normal;
}

.control input[type="color"] {
  width: 100%;
  height: 2rem;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 2px;
}

.variant-link {
  display: inline-block;
  padding: 0.375rem 0.625rem;
  margin-right: 0.375rem;
  border: 1px solid #999;
  border-radius: 2px;
  color: #333;
  text-decoration: none;
  background: #fff;
}

.variant-link:hover {
  background: #eee;
}

.hint {
  font-size: 0.75rem;
  color: #888;
  margin: 0;
}

/* ---------- Publication (publication tranche) ---------- */

.control--publish {
  border-top: 1px solid #ddd;
  padding-top: 1.25rem;
}

.publish-status {
  font-size: 0.75rem;
  color: #555;
  line-height: 1.5;
  margin: 0 0 0.75rem;
}

.publish-status--ok {
  color: #1a6b3c;
  font-weight: 600;
}

.publish-button {
  width: 100%;
  padding: 0.5rem;
  border: none;
  border-radius: 2px;
  background: #2a3b4c;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.publish-button:hover {
  background: #1c2a37;
}

/* ---------- Preview stage — the canvas the hero renders onto ---------- */

.preview-stage {
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
}

#hero-slot {
  display: block;
  width: 100%;
  max-width: 960px;
}

/* ---------- HeroComponent ---------- */

.hero {
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius) * 3);
  box-shadow: var(--shadow);
  background: var(--brand-surface);
  font-family: var(--font-body);
  color: var(--brand-text);
}

.hero__media {
  position: relative;
  isolation: isolate;
}

.hero__image {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(120% 90% at 15% 20%, rgba(255, 214, 165, 0.55), transparent 55%),
    radial-gradient(90% 70% at 85% 75%, rgba(120, 90, 60, 0.5), transparent 60%),
    linear-gradient(160deg, #6b5a4a 0%, #2f2620 55%, #14100c 100%);
  transition: filter 120ms ease-out;
}

.hero__grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.16;
  transition: opacity 120ms ease-out;
}

.hero__content {
  display: flex;
  flex-direction: column;
  gap: calc(0.5rem * var(--space-scale));
  transition: gap 120ms ease-out;
}

.hero__headline {
  font-family: var(--font-heading);
  font-weight: normal;
  line-height: 1.1;
  margin: 0;
  outline: none;
  border-radius: 2px;
  transition: font-family 60ms;
}

.hero__headline:focus {
  box-shadow: 0 0 0 2px var(--brand-accent);
  caret-color: var(--brand-primary);
}

.hero__subhead {
  margin: 0;
  color: var(--brand-muted);
}

.hero__cta {
  display: inline-block;
  align-self: flex-start;
  background: var(--brand-primary);
  color: var(--brand-background);
  padding: calc(0.5rem * var(--space-scale)) calc(1.1rem * var(--space-scale));
  border-radius: var(--radius);
  font-size: 0.875rem;
}

/* Mood image — 100% CSS, no server round-trip (schema §7, décision n°3) */

[data-mood="warm-film"] .hero__image {
  filter: saturate(1.15) contrast(1.08) sepia(0.14) hue-rotate(-6deg);
}
[data-mood="warm-film"] .hero__grain {
  opacity: 0.2;
}

[data-mood="clean-bright"] .hero__image {
  filter: saturate(1.02) contrast(1.02) brightness(1.08) sepia(0);
}
[data-mood="clean-bright"] .hero__grain {
  opacity: 0.04;
}

/* ---------- Variant: full-bleed ---------- */

.hero--full-bleed .hero__media {
  aspect-ratio: 16 / 9;
}

.hero--full-bleed .hero__content {
  position: absolute;
  inset: 0;
  justify-content: flex-end;
  padding: calc(1.5rem * var(--space-scale)) calc(2rem * var(--space-scale)) calc(2.5rem * var(--space-scale));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0) 60%);
  color: #fff;
}

.hero--full-bleed .hero__headline {
  font-size: clamp(1.75rem, 4vw, 3rem);
  color: #fff;
}

.hero--full-bleed .hero__subhead {
  color: rgba(255, 255, 255, 0.8);
}

/* ---------- Variant: split ---------- */

.hero--split {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.hero--split .hero__media {
  min-height: 420px;
}

.hero--split .hero__content {
  justify-content: center;
  padding: calc(2rem * var(--space-scale)) calc(2.5rem * var(--space-scale));
}

.hero--split .hero__headline {
  font-size: clamp(1.5rem, 3vw, 2.5rem);
}

@media (max-width: 720px) {
  #preview-root {
    grid-template-columns: 1fr;
  }
  .hero--split {
    grid-template-columns: 1fr;
  }
}
