/* =====================================================================
   style.css - the visual design ("mall directory" look, light by default)
   All colours live in the tokens below, so the dark theme only swaps them.
   ===================================================================== */

:root {
  --bg: #F5F7FA;        /* porcelain page background */
  --surface: #FFFFFF;   /* panels */
  --tint: #EEF1FB;      /* soft blue wash for the hero map and highlights */
  --ink: #1C2333;       /* main text and dark buttons */
  --muted: #5E6879;     /* secondary text */
  --line: #E2E7EF;      /* hairlines and borders */
  --focus: #4F6BED;     /* keyboard focus + links */
  --danger: #C4314B;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --font: "Overpass", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root.dark {
  --bg: #12161F;
  --surface: #1A202C;
  --tint: #1F2738;
  --ink: #E8ECF3;
  --muted: #9AA4B5;
  --line: #2B3343;
  --focus: #8DA2FF;
  --danger: #FF7A8E;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
       font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
.wrap { max-width: 1360px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
@media (min-width: 768px) { .wrap { padding-left: 32px; padding-right: 32px; } }
main.wrap { padding-top: 32px; padding-bottom: 48px; }
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
b, strong { font-weight: 700; }

/* ---------- Type scale ---------- */
.display { font-size: clamp(2.2rem, 5vw, 3.6rem); line-height: 1.02; font-weight: 900; letter-spacing: -0.03em; margin: 0; }
.h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); line-height: 1.1; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
.h2 { font-size: 1.35rem; line-height: 1.2; font-weight: 800; letter-spacing: -0.01em; margin: 0; }
.h3 { font-size: 1rem; line-height: 1.3; font-weight: 700; margin: 0; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 36em; margin: 18px 0 0; }
.sub { font-size: .92rem; color: var(--muted); margin: 4px 0 0; max-width: 62ch; }
.page-head { margin-bottom: 24px; }

/* ---------- Top bar and tabs ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
          backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-row { display: flex; align-items: center; gap: 20px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem;
         color: var(--ink); text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; justify-content: center; }
.tabs a { position: relative; padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: .95rem;
          color: var(--muted); text-decoration: none; white-space: nowrap; transition: color .15s, background .15s; }
.tabs a:hover { color: var(--ink); background: var(--tint); }
.tabs a.active { color: var(--surface); background: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.k-pill { font-size: .88rem; color: var(--muted); text-decoration: none; padding: 6px 12px; border: 1px solid var(--line);
          border-radius: 999px; background: var(--surface); white-space: nowrap; }
.k-pill b { color: var(--ink); }
.sample-badge { font-size: .78rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #FFF1C9; color: #7A5300; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 999px; cursor: pointer;
            border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.icon-btn .moon, .dark .icon-btn .sun { display: none; }
.dark .icon-btn .moon { display: block; }

/* Phones: brand + buttons on the first row, tabs scroll on a second row */
@media (max-width: 860px) {
  .topbar-row { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 8px; row-gap: 8px; }
  .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; }
  .tabs::-webkit-scrollbar { display: none; }
  .k-pill { display: none; }
}

/* ---------- Buttons and links ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px;
       border-radius: 999px; font: 700 .95rem/1 var(--font); text-decoration: none; cursor: pointer;
       border: 1.5px solid transparent; transition: transform .1s, background .15s, border-color .15s; }
.btn:active { transform: translateY(1px); }
.btn-ink { background: var(--ink); color: var(--surface); }
.btn-ink:hover { background: color-mix(in srgb, var(--ink) 85%, var(--focus)); }
.btn-ink:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--focus);
            cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px 24px; }
@media (max-width: 640px) { .panel { padding: 18px 16px; } }

/* ---------- Hero ---------- */
/* Hero: headline left, text right, then the big map across the full width */
.hero { padding: 8px 0 40px; }
.hero-text { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 56px; align-items: end; margin-bottom: 32px; }
.hero-side .lead { margin-top: 0; }
@media (max-width: 960px) { .hero-text { grid-template-columns: 1fr; gap: 20px; } }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.credits { display: grid; grid-template-columns: repeat(4, minmax(0, auto)); justify-content: start; gap: 14px 36px; margin: 28px 0 0;
           padding-top: 20px; border-top: 1px solid var(--line); }
