:root{
  /* palette taken from flackdesign.it */
  --paper:#f5f3e6;          /* brand cream */
  --paper-2:#efecd9;
  --ink:#2a2a2a;            /* brand near-black */
  --ink-2:#5d5c58;
  --ink-3:#948f82;
  --line:#e3dfc9;
  --accent:#971b81;         /* brand magenta */
  --accent-ink:#7d1569;
  --accent-soft:#f8ebf5;
  --accent-line:#dcaed2;

  --font-display:'Inter Tight',system-ui,-apple-system,'Segoe UI',sans-serif;
  --font-body:'Lato',system-ui,-apple-system,'Segoe UI',sans-serif;

  --radius:14px;
  --shadow:0 1px 2px rgba(42,42,42,.05), 0 8px 24px -12px rgba(42,42,42,.2);
  --panel-w:380px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:var(--font-body);
  color:var(--ink);
  background:var(--paper);
  -webkit-font-smoothing:antialiased;
  overflow:hidden;
}

.app{display:flex;height:100dvh;width:100%}

/* ───────── stage ───────── */
.stage{
  flex:1 1 auto;min-width:0;
  display:flex;flex-direction:column;
  padding:22px 22px 18px;
  gap:12px;
}
.stage__head{display:flex;align-items:flex-start;gap:22px}
.brand{display:flex;flex-direction:column;gap:6px;line-height:1;padding-top:2px;text-decoration:none}
.brand__logo{display:block;height:29px;width:auto}
.brand__sub{font-family:var(--font-display);font-weight:600;font-size:10.5px;letter-spacing:.3em;text-transform:uppercase;color:var(--ink-3)}
.stage__title{border-left:1px solid var(--line);padding-left:22px}
.stage__title h1{margin:0;font-family:var(--font-display);font-size:18px;font-weight:700;letter-spacing:-.005em}
.stage__title p{margin:3px 0 0;font-size:12.5px;color:var(--ink-3)}

