/*
 * Fonts, tokens, and type styles mirror the NAFTA design system (MBDS):
 * XD-Projects/projects/mb_nafta-design-system/src/styles/globals.css.
 * Component styles mirror its Button, Slider, ToggleGroup, Label, Tag, and Card.
 */

@font-face {
  font-family: 'MB Corpo A Title Cond WEB';
  src: url('assets/mbds/fonts/MBCorpoATitleCond-Regular-Web.woff2') format('woff2'),
    url('assets/mbds/fonts/MBCorpoATitleCond-Regular-Web.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'MB Corpo A Title WEB';
  src: url('assets/mbds/fonts/MBCorpoATitle-Regular-Web.woff2') format('woff2'),
    url('assets/mbds/fonts/MBCorpoATitle-Regular-Web.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'MB Corpo S Text WEB';
  src: url('assets/mbds/fonts/MBCorpoSText-Light-Web.woff2') format('woff2'),
    url('assets/mbds/fonts/MBCorpoSText-Light-Web.woff') format('woff');
  font-weight: 300;
  font-display: swap;
}
@font-face {
  font-family: 'MB Corpo S Text WEB';
  src: url('assets/mbds/fonts/MBCorpoSText-Regular-Web.woff2') format('woff2'),
    url('assets/mbds/fonts/MBCorpoSText-Regular-Web.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'MB Corpo S Text WEB';
  src: url('assets/mbds/fonts/MBCorpoSText-Bold-Web.woff2') format('woff2'),
    url('assets/mbds/fonts/MBCorpoSText-Bold-Web.woff') format('woff');
  font-weight: 700;
  font-display: swap;
}

:root {
  --font-family-display: 'MB Corpo A Title Cond WEB', 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  --font-family-title: 'MB Corpo A Title WEB', 'MB Corpo A Title Cond WEB', 'Helvetica Neue', Arial, sans-serif;
  --font-family-body: 'MB Corpo S Text WEB', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --amg-brand: #b21e23;
  --grey-white: #ffffff;
  --grey-90: #f4f4f4;
  --grey-85: #e8e8e8;
  --grey-75: #c9c9c9;
  --grey-60: #9f9f9f;
  --grey-40: #696969;
  --grey-25: #424242;
  --grey-15: #262626;
  --grey-05: #0d0d0d;
  --blue-85: #b4ddfe;
  --blue-65: #4eaffd;
  --blue-15: #003156;
  --red-55: #ff5c5c;
  --red-25: #821414;
  --red-10: #410a0a;

  /* MBDS dark-mode semantic tokens */
  --background: var(--grey-05);
  --foreground: var(--grey-white);
  --card: var(--grey-15);
  --muted: var(--grey-25);
  --muted-foreground: var(--grey-60);
  --accent: var(--blue-15);
  --accent-foreground: var(--blue-85);
  --border: var(--grey-25);
  --ring: var(--blue-65);
  --radius: 0.5rem;

  /* The experience's primary action keeps its holiday red, using the MBDS AMG brand token. */
  --action: var(--amg-brand);
  --action-hover: var(--red-25);
  --action-active: var(--red-10);

  /* Overwritten from the active sweater palette in app.js */
  --knit-band: #b3121b;
  --knit-motif: #f4efe6;
  --accent-text: #ff5c5c;

  --surface: rgba(13, 13, 13, 0.88);
  --topbar-h: 4.5rem;
  --footer-h: 2.75rem;
  --stage-pad-y: clamp(1rem, 2.2vw, 2rem);
  --caption-h: 3.25rem;
  /* Half the Snap it button hangs below the frame; this space is reserved so nothing jumps. */
  --snap-h: 3.25rem;
  --snap-overhang: calc(var(--snap-h) / 2);
  --panel-w: clamp(400px, 34vw, 32rem);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  font-size: 16px;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-family-body);
  color: var(--foreground);
  background-color: var(--background);
  overflow-x: hidden;
}
body.is-loading { overflow: hidden; }

h1, h2, h3, p { margin: 0; }

/* ---------- MBDS type styles ---------- */
.mb-heading-2xl { font-family: var(--font-family-display); font-weight: 400; font-size: 56px; line-height: 60px; }
.mb-body-lg { font-family: var(--font-family-body); font-weight: 400; font-size: 16px; line-height: 24px; }
.mb-body-lg-bold { font-family: var(--font-family-body); font-weight: 700; font-size: 16px; line-height: 24px; }
.mb-body-md { font-family: var(--font-family-body); font-weight: 400; font-size: 14px; line-height: 20px; }
.mb-body-md-bold { font-family: var(--font-family-body); font-weight: 700; font-size: 14px; line-height: 20px; }
.mb-body-sm { font-family: var(--font-family-body); font-weight: 400; font-size: 12px; line-height: 16px; }
.mb-eyebrow-sm { font-family: var(--font-family-body); font-weight: 700; font-size: 12px; line-height: 16px; text-transform: uppercase; letter-spacing: 0.06em; }
.mb-disclaimer-sm { font-family: var(--font-family-body); font-weight: 400; font-size: 12px; line-height: 16px; }

/* ---------- Knitted sweater background ---------- */
.knit-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--knit-band);
  background-repeat: repeat;
}
.knit-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 60% 45%, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.55) 85%);
}