.credits dt { font-size: .8rem; color: var(--muted); }
.credits dd { margin: 2px 0 0; font-weight: 700; }
/* The hero map sits on a faint dotted grid, like a store floor plan */
.hero-map { margin: 0; border-radius: 24px; padding: 18px 18px 14px; border: 1px solid var(--line);
            background: radial-gradient(circle, color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1.2px) 0 0 / 18px 18px,
                        var(--tint); box-shadow: 0 30px 60px -40px rgba(28, 35, 51, .35); }
.hero-map figcaption { font-size: .82rem; color: var(--muted); padding: 10px 6px 0; }

/* Training player */
.player-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 2px 4px 10px; }
.player-step { margin: 0; font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.player-phase { margin: 2px 0 0; font-size: .88rem; color: var(--muted); min-height: 1.4em; }
.player-controls { display: flex; gap: 6px; flex-shrink: 0; }
.ctrl { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 999px; cursor: pointer;
        border: 1px solid var(--line); background: var(--surface); color: var(--ink); transition: border-color .15s; }
.ctrl:hover { border-color: var(--ink); }
.ctrl .i-pause, .ctrl.playing .i-play { display: none; }
.ctrl.playing .i-pause { display: block; }
#play-btn { background: var(--ink); color: var(--surface); border-color: var(--ink); }
/* Scrubber: a range slider styled as a thin track with a round handle */
.scrub-row { display: flex; align-items: center; gap: 12px; padding: 0 4px 8px; }
.scrub { -webkit-appearance: none; appearance: none; flex: 1; height: 22px; background: transparent; cursor: grab; --fill: 0%; }
.scrub:active { cursor: grabbing; }
.scrub::-webkit-slider-runnable-track { height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--ink) var(--fill), color-mix(in srgb, var(--muted) 22%, transparent) var(--fill)); }
.scrub::-moz-range-track { height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 22%, transparent); }
.scrub::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--ink); }
.scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 999px;
  background: var(--surface); border: 3px solid var(--ink); box-shadow: 0 2px 6px rgba(28, 35, 51, .25); transition: transform .12s; }
.scrub::-moz-range-thumb { width: 16px; height: 16px; border-radius: 999px; background: var(--surface); border: 3px solid var(--ink); }
.scrub:hover::-webkit-slider-thumb, .scrub:focus-visible::-webkit-slider-thumb { transform: scale(1.15); }
.scrub-hint { font-size: .78rem; color: var(--muted); white-space: nowrap; }
@media (max-width: 640px) { .scrub-hint { display: none; } }
.progress { height: 4px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 18%, transparent); margin: 0 4px 6px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 999px; transition: width .5s ease; }

/* 3D plot */
.plot3d { position: relative; height: 640px; margin-top: 8px; }
@media (max-width: 1024px) { .plot3d { height: 480px; } }
@media (max-width: 640px) { .plot3d { height: 360px; } }

/* Expand button on every chart, and the full-screen viewer */
.expand-btn { position: absolute; top: -2px; right: 0; z-index: 2; width: 32px; height: 32px; display: grid; place-items: center;
              border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer;
              opacity: .75; transition: opacity .15s, color .15s, border-color .15s; }
.expand-btn:hover, .expand-btn:focus-visible { opacity: 1; color: var(--ink); border-color: var(--ink); }
.chart-dialog { width: min(1500px, 96vw); height: 92vh; max-width: none; max-height: none; padding: 20px 24px 24px;
                border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--ink); }
