:root {
  --ink: #1d2a24;
  --ink-soft: #4c5b53;
  --paper: #fbf8ef;
  --paper-2: #f1ecdd;
  --line: #d9d2bf;
  --green: #2f6b4f;
  --green-dark: #1f4e39;
  --good: #1f7a4d;
  --bad: #b83a24;
  --gold: #e8b83a;
  --shadow: 0 18px 50px rgba(20, 28, 22, .28);
  --display: 'Fraunces', Georgia, serif;
  --ui: 'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
  --mono: 'Space Mono', ui-monospace, Menlo, monospace;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cfc9ba;
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--green-dark); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.primary {
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 13px 20px;
  font-weight: 600;
  font-size: 16px;
  transition: background .15s, transform .15s;
}
.primary:hover:not(:disabled) { background: var(--green-dark); transform: translateY(-1px); }
.primary:disabled { opacity: .72; cursor: progress; }
.primary.big { padding: 16px 30px; font-size: 18px; }

.ghost {
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
  font-size: 15px;
}
.ghost:hover { background: var(--paper-2); }

/* Title screen */
#title {
  overflow-y: auto;
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 24px clamp(16px, 7vw, 96px);
  background: linear-gradient(90deg, rgba(20, 30, 25, .55), rgba(20, 30, 25, .05) 72%);
  z-index: 20;
}
.title-card {
  max-width: 500px;
  background: var(--paper);
  border-radius: 20px;
  padding: clamp(24px, 4vw, 42px);
  box-shadow: var(--shadow);
}
.kicker {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--green);
}
h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(42px, 7vw, 68px);
  line-height: .98;
  margin: 0 0 16px;
  letter-spacing: -.02em;
}
.lede { font-size: 18px; line-height: 1.45; margin: 0 0 24px; color: var(--ink-soft); }
.status { font-weight: 600; font-size: 16px; margin: 0 0 8px; line-height: 1.4; }
.trips { display: grid; gap: 9px; }
.trip {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  text-align: left;
  padding: 12px 15px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  transition: border-color .15s, background .15s, transform .15s;
}
.trip:hover:not(:disabled) { border-color: var(--green); background: var(--paper-2); transform: translateY(-1px); }
.trip:disabled { opacity: .72; cursor: progress; }
.trip strong { font-family: var(--display); font-weight: 800; font-size: 20px; line-height: 1.15; }
.trip em { font-style: normal; font-family: var(--mono); font-size: 12.5px; color: var(--green); align-self: center; white-space: nowrap; }
.trip small { grid-column: 1 / -1; font-size: 14.5px; line-height: 1.32; color: var(--ink-soft); }
.fine { font-size: 13.5px; line-height: 1.4; color: var(--ink-soft); margin: 16px 0 0; }

/* HUD */
#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  max-width: min(340px, calc(100vw - 80px));
  z-index: 5;
}
#stopcard {
  background: var(--paper);
  border-radius: 14px;
  padding: 12px 16px 13px;
  box-shadow: 0 8px 24px rgba(20, 28, 22, .2);
}
#stopnum { font-family: var(--mono); font-size: 12px; letter-spacing: .05em; color: var(--green); text-transform: uppercase; }
#stopname { font-family: var(--display); font-weight: 800; font-size: 24px; margin: 2px 0 3px; line-height: 1.1; }
#stopprompt { margin: 0; font-size: 15px; line-height: 1.32; color: var(--ink-soft); }

#list {
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 28, 22, .18);
  font-size: 14.5px;
  min-width: 190px;
}
#list summary {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  list-style-position: inside;
}
#list summary span::before { content: '\25B8\00A0'; }
#list[open] summary span::before { content: '\25BE\00A0'; }
#list b { font-family: var(--mono); font-size: 13px; font-weight: 700; }
#listitems { list-style: none; margin: 0; padding: 0 14px 10px; }
#listitems li { padding: 3px 0 3px 22px; position: relative; color: var(--ink-soft); }
#listitems li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 7px;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--line);
  border-radius: 3px;
}
#listitems li.now { color: var(--ink); font-weight: 600; }
#listitems li.good, #listitems li.bad { text-decoration: line-through; }
#listitems li.good::before { background: var(--good); border-color: var(--good); }
#listitems li.bad::before { background: var(--bad); border-color: var(--bad); }

.iconbtn {
  position: fixed;
  bottom: 16px;
  left: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--paper);
  box-shadow: 0 6px 18px rgba(20, 28, 22, .22);
  display: grid;
  place-items: center;
  z-index: 25;
}
.iconbtn .cross { display: none; }
.iconbtn[aria-pressed="true"] .wave { display: none; }
.iconbtn[aria-pressed="true"] .cross { display: inline; }

#tip {
  position: fixed;
  left: 0;
  top: 0;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 8px;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
  white-space: nowrap;
  z-index: 6;
}

#chips {
  position: fixed;
  left: 0;
  right: 0;
  margin-inline: auto;
  width: fit-content;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 7px;
  background: rgba(251, 248, 239, .94);
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(20, 28, 22, .22);
  z-index: 5;
}
#chips::-webkit-scrollbar { display: none; }
#chips button {
  flex: none;
  min-height: 42px;
  padding: 7px 14px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.12;
  text-align: left;
}
#chips button:hover { border-color: var(--green); background: var(--paper-2); }