.viewport{
  position:relative;flex:1 1 auto;min-height:0;
  border-radius:var(--radius);
  overflow:hidden;
  background:
    radial-gradient(120% 90% at 50% 8%, #fffef5 0%, #f5f3e6 46%, #e6e2cb 100%);
  box-shadow:inset 0 0 0 1px var(--line), var(--shadow);
  cursor:grab;
}
.viewport:active{cursor:grabbing}
.viewport canvas{display:block;width:100%;height:100%;touch-action:none}

.loader{
  position:absolute;inset:0;display:flex;align-items:center;justify-content:center;gap:10px;
  font-size:13px;color:var(--ink-3);background:var(--paper-2);
  transition:opacity .45s ease;
}
.loader span{
  width:13px;height:13px;border-radius:50%;
  border:2px solid var(--line);border-top-color:var(--accent);
  animation:spin .8s linear infinite;
}
.loader.is-done{opacity:0;visibility:hidden;pointer-events:none}
.loader.is-error{
  flex-direction:column;gap:7px;padding:28px;text-align:center;
  color:var(--ink);background:var(--paper-2);
}
.loader.is-error strong{font-family:var(--font-display);font-size:15px;font-weight:700}
.loader.is-error span{max-width:38ch;font-size:13px;line-height:1.55;color:var(--ink-3);
  width:auto;height:auto;border:0;border-radius:0;animation:none}
@keyframes spin{to{transform:rotate(360deg)}}

.stage__tools{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.tool{
  display:inline-flex;align-items:center;gap:7px;
  font-family:var(--font-display);font-size:12.5px;font-weight:600;color:var(--ink-2);
  background:#fff;border:1px solid var(--line);border-radius:999px;
  padding:7px 14px 7px 11px;cursor:pointer;
  transition:border-color .16s,color .16s,background .16s;
}
.tool:hover{border-color:var(--accent);color:var(--ink)}
.tool svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
.tool[aria-pressed="true"],
.tool[aria-checked="true"]{background:var(--accent-soft);border-color:var(--accent-line);color:var(--accent-ink)}

/* the turntable control is a state, not an action — give it a switch */
.tool--switch{padding-left:9px}
.switch-track{
  position:relative;flex:0 0 auto;display:inline-block;
  width:30px;height:17px;border-radius:999px;
  background:#cfcab6;transition:background .18s ease;
}
.switch-knob{
  position:absolute;top:2px;left:2px;width:13px;height:13px;border-radius:50%;
  background:#fff;box-shadow:0 1px 2px rgba(42,42,42,.4);
  transition:transform .18s ease;
}
.tool--switch[aria-checked="true"] .switch-track{background:var(--accent)}
.tool--switch[aria-checked="true"] .switch-knob{transform:translateX(13px)}
@media (prefers-reduced-motion:reduce){
  .switch-track,.switch-knob{transition:none}
}
.hint{margin-left:auto;font-size:11.5px;color:var(--ink-3);letter-spacing:.02em}

/* ───────── panel ───────── */
.panel{
  flex:0 0 var(--panel-w);width:var(--panel-w);
  display:flex;flex-direction:column;
  background:#fff;border-left:1px solid var(--line);
}
.panel__scroll{flex:1 1 auto;overflow-y:auto;padding:20px 24px 6px}
.panel__scroll::-webkit-scrollbar{width:9px}
.panel__scroll::-webkit-scrollbar-thumb{background:var(--line);border-radius:9px;border:3px solid #fff}

.group{padding-bottom:16px;margin-bottom:16px;border-bottom:1px solid var(--line)}
.group:last-child{border-bottom:0;margin-bottom:0}
.group__title{
  margin:0 0 3px;font-family:var(--font-display);font-size:11px;font-weight:700;
  letter-spacing:.16em;text-transform:uppercase;color:var(--ink-3);
}
.group__note{margin:0 0 10px;font-size:11.5px;color:var(--ink-3)}
.group__value{margin:9px 0 0;font-size:12.5px;font-weight:600;color:var(--ink-2)}
.group__value em{font-style:normal;font-weight:500;color:var(--ink-3)}

/* character chips */
.chips--character{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.chip{
  position:relative;
  display:flex;flex-direction:column;align-items:center;gap:5px;
  padding:9px 6px 7px;cursor:pointer;
  border:1px solid var(--line);border-radius:12px;background:#fff;
  font-family:var(--font-display);font-size:11.5px;font-weight:600;color:var(--ink-2);
  transition:border-color .16s,background .16s,transform .16s;
}
.chip:hover{border-color:var(--accent-line);transform:translateY(-1px)}
.chip[aria-pressed="true"]{border-color:var(--accent);background:var(--accent-soft);color:var(--accent-ink)}
.chip svg{width:100%;height:34px;display:block}
.chip svg path{fill:currentColor;opacity:.82}

/* font chips */
.chips--font{display:grid;grid-template-columns:repeat(4,1fr);gap:7px;margin-top:10px}
.chip--font{padding:8px 4px 6px;gap:1px;min-height:54px;justify-content:center}
.chip__sample{line-height:1.25;color:var(--ink);white-space:nowrap}
.chip[aria-pressed="true"] .chip__sample{color:var(--accent-ink)}
.chip__caption{font-size:10px;letter-spacing:.12em;text-transform:uppercase;color:var(--ink-3)}
.chip[aria-pressed="true"] .chip__caption{color:var(--accent)}

/* swatches */
.swatches{display:flex;flex-wrap:wrap;gap:8px}
.swatch{
  width:34px;height:34px;padding:0;cursor:pointer;
  border-radius:50%;border:1px solid rgba(42,42,42,.14);
  background:var(--sw);
  box-shadow:inset 0 -6px 12px -8px rgba(0,0,0,.5);
  transition:transform .16s,box-shadow .16s;
  position:relative;
}
.swatch:hover{transform:translateY(-2px)}
.swatch[aria-pressed="true"]{
  box-shadow:0 0 0 2px #fff, 0 0 0 4px var(--accent), inset 0 -6px 12px -8px rgba(0,0,0,.5);
}

/* name field */
.field{position:relative;display:flex;align-items:center}
.field input{
  width:100%;font-family:var(--font-display);font-size:15px;font-weight:600;color:var(--ink);
  padding:10px 58px 10px 13px;
  border:1px solid var(--line);border-radius:11px;background:var(--paper);
  transition:border-color .16s,background .16s;
}
.field input:focus{outline:none;border-color:var(--accent);background:#fff}
.field input::placeholder{color:var(--ink-3);font-weight:500}
.field__count{position:absolute;right:13px;font-size:11px;color:var(--ink-3);pointer-events:none;font-variant-numeric:tabular-nums}

/* summary — on desktop the breakdown sits above the total and never closes;
   on mobile it folds away behind the total to keep the sticky bar short. */
.summary{flex:0 0 auto;border-top:1px solid var(--line);padding:15px 24px 18px;background:var(--paper-2)}
.summary__box{display:flex;flex-direction:column}
.summary__box::details-content{order:1;display:block}   /* newer engines */
.summary__list{list-style:none;order:1;margin:0 0 10px;padding:0;display:grid;gap:4px}
.summary__list li{display:flex;justify-content:space-between;gap:12px;font-size:12.5px;color:var(--ink-2)}
.summary__list li span:last-child{color:var(--ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}
.summary__total{
  order:2;display:flex;align-items:baseline;gap:10px;
  padding-top:10px;border-top:1px solid var(--line);
  font-family:var(--font-display);font-size:12px;letter-spacing:.14em;text-transform:uppercase;color:var(--ink-3);font-weight:700;
  list-style:none;cursor:default;pointer-events:none;
}
.summary__total::-webkit-details-marker{display:none}
.summary__caption{flex:0 0 auto}
.summary__total strong{margin-left:auto;font-size:26px;font-weight:700;letter-spacing:-.01em;text-transform:none;color:var(--ink);font-variant-numeric:tabular-nums}
.summary__toggle{display:none;align-items:center;gap:4px;font-size:10.5px;letter-spacing:.08em;color:var(--ink-3)}
.summary__toggle svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round;transition:transform .2s ease}
.cta{
  width:100%;margin-top:12px;padding:12px;cursor:pointer;
  font-family:var(--font-display);font-size:14px;font-weight:700;letter-spacing:.01em;color:#fff;
  background:var(--accent);border:0;border-radius:11px;
  transition:background .16s,transform .16s;
}
.cta:hover{background:var(--accent-ink);transform:translateY(-1px)}
.summary__fine{margin:7px 0 0;text-align:center;font-size:10.5px;color:var(--ink-3)}

/* dialog */
.dialog{
  border:0;border-radius:var(--radius);padding:26px;max-width:440px;width:calc(100% - 40px);
  box-shadow:0 30px 70px -20px rgba(42,42,42,.45);color:var(--ink);background:#fff;
}
.dialog::backdrop{background:rgba(42,42,42,.42)}
.dialog h3{margin:0 0 14px;font-family:var(--font-display);font-size:17px;font-weight:700}
.dialog pre{
  margin:0;padding:14px;border-radius:10px;overflow:auto;max-height:46vh;
  background:var(--paper);border:1px solid var(--line);
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:1.55;
}
.dialog__note{font-size:12px;color:var(--ink-3);margin:12px 0 16px}

/* ───────── responsive ───────── */
@media (max-width:920px){
  body{overflow:auto}
  .app{flex-direction:column;height:auto;min-height:100vh;min-height:100svh}

  /* Pin the chair to the top so it stays in view while the options scroll
     underneath it — on a phone you need to see what the choice does. */
  .stage{
    position:sticky;top:0;z-index:5;
    height:auto;padding:10px 16px 8px;
    background:var(--paper);
    border-bottom:1px solid var(--line);
    will-change:transform;        /* own compositor layer, so sticky
                                     repositioning does not repaint the canvas */
  }
  .stage__head{gap:12px;align-items:center}
  .brand__logo{height:21px}
  .brand__sub{display:none}
  .stage__title{padding-left:12px}
  .stage__title h1{font-size:15px}

  /* Fixed slice of the screen for the viewer, the rest is for choosing.
     svh, NOT dvh: the dynamic unit changes as the URL bar collapses during
     scroll, which resized the WebGL buffer and re-framed the camera on every
     scroll frame — that was the flicker. svh is a constant. */
  .viewport{flex:0 0 auto;height:38vh;height:38svh;min-height:210px}

  /* icon-only tools keep the pinned block to one compact row */
  .stage__tools{gap:6px}
  .tool{padding:8px}
  .tool__label{display:none}
  .tool--switch{padding:6px 12px 6px 8px}
  .tool--switch .tool__label{display:inline}
  .hint{display:none}
  .panel{flex:1 1 auto;width:100%;border-left:0;border-top:1px solid var(--line)}
  .panel__scroll{overflow:visible;padding:22px 16px 8px}

  /* compact sticky bar: total + CTA only, tap the total for the breakdown */
  .summary{
    padding:10px 16px calc(12px + env(safe-area-inset-bottom));
    position:sticky;bottom:0;
    box-shadow:0 -10px 24px -18px rgba(42,42,42,.5);
  }
  .summary__total{order:0;padding-top:0;border-top:0;cursor:pointer;pointer-events:auto;-webkit-tap-highlight-color:transparent}
  .summary__box::details-content{order:2}
  .summary__total strong{font-size:24px}
  .summary__toggle{display:inline-flex;order:3;flex:0 0 auto}
  .summary__box[open] .summary__toggle svg{transform:rotate(180deg)}
  .summary__list{order:2;margin:10px 0 0;padding-top:10px;border-top:1px solid var(--line)}
  .cta{margin-top:10px;padding:14px}
  .summary__fine{display:none}
}

/* A landscape phone has no vertical room to stack a pinned viewer above the
   options, but plenty of width — so put them side by side instead. */
@media (max-width:920px) and (max-height:560px) and (orientation:landscape){
  body{overflow:hidden}
  .app{flex-direction:row;height:100vh;height:100svh}
  .stage{position:static;height:auto;border-bottom:0;padding:10px 12px 8px}
  .stage__head{display:none}
  .viewport{flex:1 1 auto;height:auto;min-height:0}
  .panel{flex:0 0 290px;width:290px;border-top:0;border-left:1px solid var(--line)}
  .panel__scroll{overflow-y:auto;padding:14px 14px 6px}
  /* vertical room is scarce here, so keep the portrait behaviour: the
     breakdown stays folded behind the total and is tapped open */
  .summary{position:static;padding:10px 14px 12px}
  .cta{margin-top:10px;padding:11px}
}