.chart-dialog[open] { display: flex; flex-direction: column; animation: dialogIn .18s ease-out; }
.chart-dialog::backdrop { background: rgba(28, 35, 51, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 8px; }
.dialog-body { flex: 1; min-height: 0; position: relative; }
.dialog-body > .chart-box, .dialog-body > .plot3d { height: 100% !important; margin: 0; }
.dialog-body .expand-btn { display: none; }
@keyframes dialogIn { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Key figures strip ---------- */
.stat-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface);
              border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 20px; }
.stat-strip > div { padding: 20px 24px; border-left: 1px solid var(--line); }
.stat-strip > div:first-child { border-left: 0; }
@media (max-width: 760px) {
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-strip > div:nth-child(3) { border-left: 0; }
  .stat-strip > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .stat-strip > div { padding: 16px; }
}
.stat-label { font-size: .85rem; color: var(--muted); margin: 0; }
.stat-value { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; margin: 4px 0 0; min-height: 2.4rem; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .95rem; font-weight: 600; color: var(--muted); margin-left: 3px; }

/* ---------- Small-multiple charts ---------- */
.multiples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 36px 40px; margin-top: 22px; }
.multiples .chart-box { height: 280px; }
@media (max-width: 760px) { .multiples { grid-template-columns: 1fr; } }