/* Inspect panel */
#inspect {
  position: fixed;
  right: clamp(14px, 3vw, 40px);
  top: 50%;
  transform: translateY(-50%);
  width: min(340px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  background: var(--paper);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  z-index: 11;
  animation: slide-in .24s ease-out;
}
.inspect-head p { margin: 0; }
#ibrand { font-family: var(--mono); font-size: 13px; color: var(--green); text-transform: uppercase; letter-spacing: .04em; }
#iname { font-family: var(--display); font-weight: 800; font-size: 28px; line-height: 1.08; margin: 3px 0 4px; }
#iprice { font-weight: 600; font-size: 17px; }
.turn { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-top: 15px; background: var(--paper-2); border-radius: 11px; padding: 3px; }
.turn button { border: 0; background: transparent; border-radius: 9px; padding: 9px; font-weight: 600; font-size: 15px; }
.turn button.on { background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .14); }
.hint { font-size: 13.5px; color: var(--ink-soft); margin: 10px 0 12px; line-height: 1.35; }
#astext { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 10px 0; font-size: 14.5px; }
#astext summary { cursor: pointer; font-weight: 600; }
#labeltext { margin-top: 8px; line-height: 1.42; }
#labeltext p { margin: 0 0 7px; }
#labeltext table { width: 100%; border-collapse: collapse; }
#labeltext td { padding: 3px 0; border-top: 1px solid var(--line); }
#labeltext td:last-child { text-align: right; font-weight: 600; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 15px; }

/* Result card */
#result {
  position: fixed;
  right: clamp(14px, 3vw, 40px);
  top: 14px;
  bottom: 14px;
  width: min(460px, calc(100vw - 28px));
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  z-index: 12;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-in .3s cubic-bezier(.2, .9, .3, 1.1);
}
#result.isbad { animation: slide-in .3s ease-out, nudge .42s .28s; }
.result-body { padding: 24px 24px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.result-foot { padding: 12px 24px 18px; border-top: 1px solid var(--line); display: grid; }
.verdict { display: flex; align-items: center; gap: 12px; }
.stamp {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 25px;
  font-weight: 800;
  animation: stamp .36s cubic-bezier(.2, 1.5, .4, 1);
}
#headline { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1.04; margin: 0; outline: none; }
.isgood .stamp { background: var(--good); }
.isgood #headline { color: var(--good); }
.isbad .stamp { background: var(--bad); }
.isbad #headline { color: var(--bad); }
.picked { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); margin: 10px 0 0; }
.speak {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  margin: 12px 0 0;
  padding: 7px 15px 7px 7px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 40px;
  font-weight: 600;
  font-size: 16px;
  text-align: left;
  transition: border-color .15s, background .15s;
}
.speak:hover { border-color: var(--green); background: var(--paper-2); }
.speak.on { border-color: var(--green); background: #eef5ef; }
.speak-face { display: block; width: 40px; height: 40px; flex: none; }
.speak-face svg { display: block; }
.speak-text { flex: 1; }
.speak-waves { display: flex; align-items: center; gap: 3px; height: 20px; }
.speak-waves i { display: block; width: 3px; height: 5px; background: var(--green); border-radius: 2px; opacity: .45; }
.speak-mouth { transform-box: fill-box; transform-origin: center; }
.speak.on .speak-mouth { animation: talk .34s ease-in-out infinite alternate; }
.speak.on .speak-waves i { opacity: 1; animation: wave .7s ease-in-out infinite alternate; }
.speak.on .speak-waves i:nth-child(2) { animation-delay: .15s; }
.speak.on .speak-waves i:nth-child(3) { animation-delay: .3s; }
.speak.on .speak-waves i:nth-child(4) { animation-delay: .08s; }
@keyframes talk { from { transform: scaleY(.6); } to { transform: scaleY(2.2); } }
@keyframes wave { from { height: 4px; } to { height: 19px; } }
.tell { font-weight: 600; font-size: 16.5px; line-height: 1.38; margin: 12px 0 0; padding: 11px 13px; background: var(--paper-2); border-radius: 11px; }
.why { font-size: 16.5px; line-height: 1.46; margin: 13px 0 0; }
.better { margin: 14px 0 0; padding-left: 13px; border-left: 3px solid var(--good); }
.better h3 { margin: 0 0 5px; font-size: 15.5px; line-height: 1.3; font-weight: 600; color: var(--good); }
.better ul { list-style: none; margin: 0; padding: 0; }
.better li { font-size: 15px; line-height: 1.38; padding: 3px 0; }
.better strong { display: block; font-weight: 600; }
.better span { color: var(--ink-soft); }
.studies {
  margin-top: 17px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  padding: 13px 15px;
}
.notes { background: var(--paper-2); margin-top: 11px; }
.notes li { border-top-color: var(--line); }
.notes .finding { color: var(--ink); }
.aside { font-size: 14.5px; line-height: 1.4; margin: 12px 0 2px; color: var(--ink-soft); }
.studies h3 { margin: 0 0 6px; font-family: var(--mono); font-size: 13px; letter-spacing: .05em; text-transform: uppercase; color: var(--green); }
.studies ul, .allsources ul { list-style: none; margin: 0; padding: 0; }
.studies li { padding: 9px 0; border-top: 1px solid var(--paper-2); }
.studies li:first-child { border-top: 0; padding-top: 3px; }
.studies a, .allsources a { font-weight: 600; font-size: 15px; line-height: 1.28; }
.studies .src { display: block; font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.studies .finding { display: block; font-size: 14.5px; line-height: 1.38; margin-top: 4px; }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 13; }
#confetti i {
  position: absolute;
  top: -14px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}

