:root {
  --ink: #211a24;
  --muted: #756d78;
  --pearl: #f5f1f6;
  --paper: #fffdfd;
  --aubergine: #5a2d5f;
  --orchid: #cf83c1;
  --ice: #9bd7dc;
  --coral: #ff765e;
  --lime-thread: #c8db77;
  --line: rgba(40, 26, 42, .13);
  --shadow: 0 18px 50px rgba(66, 38, 67, .09);
  --radius: 22px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 84% 4%, rgba(207, 131, 193, .16), transparent 29rem),
    linear-gradient(135deg, rgba(155, 215, 220, .12), transparent 35rem),
    var(--pearl);
  font-family: "DM Sans", sans-serif;
  min-height: 100vh;
}

button, input, select { font: inherit; }

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(90, 45, 95, .35);
  outline-offset: 3px;
}

.page-shell {
  width: min(1540px, calc(100% - 36px));
  margin: 0 auto;
  padding: 26px 0 40px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px 22px;
}

.brand-lockup { display: flex; align-items: center; gap: 16px; }

.brand-monogram {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50% 50% 45% 55%;
  color: white;
  background: var(--aubergine);
  font: 600 27px/1 "Bodoni Moda", serif;
  transform: rotate(-7deg);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--aubergine);
  font: 500 10px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: .16em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font: 500 clamp(25px, 3vw, 39px)/.95 "Bodoni Moda", serif;
  letter-spacing: -.035em;
}

h1 em, h2 em { color: var(--aubergine); font-weight: 500; }

.live-stamp {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .56);
  color: var(--muted);
  font-size: 12px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #46a36b;
  box-shadow: 0 0 0 5px rgba(70, 163, 107, .14);
}

.control-ribbon {
  position: sticky;
  top: 10px;
  z-index: 20;
  display: flex;
  align-items: end;
  gap: 12px;
  min-height: 84px;
  padding: 15px 18px;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 20px;
  color: white;
  background: rgba(36, 25, 39, .92);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 38px rgba(34, 24, 36, .19);
}

.control-group { display: grid; gap: 6px; }
.control-group label { color: rgba(255,255,255,.6); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }

.control-group select,
.control-group input {
  min-height: 39px;
  padding: 7px 36px 7px 11px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 11px;
  color: white;
  background: rgba(255,255,255,.08);
}

.control-group select { color-scheme: dark; }
.control-group select option {
  color: var(--ink);
  background: var(--paper);
}

.control-period select { min-width: 170px; }
.custom-range { display: flex; gap: 10px; }

.refresh-button {
  min-height: 39px;
  padding: 8px 14px;
  border: 0;
  border-radius: 11px;
  color: var(--ink);
  background: var(--lime-thread);
  font-weight: 700;
  cursor: pointer;
}

.refresh-button:hover { filter: brightness(1.04); transform: translateY(-1px); }
.refresh-button.loading .refresh-icon { display: inline-block; animation: spin .8s linear infinite; }

.account-note {
  display: grid;
  margin-left: auto;
  align-self: center;
  text-align: right;
  font-size: 12px;
}
.account-note span { color: rgba(255,255,255,.55); }

main { padding: 25px 0; }

.loading-state {
  min-height: 58vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--muted);
}

.loading-mark {
  width: 52px;
  height: 52px;
  border: 2px solid rgba(90,45,95,.15);
  border-top-color: var(--aubergine);
  border-radius: 48% 52% 55% 45%;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  max-width: 720px;
  margin: 70px auto;
  padding: 45px;
  border: 1px solid rgba(255,118,94,.35);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.error-state h2 { font: 500 36px/1.08 "Bodoni Moda", serif; }
.error-state button { border: 0; padding: 11px 16px; border-radius: 10px; color: white; background: var(--aubergine); cursor: pointer; }

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(280px, .7fr);
  gap: 18px;
  margin-bottom: 18px;
}

