@font-face {
  font-family: "Inter";
  src: url("vendor/fonts/Inter-400-800.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: "Barlow Condensed";
  src: url("vendor/fonts/BarlowCondensed-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* Everything is sized in --u, which main.js scales with the window (1 at 1440 x 900),
   so the ball and the interface grow and shrink together. */
:root {
  color-scheme: light;
  --s: 1;
  --u: calc(var(--s) * 1px);
  --ink: #111114;
  --muted: #6b6b74;
  --faint: #9d9da7;
  --line: #e4e4ea;
  --blue: #2440d0;
  --answer: #1a2ea6;
  --red: #cf2e2e;
  --yes: #a3b2f2;
  --maybe: #cdcdd8;
  --no: #eaa9a4;
  --custom: #b7c4d8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  align-content: center;
  background: #ffffff;
  color: var(--ink);
  font: 400 calc(15 * var(--u))/1.5 Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
  overflow-x: hidden;
}
button, textarea, input { font: inherit; color: inherit; }

/* ---------- desktop: one horizontal band ----------
   Inputs, ball and result share one centerline right under the header. The canvas is
   taller than the band and centered on it, and the probabilities hang below the result. */
.app {
  --side: calc(318 * var(--u));
  --right: calc(346 * var(--u));
  --head: calc(78 * var(--u));
  --pad: calc(40 * var(--u));
  --stage-h: calc(600 * var(--u));
  display: grid;
  width: 100%;
  height: 100vh;
  height: min(100dvh, calc(1000 * var(--u)));
  padding: 0 var(--pad) calc(18 * var(--u));
  column-gap: calc(36 * var(--u));
  grid-template-columns: var(--side) minmax(0, 1fr) var(--right);
  grid-template-rows: minmax(var(--head), auto) auto minmax(0, 1fr);
}
/* Question, answer and buttons to the right of the ball. The column starts where
   the inputs start: the question's first line sits level with "Context (optional)". */
.app[data-layout="C"] {
  grid-template-areas:
    "brand  .      ."
    "ask    stage  result"
    ".      .      result";
}

.brand { grid-area: brand; align-self: center; display: flex; align-items: center; gap: calc(12 * var(--u)); }
.ask { grid-area: ask; align-self: center; }
.stage { grid-area: stage; position: relative; min-height: 0; }
.result { grid-area: result; align-self: start; text-align: center; margin-top: calc(-6 * var(--u)); min-height: 0; }
.q-block { grid-area: q; }
.verdict { position: relative; text-align: center; }
.brand, .ask, .result, .q-block, .verdict { position: relative; z-index: 1; }
.q-block > .label, .a-block > .label { display: none; }

.ball-canvas {
  position: absolute; left: 0; right: 0; top: 50%;
  height: var(--stage-h);
  transform: translateY(-50%);
  pointer-events: none;
}
.ball-canvas canvas { display: block; width: 100%; height: 100%; }
.no-webgl { position: absolute; inset: auto 0 45% 0; text-align: center; color: var(--muted); }

/* Result pieces keep their space before the first answer, so nothing jumps. */
.app:not(.asked) :is(.q-block, .a-block) { visibility: hidden; }
.app:not(.answered) .odds, .app:not(.answered) .actions, .app.rolling .actions { visibility: hidden; }

/* ---------- brand + layout switch ---------- */
.brand-mark {
  width: calc(32 * var(--u)); height: calc(32 * var(--u)); border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #55555e 0%, #16161a 42%, #050506 100%);
  display: grid; place-items: center;
  box-shadow: 0 calc(6 * var(--u)) calc(12 * var(--u)) calc(-6 * var(--u)) rgb(0 0 0 / .6);
}
.brand-mark span {
  width: calc(14 * var(--u)); height: calc(14 * var(--u)); border-radius: 50%;
  background: #fff; color: #111;
  font: 800 calc(9.5 * var(--u))/calc(14 * var(--u)) Inter, sans-serif; text-align: center;
}
.brand h1 { margin: 0; font-size: calc(16.5 * var(--u)); font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; }
.brand p { margin: calc(1 * var(--u)) 0 0; font-size: calc(12 * var(--u)); color: var(--muted); }
.brand a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 2px; }
.brand a:hover { color: var(--ink); text-decoration-color: currentColor; }


/* ---------- form ---------- */
.field-label, .label {
  display: block;
  margin: 0 0 calc(7 * var(--u));
  font-size: calc(11 * var(--u));
  font-weight: 650;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.optional, .label-aside { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--faint); font-size: calc(11.5 * var(--u)); }
textarea, .ans-body input {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: calc(13 * var(--u));
  background: #fff;
  padding: calc(11 * var(--u)) calc(13 * var(--u));
  line-height: 1.5;
  resize: vertical;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea::placeholder, .ans-body input::placeholder { color: #aeaeb7; }
textarea:hover { border-color: #d3d3db; }
textarea:focus, .ans-body input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 calc(4 * var(--u)) rgb(36 64 208 / .12); }
textarea.invalid { border-color: var(--red); box-shadow: 0 0 0 calc(4 * var(--u)) rgb(207 46 46 / .10); }
#context { height: calc(176 * var(--u)); min-height: calc(90 * var(--u)); max-height: calc(340 * var(--u)); font-size: calc(14 * var(--u)); margin-bottom: calc(20 * var(--u)); }
#contextError { margin: calc(-13 * var(--u)) 2px calc(16 * var(--u)); }
#question { resize: none; overflow: hidden; min-height: calc(48 * var(--u)); max-height: calc(160 * var(--u)); font-size: calc(15.5 * var(--u)); font-weight: 550; }

.ask-btn {
  margin-top: calc(16 * var(--u));
  width: 100%;
  height: calc(50 * var(--u));
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-size: calc(15.5 * var(--u));
  font-weight: 650;
  background: radial-gradient(130% 160% at 28% -10%, #4a4a54 0%, #16161a 42%, #050506 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .16), 0 calc(12 * var(--u)) calc(26 * var(--u)) calc(-14 * var(--u)) rgb(0 0 0 / .7);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease, opacity .2s ease;
}
.ask-btn:hover:not(:disabled) { transform: translateY(-1px); }
.ask-btn:active:not(:disabled) { transform: translateY(1px) scale(.995); }
.ask-btn:disabled { opacity: .32; cursor: default; }
.ask-btn.busy:disabled { opacity: .6; }
:focus-visible { outline: 3px solid rgb(36 64 208 / .45); outline-offset: 3px; }
textarea:focus-visible, .ans-body input:focus-visible { outline: none; }

.error { margin: calc(9 * var(--u)) 2px 0; color: var(--red); font-size: calc(12.5 * var(--u)); font-weight: 500; }
.text-btn {
  margin-top: calc(14 * var(--u));
  padding: 0;
  border: 0;
  background: none;
  font-size: calc(12.5 * var(--u));
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}
.text-btn:hover { color: var(--ink); text-decoration-color: currentColor; }
.mode-tag { color: var(--blue); font-weight: 600; }

/* ---------- result ---------- */
.r-question {
  margin: 0 auto;
  max-width: calc(620 * var(--u));
  font-size: calc(23 * var(--u));
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.014em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.r-question .qtext {
  display: inline-block;
  max-width: 100%;
  display: -webkit-inline-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.app[data-layout="C"] .q-block { margin-bottom: calc(8.5 * var(--u)); }  /* with the buttons' 19.5u, centers the answer's capitals */
.r-answer {
  margin: 0;
  font-family: "Barlow Condensed", sans-serif;
  font-weight: 700;
  font-size: calc(46 * var(--u));
  line-height: 1;
  color: var(--answer);
  text-align: center;
  letter-spacing: .01em;
}
.r-answer .line { display: block; white-space: pre; }
.a-block { min-height: calc(46 * var(--u)); }
.spinning { display: flex; justify-content: center; align-items: center; gap: calc(11 * var(--u)); margin: calc(6 * var(--u)) 0; font-size: calc(17 * var(--u)); font-weight: 650; color: var(--muted); }
.spin-word { animation: breathe 1.15s ease-in-out infinite; }
.pulse-dot { position: relative; width: calc(9 * var(--u)); height: calc(9 * var(--u)); border-radius: 50%; background: var(--blue); }
.pulse-dot::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%;
  border: 2px solid var(--blue);
  animation: ring 1.15s ease-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes ring { from { transform: scale(.6); opacity: .9; } to { transform: scale(2.6); opacity: 0; } }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: calc(8 * var(--u)); padding-top: calc(19.5 * var(--u)); }
.pill {
  display: inline-flex; align-items: center; justify-content: center;
  height: calc(40 * var(--u)); padding: 0 calc(15 * var(--u));
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink);
  font-size: calc(13.5 * var(--u)); font-weight: 600; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, transform .12s ease;
}
.pill:hover:not(:disabled) { border-color: #c9c9d2; transform: translateY(-1px); }
.pill:active:not(:disabled) { transform: translateY(1px); }
.pill.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.pill.primary:hover:not(:disabled) { background: #2a2a31; }
.pill:disabled { opacity: .45; cursor: default; }
.pill[hidden] { display: none; }

/* The probabilities follow the buttons; long lists scroll inside the space left. */
.odds {
  padding-top: calc(22 * var(--u));
  text-align: left;
  overflow-y: auto;
  scrollbar-width: thin;
}
.odds-list { list-style: none; margin: calc(2 * var(--u)) 0 calc(8 * var(--u)); padding: 0; }
.odd {
  display: grid;
  grid-template-columns: minmax(0, 1fr) calc(78 * var(--u)) calc(38 * var(--u));
  align-items: center;
  column-gap: calc(10 * var(--u));
  height: calc(20 * var(--u));
  margin: 0 calc(-7 * var(--u));
  padding: 0 calc(7 * var(--u));
  border-radius: calc(6 * var(--u));
  font-size: calc(12.5 * var(--u));
  color: #45454d;
  transition: background-color .3s ease;
}
.odd .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.odd .bar { height: calc(5 * var(--u)); border-radius: 3px; background: #f0f1f5; overflow: hidden; }
.odd .bar i { display: block; height: 100%; border-radius: 3px; transform-origin: left center; background: var(--yes); }
.odd[data-kind="maybe"] .bar i { background: var(--maybe); }
.odd[data-kind="no"] .bar i { background: var(--no); }
.odd[data-kind="custom"] .bar i { background: var(--custom); }
.odd .pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.odd.landed { background: #f2f4ff; color: var(--ink); font-weight: 700; }
.odd.landed .bar i { background: var(--blue); }
.odd.landed[data-kind="maybe"] .bar i { background: #6f6f82; }
.odd.landed[data-kind="no"] .bar i { background: var(--red); }
.odd.landed[data-kind="custom"] .bar i { background: #3b5a8a; }
.r-meta { margin: 0; font-size: calc(11 * var(--u)); color: var(--faint); }

/* ---------- flying letters ---------- */
.ghost-layer { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 40; pointer-events: none; }
.ghost { position: absolute; white-space: pre; will-change: transform, opacity, filter; }

/* ---------- dialogs ---------- */
.sheet {
  border: 0; padding: 0; border-radius: 20px;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  color: var(--ink);
  font-size: 15px;
  box-shadow: 0 40px 90px -30px rgb(0 0 0 / .45), 0 0 0 1px rgb(0 0 0 / .04);
}
.sheet::backdrop { background: rgb(14 14 20 / .32); backdrop-filter: blur(3px); }
.sheet[open] { animation: sheet-in .22s ease-out; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.sheet-head h3 { margin: 0; font-size: 17px; font-weight: 750; letter-spacing: -0.01em; }
.close { width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f2f2f5; font-size: 20px; line-height: 1; cursor: pointer; }
.close:hover { background: #e7e7ec; }
.share-preview {
  display: block; margin: 8px auto 0;
  width: auto; max-width: calc(100% - 40px);
  max-height: min(56vh, 540px);
  aspect-ratio: 1080 / 1350;
  border-radius: 12px; border: 1px solid var(--line);
  background: #fafafa;
}
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px 4px; }
.share-actions .pill { height: 40px; padding: 0 16px; font-size: 14px; }
.share-status { margin: 0; padding: 6px 20px 18px; font-size: 13px; color: var(--muted); min-height: 1.5em; }

/* Customize answers */
.answers-sheet { width: min(600px, calc(100vw - 32px)); }
.mode-tabs { display: flex; gap: 4px; margin: 6px 20px 12px; padding: 4px; border-radius: 12px; background: #f2f2f5; }
.mode-tabs button { flex: 1; height: 34px; border: 0; border-radius: 9px; background: transparent; font-size: 13.5px; font-weight: 650; color: var(--muted); cursor: pointer; }
.mode-tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.sheet-intro { margin: 0; padding: 0 20px 12px; font-size: 13px; color: var(--muted); }
.answers-tools { display: flex; align-items: center; gap: 8px; padding: 0 20px 12px; }
.answers-tools .count { margin-left: auto; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:hover:not(:disabled) { border-color: #c9c9d2; }
.chip:disabled { opacity: .45; cursor: default; }
.chip.add { background: var(--ink); border-color: var(--ink); color: #fff; }
.answers-list {
  list-style: none; margin: 0; padding: 0 20px;
  max-height: min(52vh, 540px); overflow: auto;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.ans-row {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px;
  align-items: start; padding: 9px 0; border-bottom: 1px solid #f1f1f4;
}
.ans-row:last-child { border-bottom: 0; }
.ans-row input[type="checkbox"] { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; }
.ans-body b { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 650; }
.ans-body b::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--yes); flex: none; }
.ans-row[data-kind="maybe"] .ans-body b::before { background: #b1b1c0; }
.ans-row[data-kind="no"] .ans-body b::before { background: #e08d86; }
.ans-row[data-kind="custom"] .ans-body b::before { background: #8ea3c4; }
.ans-body small { display: block; margin-top: 1px; font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.ans-row.off .ans-body { opacity: .5; }
.row-tools { display: flex; gap: 2px; }
.icon-btn {
  width: 32px; height: 30px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { background: #f2f2f5; color: var(--ink); }
.icon-btn.trash:hover { background: #fdeeee; color: var(--red); }
.icon-btn svg { width: 16px; height: 16px; }
.ans-row.editing { background: #fafbff; margin: 0 -20px; padding: 12px 20px; }
.ans-body input { padding: 8px 11px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.ans-body textarea { margin-top: 6px; padding: 8px 11px; border-radius: 10px; font-size: 13px; min-height: 58px; }
.edit-actions { display: flex; gap: 8px; margin-top: 8px; }
.edit-error { margin: 6px 0 0; font-size: 12.5px; color: var(--red); }
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 20px 16px; }
.sheet-foot .note { font-size: 12.5px; color: var(--muted); }
.sheet-foot .note button { margin: 0 0 0 4px; font-size: 12.5px; }
.sheet-foot > .text-btn { margin: 0 0 0 auto; font-size: 12.5px; }
.noul-card { margin: 0 20px 20px; padding: 18px 20px; border-radius: 14px; background: #f7f8fc; font-size: 14px; line-height: 1.55; }
.noul-card p { margin: 0 0 10px; }
.noul-card .muted { margin: 0; color: var(--muted); font-size: 13px; }
.noul-faces { display: flex; gap: 10px; }
.noul-faces span {
  display: grid; place-items: center; width: 64px; height: 56px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: linear-gradient(#3d5cf0, #1b2c9a); color: #fff;
  font: 700 15px/1 "Barlow Condensed", sans-serif; padding-top: 18px;
}

/* ---------- stacked (tablet / phone): question and answer hug the ball ---------- */
@media (max-width: 979px) {
  body { display: block; }
  .app[data-layout] {
    height: auto;
    max-width: 640px;
    margin: 0 auto;
    padding: 0 20px 40px;
    column-gap: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "brand" "q" "stage" "a" "actions" "odds" "ask";
  }
  .result, .verdict { display: contents; }
  .q-block { grid-area: q; }
  .a-block { grid-area: a; }
  .actions { grid-area: actions; }
  .odds { grid-area: odds; position: static; overflow: visible; max-height: none !important; padding-top: 22px; }
  .brand { padding: 18px 0 0; }
  .q-block { padding-top: 16px; text-align: center; }
  .app[data-layout] .q-block { margin-bottom: calc(14 * var(--u)); }
  .r-question { font-size: 22px; }
  .ball-canvas { top: -24px; bottom: -24px; height: auto; left: -20px; right: -20px; transform: none; }  /* bleed past the stage so the shadow never clips */
  .a-block { margin-top: -10px; text-align: center; }
  .r-answer, .app[data-layout] .r-answer { font-size: 46px; }
  .actions { padding-top: 16px; }
  .app:not(.asked) :is(.q-block, .a-block) { display: none; }
  .app:not(.answered) .odds { display: none; }
  .app:not(.answered) .actions { display: none; }
  .ask { padding-top: 16px; }
  #context { height: 104px; margin-bottom: 16px; }
  #contextError { margin: -9px 2px 12px; }
  .ask-btn { margin-top: 14px; }
  .app[data-layout] { padding-bottom: 20px; }
  /* The first screen fits the phone: the ball gives up height before anything scrolls. */
  .stage { height: max(220px, min(calc((min(100vw, 640px) - 40px) * 0.86), calc(100svh - 452px))); }
  /* Probabilities collapse to the top three on phones. */
  .odds.collapsed .odd:nth-child(n + 4) { display: none; }
  .odds-toggle { display: block; margin: 0 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .spin-word, .pulse-dot::after { animation-duration: 2.4s; }
  .sheet[open] { animation: none; }
}