.snow {
  position: fixed;
  inset: -100px 0 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 120px 80px, rgba(255, 255, 255, .8), transparent),
    radial-gradient(2.5px 2.5px at 200px 150px, rgba(255, 255, 255, .9), transparent),
    radial-gradient(1px 1px at 60px 190px, #fff, transparent),
    radial-gradient(2px 2px at 260px 40px, rgba(255, 255, 255, .7), transparent);
  background-size: 300px 220px;
  animation: snow 14s linear infinite;
  opacity: .6;
}
@keyframes snow { to { background-position: 60px 220px; } }

/* ---------- Loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
  transition: opacity 1.2s ease, visibility 1.2s;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader__snow { position: absolute; inset: 0; width: 100%; height: 100%; }
.loader__inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
}
.loader__star {
  width: 120px;
  height: 120px;
  filter: drop-shadow(0 0 24px rgba(255, 255, 255, .3));
  animation: starIn 1.6s cubic-bezier(.2, .7, .2, 1) both, glint 3s ease-in-out 1.6s infinite;
}
@keyframes starIn {
  from { opacity: 0; transform: rotate(-120deg) scale(.6); }
  to { opacity: 1; transform: none; }
}
@keyframes glint { 50% { filter: drop-shadow(0 0 40px rgba(255, 255, 255, .6)); } }
.loader__eyebrow { margin-top: 3rem; color: var(--grey-75); animation: fadeUp .8s .6s both; }
.loader__eyebrow .x { color: var(--accent-text); }
.loader__title { margin: 1rem 0 3rem; animation: fadeUp .8s .8s both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
.loader__msg { margin-top: 1.5rem; color: var(--muted-foreground); min-height: 20px; }

/* Knit stitch texture adapted from the original gist's `stitches` mixin */
.knit-bar {
  width: min(360px, 80vw);
  height: 16px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--muted);
  overflow: hidden;
}
.knit-bar__fill {
  display: block;
  height: 100%;
  width: 0;
  background-color: var(--knit-band);
  background-image:
    linear-gradient(55deg, transparent 2.5px, var(--knit-motif) 2.5px, var(--knit-motif) 4.5px, transparent 4.5px),
    linear-gradient(-55deg, transparent 2.5px, var(--knit-motif) 2.5px, var(--knit-motif) 4.5px, transparent 4.5px);
  background-size: 10px 12px;
  background-position: 5.5px 2px, -5px 2px;
  transition: width .35s ease;
}

/* ---------- Top bar ---------- */
.topbar, .stage, .footer { position: relative; z-index: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--topbar-h);
  padding: .75rem clamp(1rem, 3vw, 3rem);
  background: var(--surface);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .875rem; min-width: 0; }
.brand__star { width: 36px; height: 36px; flex-shrink: 0; }
.brand__text { display: flex; align-items: center; gap: .875rem; min-width: 0; }
.brand__wordmark { height: 16px; width: auto; }
.brand__divider { width: 1px; height: 22px; background: var(--grey-40); }
.brand__sub { color: var(--grey-75); white-space: nowrap; }

/* MBDS Tag */
.tag {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .25rem .625rem;
  border: 1px solid var(--grey-75);
  border-radius: 999px;
  background: rgba(13, 13, 13, .6);
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
  white-space: nowrap;
}
.tag b { color: var(--accent-text); }

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  display: grid;
  /* Portrait column is sized by the frame; the controls panel takes the rest. */
  /* Fixed-width controls column; the portrait takes all remaining space. */
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
  gap: clamp(1.5rem, 3vw, 4rem);
  align-items: start;
  width: 100%;
  padding: var(--stage-pad-y) clamp(1rem, 3vw, 3rem);
}