/* ---------- How it works ---------- */
.how { margin-top: 44px; }
.steps { list-style: none; padding: 0; margin: 20px 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
.steps li { padding: 4px 28px 4px 0; }
.steps li + li { padding-left: 28px; border-left: 1px solid var(--line); }
.steps p { color: var(--muted); font-size: .94rem; margin: 8px 0 0; max-width: 40ch; }
.step-num { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 999px; margin-bottom: 12px;
            border: 2px solid var(--ink); font-weight: 800; }
@media (max-width: 860px) {
  .steps { grid-template-columns: 1fr; gap: 22px; }
  .steps li, .steps li + li { padding: 0 0 0 0; border: 0; }
}

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 240px; margin-top: 12px; }
.chart-box.tall { height: 400px; }
.chart-box.xtall { height: 600px; }
.hero-box { height: 600px; margin-top: 0; }
@media (max-width: 1024px) { .hero-box, .chart-box.xtall { height: 480px; } }
@media (max-width: 640px) {
  .hero-box, .chart-box.xtall { height: 380px; }
  .chart-box.tall { height: 320px; }
  .multiples .chart-box { height: 220px; }
  .credits { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Choose K ---------- */
.k-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 32px; align-items: center; }
@media (max-width: 760px) { .k-panel { grid-template-columns: 1fr; gap: 20px; } }
.k-control { display: flex; align-items: center; gap: 28px; }
.k-big { display: flex; align-items: baseline; gap: 6px; min-width: 104px; font-variant-numeric: tabular-nums; }
.k-letter { font-size: 1.4rem; font-weight: 700; color: var(--muted); }
#k-value { font-size: 4.2rem; line-height: 1; font-weight: 900; letter-spacing: -0.04em; }
input[type="range"] { width: 100%; accent-color: var(--ink); height: 28px; cursor: pointer; }
.k-ticks { display: flex; justify-content: space-between; padding: 0 4px; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.k-stats { display: flex; gap: 28px; margin: 0; }
.k-stats dt { font-size: .82rem; color: var(--muted); }
.k-stats dd { margin: 2px 0 0; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Segment directory ---------- */
.directory { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.dir-row { display: grid; grid-template-columns: 14px minmax(0, 2.2fr) minmax(0, 1.4fr) minmax(0, 2.6fr); gap: 22px;
           padding: 22px 24px; border-top: 1px solid var(--line); align-items: start; }
.dir-row:first-child { border-top: 0; }
.dir-stripe { align-self: stretch; width: 6px; border-radius: 999px; background: var(--c); }
.dir-name { font-size: 1.15rem; font-weight: 800; line-height: 1.25; }
.dir-desc { color: var(--muted); font-size: .92rem; margin: 6px 0 0; }
.dir-meta { font-size: .84rem; color: var(--muted); margin-top: 8px; }
.size-bar { height: 8px; border-radius: 999px; background: var(--tint); margin-top: 8px; overflow: hidden; }
.size-bar span { display: block; height: 100%; border-radius: 999px; background: var(--c); }
.dir-count { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.dir-avgs { display: flex; gap: 18px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.dir-avgs b { display: block; color: var(--ink); font-size: 1rem; font-variant-numeric: tabular-nums; }
.dir-offer { font-size: .95rem; padding: 12px 14px; border-radius: var(--radius-sm);
             background: color-mix(in srgb, var(--c) 9%, var(--surface)); border-left: 3px solid var(--c); }
.dir-offer p:first-child { font-size: .8rem; color: var(--muted); margin: 0 0 2px; }
.dir-offer p { margin: 0; }
@media (max-width: 860px) {
  .dir-row { grid-template-columns: 6px minmax(0, 1fr); gap: 8px 16px; padding: 18px 16px; }
  .dir-row > :not(.dir-stripe) { grid-column: 2; }
  .dir-stripe { grid-row: span 3; }
}

/* ---------- Predict ---------- */
.field { display: block; }
.field span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.field input { width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
               background: var(--bg); color: var(--ink); font: 600 1.05rem var(--font); font-variant-numeric: tabular-nums; }
.field input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 18%, transparent); }
.field-error { color: var(--danger); font-size: .9rem; margin: 0; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
.preset { font: 600 .86rem var(--font); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
          background: var(--surface); color: var(--ink); cursor: pointer; }
.preset:hover { border-color: var(--ink); }
.empty { min-height: 220px; display: grid; place-content: center; text-align: center; border-style: dashed; }

/* The result is a swing tag, like the price tag on a shop item */
.tag { position: relative; display: grid; grid-template-columns: 60px minmax(0, 1fr); background: var(--surface);
       border: 1.5px solid var(--line); border-radius: 18px 22px 22px 18px; overflow: hidden;
       transform-origin: 30px 50%; animation: swingIn .7s cubic-bezier(.2, .9, .25, 1.15) both; }
.tag-stub { background: var(--c); display: grid; place-items: center; }
.tag-hole { width: 18px; height: 18px; border-radius: 999px; background: var(--bg); border: 2px solid color-mix(in srgb, var(--c) 60%, black); }
.tag-body { padding: 22px 24px; }
.tag-kicker { font-size: .88rem; color: var(--muted); margin: 0; }
.tag-name { font-size: clamp(1.7rem, 3.5vw, 2.4rem); font-weight: 900; line-height: 1.05; letter-spacing: -0.02em; margin: 4px 0 0; }
.tag-desc { color: var(--muted); margin: 8px 0 0; }
.tag-offer { margin-top: 18px; padding-top: 16px; border-top: 1.5px dashed var(--line); }
.tag-offer p:first-child { font-size: .84rem; color: var(--muted); margin: 0; }
.tag-offer p:last-child { font-size: 1.1rem; font-weight: 700; margin: 2px 0 0; }
.tag-foot { font-size: .84rem; color: var(--muted); margin-top: 14px; font-variant-numeric: tabular-nums; }
@keyframes swingIn {
  0% { opacity: 0; transform: rotate(-7deg) translateY(-8px); }
  60% { opacity: 1; transform: rotate(2deg); }
  100% { transform: none; }
}

/* ---------- Report (paper) ---------- */
.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.paper { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; max-width: 860px; margin: 0 auto;
         padding: 56px 64px; box-shadow: 0 1px 0 var(--line), 0 18px 40px -24px rgba(28, 35, 51, .25); }
@media (max-width: 640px) { .paper { padding: 28px 18px; } }
.paper h2 { font-size: 1.9rem; font-weight: 900; letter-spacing: -0.02em; line-height: 1.1; margin: 0; }
.paper h3 { font-size: 1.1rem; font-weight: 800; margin: 32px 0 8px; }
.paper p, .paper li { font-size: .97rem; line-height: 1.7; max-width: 70ch; }
.paper ul { list-style: disc; padding-left: 1.2rem; margin: 0; }
.paper li { margin: 4px 0; }
.paper table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 8px; }
.paper th, .paper td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.paper th { font-weight: 700; color: var(--muted); font-size: .84rem; }
.paper .meta th { width: 18%; }
.paper .num { text-align: right; font-variant-numeric: tabular-nums; }
.paper .report-date { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; background: var(--c); margin-right: 8px; }
.table-wrap { overflow-x: auto; }

/* ---------- Loading and errors ---------- */
.skeleton { display: inline-block; width: 70px; height: 30px; border-radius: 8px; background: var(--line); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.loader { position: absolute; inset: 0; display: none; place-items: center; background: color-mix(in srgb, var(--surface) 65%, transparent); }
.loader.show { display: grid; }
.loader::after { content: ""; width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line);
                 border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; margin-top: 24px;
             padding: 18px 20px; border-radius: var(--radius-lg); border: 1.5px solid var(--danger);
             background: color-mix(in srgb, var(--danger) 7%, var(--surface)); color: var(--danger); }
.error-box p { margin: 0; }
.footer { padding-top: 8px; padding-bottom: 32px; font-size: .85rem; color: var(--muted); }
.btn-sm { padding: 8px 14px; font-size: .88rem; }
@media (max-width: 860px) { #present-btn span { display: none; } #present-btn { padding: 0; width: 38px; height: 38px; } }

/* ---------- Upload panel ---------- */
.upload-panel { margin-top: 44px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 32px; align-items: center; }
@media (max-width: 860px) { .upload-panel { grid-template-columns: 1fr; } }
.data-source { margin: 14px 0 0; font-size: .92rem; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.dropzone { display: grid; justify-items: center; gap: 4px; padding: 34px 20px; border: 2px dashed var(--line);
            border-radius: var(--radius-lg); background: var(--bg); color: var(--muted); text-align: center; cursor: pointer;
            transition: border-color .15s, background .15s, transform .15s; }
.dropzone:hover, .dropzone:focus-within { border-color: var(--ink); color: var(--ink); }
.dropzone.drag { border-color: var(--focus); background: color-mix(in srgb, var(--focus) 8%, var(--surface)); transform: scale(1.01); color: var(--ink); }
.dropzone.is-off { cursor: default; border-style: solid; }
.dropzone.is-off:hover { border-color: var(--line); color: var(--muted); }
.drop-main { font-weight: 800; font-size: 1.05rem; color: var(--ink); margin-top: 6px; }
.drop-sub { font-size: .88rem; }

/* ---------- Upload pipeline dialog ---------- */
.pipe-dialog { width: min(1080px, 95vw); max-width: none; max-height: 94vh; overflow: auto; padding: 26px 28px; border: 1px solid var(--line);
               border-radius: 22px; background: var(--surface); color: var(--ink); }
.pipe-dialog[open] { animation: dialogIn .2s ease-out; }
.pipe-dialog::backdrop { background: rgba(28, 35, 51, .5); backdrop-filter: blur(3px); }
.pipe-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.pipe-percent { margin: 0; font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.pipe-bar { height: 6px; border-radius: 999px; background: var(--tint); margin: 16px 0 20px; overflow: hidden; }
.pipe-bar span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--ink); transition: width .45s ease; }
.pipe-body { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 26px; }
@media (max-width: 760px) { .pipe-body { grid-template-columns: 1fr; } }
.pipe-visual { display: flex; flex-direction: column; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: var(--tint); }
#pipe-canvas { display: block; width: 100%; height: 260px;
               background: radial-gradient(circle, color-mix(in srgb, var(--muted) 20%, transparent) 1px, transparent 1.2px) 0 0 / 16px 16px; }
/* Rows from the file stream past in a strip under the dots, like a receipt printer */
.pipe-rows { height: 118px; margin: 0; padding: 8px 14px; list-style: none; border-top: 1px dashed var(--line); background: var(--surface);
             font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden;
             display: flex; flex-direction: column; justify-content: flex-end; }
.pipe-rows li { animation: rowIn .25s ease-out; line-height: 1.55; overflow: hidden; text-overflow: ellipsis; }
.pipe-rows li:last-child { color: var(--ink); font-weight: 700; }
@keyframes rowIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.pipe-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; align-content: start; }
.pipe-steps li { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; padding: 12px; border-radius: 12px;
                 color: var(--muted); transition: background .2s, color .2s; }
.pipe-steps li b { display: block; font-size: .98rem; }
.pipe-steps li small { display: block; font-size: .84rem; margin-top: 2px; min-height: 1em; }
.pipe-steps li[data-state="active"] { background: var(--tint); color: var(--ink); }
.pipe-steps li[data-state="done"] { color: var(--ink); }
.pipe-steps li[data-state="done"] small { color: var(--muted); }
.pipe-steps li[data-state="error"] { color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, var(--surface)); }
.pipe-icon { width: 26px; height: 26px; border-radius: 999px; border: 2px solid var(--line); position: relative; margin-top: 1px; }
[data-state="active"] .pipe-icon { border-color: var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; }
[data-state="done"] .pipe-icon { border-color: var(--ink); background: var(--ink); animation: pop .3s ease-out; }
[data-state="done"] .pipe-icon::after { content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px;
  border: solid var(--surface); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
[data-state="error"] .pipe-icon { border-color: var(--danger); background: var(--danger); }
[data-state="error"] .pipe-icon::after { content: "!"; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--surface); font-weight: 900; font-size: .85rem; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.15); } 100% { transform: none; } }
.pipe-error { margin-top: 20px; padding: 16px 18px; border-radius: 14px; border: 1.5px solid var(--danger);
              background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
.pipe-error p { margin: 0; color: var(--danger); font-weight: 600; }

/* ---------- Presentation mode ---------- */
.present { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--bg); }
.present-top, .present-nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 4vw; }
.present-brand { font-weight: 800; color: var(--muted); }
.present-top-right { display: flex; align-items: center; gap: 10px; }
.present-count { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }
.present-nav { justify-content: center; gap: 20px; padding-bottom: 18px; }
.present-nav .icon-btn { width: 46px; height: 46px; }
.present-nav .icon-btn:disabled { opacity: .3; cursor: default; }
.present-dots { display: flex; gap: 8px; }
.p-dot { width: 10px; height: 10px; border-radius: 999px; border: 0; padding: 0; background: var(--line); cursor: pointer; transition: width .2s, background .2s; }
.p-dot.on { width: 28px; background: var(--ink); }
.present-stage { flex: 1; min-height: 0; position: relative; }
.slide { display: none; position: absolute; inset: 0; padding: 1vh 6vw 2vh; flex-direction: column; gap: 2.2vh; overflow: auto; }
.slide.active { display: flex; animation: slideIn .35s ease-out; }
.slide.active.from-left { animation-name: slideInLeft; }
@keyframes slideIn { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes slideInLeft { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
.slide h2 { font-size: clamp(1.8rem, 3.6vw, 3.2rem); font-weight: 900; letter-spacing: -0.03em; line-height: 1.05; margin: 0; }
.s-lead { font-size: clamp(1.05rem, 1.6vw, 1.45rem); color: var(--muted); max-width: 46ch; margin: 0; line-height: 1.5; }
.s-note { font-size: clamp(.95rem, 1.2vw, 1.15rem); color: var(--muted); margin: 0; }
.s-grow { flex: 1; min-height: 280px; }
.s-two { display: grid; grid-template-columns: 1fr 1fr; gap: 3vw; }
@media (max-width: 760px) { .s-two { grid-template-columns: 1fr; } .s-two .p-chart { min-height: 220px; } }
.s-fig { margin: 0; display: flex; flex-direction: column; min-height: 0; }
.s-fig figcaption { font-weight: 700; font-size: clamp(.95rem, 1.2vw, 1.15rem); margin-bottom: 8px; }
.p-chart { position: relative; flex: 1; min-height: 0; }
.s-title { margin: auto 0; display: grid; gap: 2.6vh; max-width: 1100px; }
.s-title h1 { font-size: clamp(2.4rem, 6vw, 5.4rem); font-weight: 900; letter-spacing: -0.035em; line-height: .98; margin: 0; }
.s-mark { width: clamp(56px, 7vw, 96px); height: auto; }
.s-credits { display: flex; flex-wrap: wrap; gap: 14px 44px; margin: 2vh 0 0; padding-top: 2.4vh; border-top: 1px solid var(--line); }
.s-credits dt { font-size: .9rem; color: var(--muted); }
.s-credits dd { margin: 2px 0 0; font-weight: 800; font-size: clamp(1rem, 1.4vw, 1.25rem); }
.s-split { display: grid; grid-template-columns: 1fr 1fr; gap: 5vw; align-items: start; margin-top: 2vh; }
@media (max-width: 760px) { .s-split { grid-template-columns: 1fr; } }
.s-points { margin: 0; padding: 0; list-style: none; display: grid; gap: 2.2vh; }
.s-points li { font-size: clamp(1.05rem, 1.6vw, 1.4rem); line-height: 1.45; padding-left: 22px; position: relative; max-width: 52ch; }
.s-points li::before { content: ""; position: absolute; left: 0; top: .6em; width: 9px; height: 9px; border-radius: 999px; background: var(--focus); }
.s-big li { font-size: clamp(1.15rem, 1.9vw, 1.65rem); }
.s-thanks { font-size: clamp(1.6rem, 3vw, 2.6rem); font-weight: 900; margin: auto 0 0; letter-spacing: -0.02em; }
.s-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2vw; }
@media (max-width: 760px) { .s-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.s-stats p { margin: 0; color: var(--muted); font-size: clamp(.85rem, 1.1vw, 1rem); }
.s-stats b { font-size: clamp(1.6rem, 3vw, 2.8rem); font-weight: 900; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.s-stats small { font-size: .45em; color: var(--muted); font-weight: 600; }
.s-table table { width: 100%; border-collapse: collapse; font-size: clamp(.95rem, 1.35vw, 1.25rem); font-variant-numeric: tabular-nums; }
.s-table th, .s-table td { padding: 1.4vh 1vw; border-bottom: 1px solid var(--line); text-align: left; }
.s-table th { color: var(--muted); font-weight: 700; font-size: .85em; }
.s-table .num { text-align: right; }
.s-table .z { color: var(--focus); font-weight: 800; }
.s-table .s-mean td { color: var(--muted); }
.s-offers { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.6vw; align-content: start; overflow: auto; }
.s-offer { padding: 2.2vh 1.4vw; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--c); }
.s-offer-name { font-size: clamp(1.1rem, 1.6vw, 1.45rem); font-weight: 900; margin: 0; }
.s-offer-meta { color: var(--muted); font-size: .9rem; margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.s-offer-action { margin: 12px 0 0; font-size: clamp(.95rem, 1.2vw, 1.1rem); font-weight: 600; }
/* Problem slide: text left, before/after pictures right */
.s-problem { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 4vw; align-items: stretch; }
.s-problem-text { display: flex; flex-direction: column; gap: 4vh; justify-content: center; }
.s-compare { display: grid; grid-template-rows: 1fr 1fr; gap: 2vh; min-height: 0; }
.s-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1.8vh 1.4vw; }
.s-compare .s-fig figcaption { display: flex; align-items: center; gap: 10px; font-size: clamp(.95rem, 1.2vw, 1.15rem); }
.s-tag { font-size: .75em; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--ink); color: var(--surface); }
.s-tag-grey { background: var(--line); color: var(--muted); }
@media (max-width: 900px) { .s-problem { grid-template-columns: 1fr; } .s-compare { min-height: 520px; } }

/* 3D slide: title, explanation and legend on the left, the big plot on the right */
.s-3d { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(260px, 26vw) minmax(0, 1fr); gap: 2vw; }
.s-3d-side { display: flex; flex-direction: column; gap: 2.4vh; min-height: 0; padding-top: 1vh; }
.s-3d .s-slot { min-height: 0; }
.s-3d .s-slot .plot3d { flex: 1; height: auto; min-height: 0; margin: 0; }
.s-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; overflow: auto; min-height: 0; }
.s-legend li { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 10px; align-items: center;
               padding: 7px 10px; border-radius: 10px; font-size: clamp(.88rem, 1vw, 1rem); }