.hero-statement,
.hero-score {
  position: relative;
  min-height: 235px;
  padding: clamp(28px, 5vw, 62px);
  overflow: hidden;
  border-radius: 30px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.hero-statement::after {
  content: "MOOD";
  position: absolute;
  right: -22px;
  bottom: -39px;
  color: rgba(90,45,95,.055);
  font: 600 126px/1 "Bodoni Moda", serif;
  letter-spacing: -.08em;
}

.hero-statement h2 {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin-bottom: 16px;
  font: 500 clamp(37px, 5.4vw, 72px)/.94 "Bodoni Moda", serif;
  letter-spacing: -.045em;
}

.hero-statement > p:not(.eyebrow) { max-width: 650px; color: var(--muted); }
.hero-meta { display: flex; gap: 18px; margin-top: 28px; color: var(--muted); font: 500 11px "IBM Plex Mono", monospace; }

.hero-score {
  display: grid;
  align-content: end;
  color: white;
  background: var(--aubergine);
}
.hero-score p { color: rgba(255,255,255,.62); text-transform: uppercase; letter-spacing: .12em; font-size: 10px; }
.hero-score strong { font: 500 clamp(58px, 8vw, 96px)/.9 "Bodoni Moda", serif; letter-spacing: -.06em; }
.hero-score .change { margin-top: 12px; }
.hero-score > :not(.score-seam) { position: relative; z-index: 1; }

.score-seam {
  position: absolute;
  width: calc(100% - 48px);
  height: 6px;
  left: 24px;
  top: 22px;
  background: repeating-linear-gradient(90deg, transparent 0 12px, var(--lime-thread) 12px 22px);
  opacity: .72;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 48px;
}

.kpi-card {
  min-height: 137px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,253,253,.8);
}
.kpi-card.primary { background: #e9e1eb; border-color: transparent; }
.kpi-card > span { display: block; min-height: 34px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.kpi-card strong { display: block; margin: 7px 0 10px; font: 600 clamp(24px, 3vw, 34px)/1 "Bodoni Moda", serif; letter-spacing: -.03em; }

.change { font-size: 11px; font-weight: 700; }
.change.positive { color: #2b8452; }
.change.negative { color: #cc5947; }
.change.neutral { color: var(--muted); }
.hero-score .change.positive { color: #d4eb9c; }
.hero-score .change.negative { color: #ffc3b9; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin: 0 6px 18px;
}
.section-heading h2 { margin-bottom: 0; font: 500 clamp(30px, 4vw, 47px)/1 "Bodoni Moda", serif; letter-spacing: -.04em; }
.section-heading > p { max-width: 470px; margin-bottom: 4px; color: var(--muted); font-size: 13px; text-align: right; }
.section-heading.compact { margin: 0 0 18px; }
.section-heading.compact h2 { font-size: 32px; }

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-bottom: 52px;
}

.chart-card,
.table-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 7px 26px rgba(66,38,67,.05);
}
.chart-wide { grid-column: 1 / -1; }
.card-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-heading > div:first-child { display: flex; align-items: center; gap: 12px; }
.card-heading h3 { margin: 0; font-size: 14px; }
.index { color: var(--orchid); font: 500 11px "IBM Plex Mono", monospace; }
.legend-note { color: var(--muted); font-size: 10px; }
.chart-frame { height: 320px; }
.chart-card:not(.chart-wide) .chart-frame { height: 280px; }

.runway-heading { margin-top: 10px; }
.creative-runway {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(245px, 295px);
  gap: 14px;
  padding: 2px 2px 26px;
  margin-bottom: 35px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-color: var(--orchid) transparent;
}

.creative-card {
  position: relative;
  scroll-snap-align: start;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 8px 28px rgba(66,38,67,.07);
}
.creative-media {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: #e6e0e7;
  cursor: pointer;
}
.creative-media img { width: 100%; height: 100%; object-fit: cover; transition: transform .45s ease; }
.creative-card:hover .creative-media img { transform: scale(1.035); }
.creative-media::after { content: ""; position: absolute; inset: auto 0 0; height: 44%; background: linear-gradient(transparent, rgba(25,17,27,.68)); pointer-events: none; }
.play-button { position: absolute; z-index: 2; left: 50%; top: 50%; translate: -50% -50%; width: 50px; height: 50px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.62); border-radius: 50%; color: white; background: rgba(31,21,33,.46); backdrop-filter: blur(8px); }
.creative-rank { position: absolute; z-index: 2; top: 13px; left: 13px; padding: 7px 9px; border-radius: 999px; color: white; background: rgba(31,21,33,.62); font: 500 10px "IBM Plex Mono", monospace; }
.creative-status { position: absolute; z-index: 2; right: 13px; top: 13px; padding: 6px 8px; border-radius: 999px; color: #24442f; background: #d6edbd; font-size: 9px; font-weight: 700; text-transform: uppercase; }
.creative-status.paused { color: #6a5c42; background: #f0e2b8; }
.creative-body { padding: 17px; }
.creative-body h3 { min-height: 42px; margin-bottom: 6px; font-size: 15px; line-height: 1.35; }
.creative-campaign { height: 34px; overflow: hidden; color: var(--muted); font-size: 11px; }
.creative-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 15px; }
.creative-metrics div { padding-top: 8px; border-top: 1px solid var(--line); }
.creative-metrics span { display: block; color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.creative-metrics strong { display: block; margin-top: 4px; font: 600 14px "IBM Plex Mono", monospace; }

.creative-empty { grid-column: 1 / -1; padding: 36px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; }

.campaign-section { margin-bottom: 14px; }
.campaign-card .chart-frame { height: 300px; }

.table-card { margin-top: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 12px 10px; border-bottom: 1px solid var(--ink); color: var(--muted); text-align: right; font-size: 9px; text-transform: uppercase; letter-spacing: .09em; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td { padding: 14px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
td:first-child { max-width: 360px; white-space: normal; font-weight: 600; }
.text-button { border: 0; color: var(--aubergine); background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 25px 7px 0; color: var(--muted); font-size: 10px; }

.creative-dialog {
  width: min(1120px, calc(100% - 30px));
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 28px;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 40px 100px rgba(23,13,25,.45);
}
.creative-dialog::backdrop { background: rgba(23,13,25,.72); backdrop-filter: blur(6px); }
.creative-dialog[open] { display: grid; grid-template-columns: minmax(300px, .78fr) 1.22fr; }
.dialog-media { min-height: 560px; background: #19131b; }
.dialog-media img, .dialog-media video { width: 100%; height: 100%; max-height: 78vh; object-fit: contain; }
.dialog-copy { max-height: 92vh; padding: clamp(28px, 4vw, 48px); overflow-y: auto; align-self: stretch; }
.dialog-copy h2 { font: 500 38px/1.05 "Bodoni Moda", serif; }
.dialog-copy > p:not(.eyebrow) { color: var(--muted); line-height: 1.65; }
.dialog-close { position: absolute; z-index: 2; top: 14px; right: 14px; width: 38px; height: 38px; border: 0; border-radius: 50%; color: white; background: rgba(31,21,33,.68); font-size: 22px; cursor: pointer; }
.dialog-metrics { display: grid; gap: 20px; margin: 25px 0; }
.dialog-metric-group h3 { margin: 0 0 8px; color: var(--aubergine); font: 600 10px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: .12em; }
.dialog-metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.dialog-metric-grid > div { min-width: 0; padding: 12px; border-radius: 12px; background: var(--pearl); }
.dialog-metric-grid span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; line-height: 1.3; }
.dialog-metric-grid strong { display: block; margin-top: 5px; overflow-wrap: anywhere; font: 600 15px "IBM Plex Mono", monospace; }
.preview-link { color: var(--aubergine); font-weight: 700; text-decoration: none; }

@media (max-width: 1050px) {
  .control-ribbon { flex-wrap: wrap; }
  .account-note { width: 100%; margin-left: 0; text-align: left; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 780px) {
  .page-shell { width: min(100% - 20px, 1540px); padding-top: 14px; }
  .masthead { align-items: flex-start; }
  .brand-monogram { width: 45px; height: 45px; }
  .live-stamp span:last-child { display: none; }
  .control-ribbon { position: static; align-items: stretch; }
  .control-group, .custom-range, .refresh-button { flex: 1 1 100%; width: 100%; }
  .custom-range { display: grid; grid-template-columns: 1fr 1fr; }
  .control-group select, .control-group input { width: 100%; }
  .hero-grid, .chart-grid { grid-template-columns: 1fr; }
  .hero-statement, .hero-score { min-height: 210px; padding: 30px; }
  .hero-score { min-height: 250px; }
  .chart-wide { grid-column: auto; }
  .section-heading { display: block; }
  .section-heading > p { margin-top: 10px; text-align: left; }
  .creative-dialog[open] { display: block; overflow-y: auto; }
  .dialog-media { min-height: 420px; max-height: 55vh; }
  .dialog-copy { max-height: none; overflow: visible; }
  footer { display: grid; }
}

@media (max-width: 480px) {
  .page-shell { width: min(100% - 12px, 1540px); }
  .masthead { gap: 8px; padding: 5px 4px 12px; }
  .brand-lockup { gap: 10px; }
  .brand-lockup h1 { font-size: clamp(25px, 9vw, 36px); }
  .brand-lockup .eyebrow { font-size: 8px; letter-spacing: .12em; }
  .brand-monogram { width: 39px; height: 39px; font-size: 24px; }
  .control-ribbon { gap: 10px; padding: 14px; border-radius: 18px; }
  .hero-statement, .hero-score { min-height: 0; padding: 24px 20px; border-radius: 22px; }
  .hero-statement h2 { font-size: clamp(39px, 13vw, 54px); }
  .hero-meta { display: grid; gap: 6px; margin-top: 20px; }
  .hero-score { min-height: 205px; }
  .hero-score strong { font-size: clamp(58px, 22vw, 84px); }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card { min-height: 122px; padding: 15px; }
  .kpi-card strong { font-size: 24px; }
  .section-heading h2 { font-size: 34px; }
  .chart-card, .table-card { padding: 15px; border-radius: 18px; }
  .chart-frame, .campaign-card .chart-frame { height: 260px; }
  .creative-runway { grid-auto-columns: minmax(235px, 82vw); }
  .dialog-copy { padding: 25px 18px; }
  .dialog-metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dialog-media { min-height: 300px; }
  footer { padding-inline: 4px; }
}

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

@media print {
  .control-ribbon, .refresh-button, .text-button, .live-stamp { display: none !important; }
  body { background: white; }
  .page-shell { width: 100%; }
  .hero-grid, .kpi-grid, .chart-grid { break-inside: avoid; }
  .creative-runway { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); overflow: visible; }
}