/* MBDS Card, on a translucent dark surface so text stays readable over every knit palette */
.panel {
  background: var(--surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  padding: clamp(1.25rem, 2vw, 1.75rem);
}

/* Controls stay horizontally centered in the panel as the viewport changes. */
/* Hugs its content and sits vertically centered beside the portrait. */
.intro { display: flex; flex-direction: column; align-self: center; }
.intro__inner { width: 100%; max-width: 28rem; margin-inline: auto; }

.eyebrow { color: var(--grey-75); margin-bottom: .75rem; }
.headline { margin-bottom: 1rem; }
.headline em { font-style: normal; color: var(--accent-text); }
.lede { color: var(--grey-85); }

.steps { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: 1.25rem; }
.steps li { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: 1rem; }
.steps h3 { margin: 4px 0 .625rem; }
.steps__n {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--grey-40);
}

.actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.hint { margin-top: .625rem; color: var(--muted-foreground); }

/* MBDS Button (size lg) */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  height: 2.75rem;
  padding: 0 1.5rem;
  border: 1px solid transparent;
  border-radius: 2px;
  font: 700 16px/1 var(--font-family-body);
  color: var(--grey-white);
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.btn:focus-visible, .toggle-group__item:focus-visible { box-shadow: 0 0 0 3px rgba(78, 175, 253, .5); border-color: var(--ring); }
.btn:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(78, 175, 253, .5); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn--primary { background: var(--action); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.btn--primary:hover { background: var(--action-hover); }
.btn--primary:active { background: var(--action-active); }
.btn--outline { background: var(--background); border-color: var(--grey-40); }
.btn--outline:hover { background: var(--grey-25); }
.btn--outline:active { background: var(--grey-40); }

/* MBDS ToggleGroup (outline) */
.toggle-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin-bottom: 1.25rem;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
}
.toggle-group__item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 2.5rem;
  padding: .375rem .625rem;
  border: 1px solid transparent;
  background: var(--background);
  color: var(--foreground);
  font: 400 14px/20px var(--font-family-body);
  text-align: left;
  cursor: pointer;
  outline: none;
  transition: background-color .15s, color .15s;
}
.toggle-group__item:hover { background: var(--muted); color: var(--grey-75); }
.toggle-group__item[aria-checked="true"] { background: var(--accent); color: var(--accent-foreground); }
.swatch__dots { display: flex; flex-shrink: 0; }
.swatch__dots i { width: 16px; height: 16px; border-radius: 50%; margin-right: -5px; border: 1px solid rgba(0, 0, 0, .5); }
.swatch__dots i:last-child { margin-right: 0; }

/* MBDS Label + Slider */
.field { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); align-items: center; gap: 1rem; margin-top: .875rem; }
.label { font-size: 14px; line-height: 1; font-weight: 400; color: var(--grey-85); user-select: none; }

.slider {
  --fill: 50%;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 16px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(to right, var(--action) var(--fill), var(--muted) var(--fill));
  cursor: pointer;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--action);
  background: var(--background);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: box-shadow .15s;
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--action);
  background: var(--background);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.slider:hover::-webkit-slider-thumb, .slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(78, 175, 253, .5); }
.slider:hover::-moz-range-thumb, .slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(78, 175, 253, .5); }

/* ---------- Preview ---------- */
.preview {
  position: sticky;
  top: var(--stage-pad-y);
  align-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

/*
 * Grows with the viewport. On desktop it fills the height left after the top bar, footer,
 * stage padding, and caption, so the page fits without scrolling. It never drops below 360px;
 * on shorter screens the page scrolls instead.
 */
.frame {
  position: relative;
  width: max(min(100%, 320px), min(100%, calc(100svh - var(--topbar-h) - var(--footer-h) - 2 * var(--stage-pad-y) - var(--caption-h) - var(--snap-overhang))));
  margin-bottom: var(--snap-overhang);
  aspect-ratio: 1;
  border-radius: 50%;
  padding: clamp(8px, 1.4%, 18px);
  background: conic-gradient(from 210deg, #8a9099, #f2f4f7, #7d848f, #e6e9ee, #8a9099);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .1);
}
.frame canvas { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--grey-15); }
.frame__badge {
  position: absolute;
  right: 6%;
  bottom: 6%;
  display: grid;
  place-items: center;
  width: 12%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--grey-05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5), 0 0 0 3px #9aa0a8;
}
.frame__badge img { width: 72%; height: 72%; }
.frame__live {
  position: absolute;
  top: 6%;
  left: 50%;
  transform: translateX(-50%);
  gap: .5rem;
  padding-inline: .75rem;
  background: var(--surface);
}