.s-legend li:nth-child(odd) { background: var(--surface); }
.s-legend-dot { width: 12px; height: 12px; border-radius: 999px; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); }
.s-legend-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-legend-n { color: var(--muted); font-variant-numeric: tabular-nums; }
.s-hint { margin-top: auto; }
@media (max-width: 900px) { .s-3d { grid-template-columns: 1fr; grid-template-rows: auto minmax(360px, 1fr); } }

/* Conclusions slide */
.s-end { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr); gap: 4vw; align-items: center; }
.s-numbers { display: grid; gap: 3vh; padding: 3vh 2vw; }
.s-donut { position: relative; height: clamp(180px, 26vh, 280px); }
.s-donut .p-chart { position: absolute; inset: 0; }
.s-donut-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.s-donut-label b { font-size: clamp(2rem, 4vw, 3.4rem); font-weight: 900; line-height: 1; }
.s-donut-label span { color: var(--muted); font-size: .95rem; }
.s-numbers dl { display: grid; grid-template-columns: 1fr 1fr; gap: 2vh 1.5vw; margin: 0; }
.s-numbers dt { color: var(--muted); font-size: .85rem; }
.s-numbers dd { margin: 2px 0 0; font-size: clamp(1.2rem, 2vw, 1.8rem); font-weight: 900; font-variant-numeric: tabular-nums; }
.s-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 12px;
            border-top: 1px solid var(--line); padding-top: 2vh; }
.s-footer .s-thanks { margin: 0; }
.s-sign { margin: 0; color: var(--muted); font-weight: 700; }
@media (max-width: 900px) { .s-end { grid-template-columns: 1fr; } }

/* Borrowed pieces (the animation and the 3D plot) fill their slide */
.s-slot { display: flex; flex-direction: column; min-height: 0; }
.s-slot .hero-map { flex: 1; display: flex; flex-direction: column; min-height: 0; box-shadow: none; }
.s-slot .hero-box { flex: 1; height: auto; min-height: 260px; }
.s-slot .hero-map figcaption { display: none; }
.s-slot .plot3d { flex: 1; height: auto; min-height: 300px; }
.present .expand-btn { display: none; }

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

/* ---------- Print: only the report, on plain white paper ---------- */
@media print {
  .no-print, .topbar, .footer, .page:not(#page-report) { display: none !important; }
  :root, :root.dark { --bg: #fff; --surface: #fff; --ink: #000; --muted: #444; --line: #ccc; }
  body { background: #fff; }
  main.wrap { padding: 0; max-width: none; }
  .paper { border: 0; box-shadow: none; padding: 0; max-width: none; }
  .dot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