/* Receipt */
#receipt {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  background: rgba(20, 30, 25, .55);
  padding: 28px 16px 40px;
  z-index: 15;
}
.paper {
  width: min(500px, 100%);
  margin: 0 auto;
  background: #fffdf6;
  padding: 26px 24px;
  font-family: var(--mono);
  box-shadow: var(--shadow);
  border-radius: 4px;
  animation: print .7s cubic-bezier(.2, .8, .3, 1);
}
.paper header { text-align: center; border-bottom: 2px dashed var(--line); padding-bottom: 12px; }
.store { font-weight: 700; font-size: 17px; margin: 0; }
.thanks { font-size: 13.5px; margin: 3px 0 0; color: var(--ink-soft); }
.score { text-align: center; padding: 18px 0 14px; }
.score strong { display: block; font-family: var(--display); font-size: 60px; line-height: 1; color: var(--green); }
.score span { display: block; font-family: var(--ui); font-size: 16.5px; margin-top: 7px; line-height: 1.35; }
#lines { width: 100%; border-collapse: collapse; font-size: 13.5px; border-top: 2px dashed var(--line); }
#lines td { padding: 7px 0; vertical-align: top; line-height: 1.26; }
#lines td.mark { width: 22px; font-weight: 700; }
#lines td.price { text-align: right; padding-left: 10px; white-space: nowrap; }
#lines tr.good .mark { color: var(--good); }
#lines tr.bad .mark { color: var(--bad); }
#lines small { display: block; color: var(--ink-soft); font-size: 12px; }
.total { display: flex; justify-content: space-between; font-weight: 700; font-size: 16px; border-top: 2px dashed var(--line); padding-top: 11px; margin: 7px 0 0; }
.allsources { margin-top: 16px; font-family: var(--ui); font-size: 15px; border-top: 1px solid var(--line); padding-top: 11px; }
.allsources summary { cursor: pointer; font-weight: 600; }
.allsources li { padding: 8px 0; border-bottom: 1px solid var(--paper-2); }
.allsources .src { display: block; font-size: 13px; color: var(--ink-soft); margin-top: 1px; }
.paper .fine { font-family: var(--ui); }

.noscript { position: fixed; inset: auto 0 40%; text-align: center; font-size: 18px; }

@keyframes slide-in { from { opacity: 0; translate: 18px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes stamp { from { transform: scale(2.1) rotate(-14deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes nudge { 0%, 100% { translate: 0 0; } 25% { translate: -7px 0; } 60% { translate: 5px 0; } }
@keyframes print { from { transform: translateY(-46px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fall { to { transform: translateY(105vh) rotate(560deg); } }

/* Narrow screens: panels become bottom sheets over the top half showing the model. */
@media (max-width: 760px) {
  .iconbtn { top: 14px; right: 14px; bottom: auto; left: auto; }
  body.holding #hud { display: none; }
  #inspect {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    transform: none;
    border-radius: 18px 18px 0 0;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    max-height: 48dvh;
  }
  #iname { font-size: 22px; }
  .turn { margin-top: 9px; }
  .hint { display: none; }
  #astext { margin-top: 9px; }
  #inspect .actions { flex-direction: row; margin-top: 10px; }
  #inspect .actions button { flex: 1; padding: 12px 8px; font-size: 15px; }
  #result { left: 0; right: 0; bottom: 0; top: 22dvh; width: 100%; border-radius: 18px 18px 0 0; }
  .result-body { padding: 18px 16px 10px; }
  .result-foot { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); }
  #headline { font-size: 29px; }
  #stopname { font-size: 20px; }
  #stopprompt { font-size: 14.5px; }
  #stopcard { padding: 9px 12px; }
  #list { display: none; }
  #title { align-items: flex-end; background: linear-gradient(0deg, rgba(20, 30, 25, .6), rgba(20, 30, 25, 0) 70%); }
  .lede { font-size: 16px; margin-bottom: 14px; }
  .title-card { padding: 20px; }
  h1 { font-size: 38px; margin-bottom: 9px; }
  .trip { padding: 9px 13px; }
  .trip strong { font-size: 18px; }
  .trip small { font-size: 13.5px; }
}

@media (max-height: 560px) and (min-width: 761px) {
  #list { display: none; }
  .hint { display: none; }
}

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