/* Pulsing record indicator shared by the Live tag and the Snap it button */
.live-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--red-55);
  box-shadow: 0 0 0 0 rgba(255, 92, 92, .7);
  animation: livePulse 1.6s ease-out infinite;
}
.btn--snap .live-dot { background: var(--grey-white); box-shadow: 0 0 0 0 rgba(255, 255, 255, .7); }
@keyframes livePulse { 70%, 100% { box-shadow: 0 0 0 8px rgba(255, 92, 92, 0); } }

/*
 * Snap it / Retake photo sit centered on the frame's bottom edge, over the knit yoke rather than
 * the face, so the capture action stays next to the preview (including on mobile).
 */
.frame__actions {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 50%);
  display: flex;
  z-index: 2;
}
.btn--snap {
  height: var(--snap-h);
  padding: 0 2rem;
  font-size: 18px;
  gap: .75rem;
}
.btn--snap.btn--primary {
  box-shadow: 0 0 0 0 rgba(178, 30, 35, .6), 0 6px 20px rgba(0, 0, 0, .5);
  animation: snapGlow 2s ease-out infinite;
}
.btn--snap.btn--outline { background: var(--surface); box-shadow: 0 6px 20px rgba(0, 0, 0, .5); }
@keyframes snapGlow { 70%, 100% { box-shadow: 0 0 0 10px rgba(178, 30, 35, 0), 0 6px 20px rgba(0, 0, 0, .5); } }
.btn--snap:focus-visible { animation: none; }

.caption {
  min-height: calc(var(--caption-h) - 1rem);
  padding: .5rem 1rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--grey-85);
  text-align: center;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: var(--footer-h);
  padding: .75rem clamp(1rem, 3vw, 3rem);
  color: var(--muted-foreground);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Shorter desktop screens: tighten vertical rhythm so the page, footer included, fits. */
@media (min-width: 1081px) and (max-height: 960px) {
  .panel { padding: 1.25rem 1.5rem; }
  .headline { margin-bottom: .75rem; font-size: 40px; line-height: 44px; }
  .steps { margin-top: 1rem; gap: 1rem; }
  .steps h3 { margin-bottom: .5rem; }
  .hint { margin-top: .375rem; }
  .toggle-group { margin-bottom: .75rem; }
  .field { margin-top: .5rem; }
}
@media (min-width: 1081px) and (max-height: 880px) {
  :root { --stage-pad-y: 1rem; }
  /* mb-body-md */
  .lede { font-size: 14px; line-height: 20px; }
  .steps { gap: .875rem; }
  .eyebrow { margin-bottom: .5rem; }
  .toggle-group__item { min-height: 2.25rem; padding: .25rem .5rem; gap: .375rem; }
  .panel { padding-block: 1rem; }
  /* MBDS Button size "default" (medium) for panel actions; Snap it in the frame stays large. */
  .panel .btn { height: 2.25rem; padding: 0 1rem; font-size: 14px; }
  /* Two sliders side by side, labels above */
  .step-yarn__fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
  .step-yarn__fields .field { grid-template-columns: minmax(0, 1fr); gap: .5rem; margin-top: .25rem; }
}

@media (min-width: 1081px) and (max-height: 800px) {
  :root { --stage-pad-y: .75rem; }
  .steps { gap: .75rem; }
}

/* Stacked layout: preview on top at full width, controls below. */
@media (max-width: 1080px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .preview { order: -1; position: static; }
  .frame { width: min(100%, max(320px, calc(100svh - var(--topbar-h) - 2 * var(--stage-pad-y) - var(--snap-h)))); }
  .intro__inner { max-width: 40rem; }
  .panel { width: 100%; min-width: 0; }
}

@media (max-width: 600px) {
  :root { --snap-h: 3rem; }
  .btn--snap { font-size: 16px; padding: 0 1.5rem; }
  .mb-heading-2xl { font-size: 40px; line-height: 44px; }
  .brand__text { flex-direction: column; align-items: flex-start; gap: 4px; }
  .brand__divider { display: none; }
  .brand__star { width: 32px; height: 32px; }
  .field { grid-template-columns: minmax(0, 1fr); gap: .625rem; }
  .actions .btn { flex: 1 1 auto; }
}

@media (max-width: 420px) {
  .toggle-group { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
