:root {
  --ground: #F2F5F6;
  --surface: #FFFFFF;
  --ink: #141529;
  --ink-2: #4A4E66;
  --ink-3: #6B7088;
  --line: #DCE2E6;
  --ghost: #4ECDC4;
  --ghost-deep: #1F8F88;
  --user-bg: #141529;
  --user-ink: #F4F7FF;
  --focus: #1F8F88;
  --danger: #B3261E;
  --oil: #141529;
  --gas: #D98A1E;
  --water: #2378C8;
  --s4: #1F8F88;
  --shadow: 0 1px 2px rgba(20, 21, 41, .06), 0 8px 24px -12px rgba(20, 21, 41, .18);
  --radius: 18px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-pop: cubic-bezier(.22, 1, .36, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0D0E1A;
    --surface: #171932;
    --ink: #EEF0FA;
    --ink-2: #B9BDD3;
    --ink-3: #8F94AE;
    --line: #2A2D4A;
    --user-bg: #4ECDC4;
    --user-ink: #0D0E1A;
    --focus: #4ECDC4;
    --danger: #FF8A80;
    --oil: #E9ECF8;
    --gas: #F2B25B;
    --water: #5AA7F0;
    --s4: #4ECDC4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 10px; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.app[data-view="boot"] main { visibility: hidden; }

/* ---------- bar ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  position: relative; z-index: 3;
}
.brand { display: flex; align-items: center; gap: 10px; }
.wordmark svg { height: 14px; width: auto; display: block; fill: var(--ink); shape-rendering: crispEdges; }
.bar-actions { display: flex; align-items: center; gap: 6px; position: relative; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px 0 10px;
  border: 0; border-radius: 999px;
  background: var(--ink); color: var(--ground);
  font-size: 14px; font-weight: 600;
  transition: transform .2s var(--ease-out), background-color .2s;
}
.pill .ic { width: 18px; height: 18px; }
.pill:hover { background: var(--ghost-deep); color: #fff; }
.pill:active { transform: scale(.96); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink-2);
  transition: background-color .2s, color .2s, transform .2s var(--ease-out);
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }

.menu {
  position: absolute; right: 0; top: 46px;
  min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: pop .22s var(--ease-out);
}
.menu button {
  display: block; width: 100%; text-align: left; min-height: 48px;
  padding: 12px 12px; border: 0; border-radius: 9px; background: none; font-size: 15px;
}
.menu button:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.menu-who { margin: 4px 12px 6px; font-size: 13px; color: var(--ink-3); }
#forget { color: var(--danger); margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0 0 9px 9px; }

/* ---------- ghost ---------- */
.ghost { display: inline-block; line-height: 0; }
.ghost svg { width: 100%; height: 100%; display: block; shape-rendering: crispEdges; overflow: visible; }
.ghost--sm { width: 28px; height: 28px; }
.ghost--xs { width: 22px; height: 22px; }
.ghost--xl { width: 112px; height: 112px; }
.g-body { fill: var(--ghost); }
.g-white { fill: #fff; }
.g-pupil { fill: #141529; transition: transform .18s steps(2, end); }
.g-feet-b { opacity: 0; }
.ghost .g-feet-a, .ghost .g-feet-b { animation: feet .5s steps(1, end) infinite; }
.ghost .g-feet-b { animation-name: feet-b; }
@keyframes feet { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes feet-b { 0%, 49% { opacity: 0; } 50%, 100% { opacity: 1; } }

.hero-ghost { display: grid; justify-items: center; gap: 10px; margin-bottom: 18px; }
.hero-ghost .ghost { animation: float 3.2s ease-in-out infinite; }
.ground {
  width: 70px; height: 10px; border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  animation: ground 3.2s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes ground { 0%, 100% { transform: scaleX(1); opacity: 1; } 50% { transform: scaleX(.72); opacity: .55; } }

/* state lives on .app so every ghost on screen reacts together */
.app[data-mood="thinking"] .ghost .g-feet-a, .app[data-mood="thinking"] .ghost .g-feet-b { animation-duration: .22s; }
.app[data-mood="thinking"] .g-pupil { animation: scan 1.4s steps(1, end) infinite; }
.app[data-mood="thinking"] .hero-ghost .ghost { animation-duration: 1.2s; }
.app[data-mood="listening"] .g-pupil { transform: translate(-1px, -2px); }
.app[data-mood="sad"] .g-pupil { transform: translate(-1px, 0); }
@keyframes scan {
  0% { transform: translate(0, 0); } 25% { transform: translate(-2px, 0); }
  50% { transform: translate(-2px, -1px); } 75% { transform: translate(0, -1px); }
}

/* ---------- connect ---------- */
.connect {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px 16px 48px; overflow: auto;
}
.connect h1, .empty h1 { margin: 0; font-size: clamp(26px, 6vw, 34px); line-height: 1.15; letter-spacing: -.02em; font-weight: 750; text-wrap: balance; }
.lede { margin: 10px 0 28px; color: var(--ink-2); max-width: 32ch; text-wrap: balance; }
.connect-form { width: 100%; max-width: 380px; text-align: left; display: grid; gap: 8px; }
.connect-form label { font-weight: 650; font-size: 15px; }
.connect-form input {
  height: 52px; padding: 0 16px;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface);
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
}
.connect-form input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 18%, transparent); }
.connect-form input[aria-invalid="true"] { border-color: var(--danger); animation: shake .4s var(--ease-out); }
.hint { margin: 0 0 6px; font-size: 14px; color: var(--ink-3); }
.hint b { color: var(--ink-2); font-weight: 600; }
.error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 550; }
.primary {
  height: 52px; border: 0; border-radius: 14px;
  background: var(--ink); color: var(--ground); font-weight: 650; font-size: 16px;
  transition: transform .2s var(--ease-out), background-color .2s, opacity .2s;
}
.primary:hover { background: var(--ghost-deep); color: #fff; }
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .6; cursor: progress; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }

.byline-bar { display: flex; justify-content: center; padding: 2px 16px calc(8px + env(safe-area-inset-bottom)); }
.byline {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px;
  color: var(--ink-3); font-size: 14px; text-decoration: none;
  opacity: .85; transition: opacity .2s;
}
.byline:hover { opacity: 1; }
.byline img { display: block; height: 28px; width: auto; }
.app[data-view="boot"] .byline-bar { visibility: hidden; }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-rows: 1fr auto; min-height: 0; }
.thread {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 16px 24px;
  display: flex; flex-direction: column; gap: 18px;
  scroll-behavior: smooth;
}
.empty {
  margin: auto 0; padding: 24px 0;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 24px; max-width: 520px; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  padding: 10px 14px; border-radius: 999px; font-size: 14.5px; color: var(--ink-2);
  transition: border-color .2s, color .2s, transform .2s var(--ease-out);
  animation: rise .6s var(--ease-out) backwards;
}
.chip:nth-child(2) { animation-delay: .07s; }
.chip:nth-child(3) { animation-delay: .14s; }
.chip:hover { border-color: var(--ghost-deep); color: var(--ink); }
.chip:active { transform: scale(.97); }

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg--user { align-items: flex-end; }
.msg--user .bubble {
  background: var(--user-bg); color: var(--user-ink);
  padding: 10px 15px; border-radius: var(--radius) var(--radius) 6px var(--radius);
  max-width: min(85%, 560px); white-space: pre-wrap; overflow-wrap: anywhere;
  transform-origin: bottom right;
  animation: send .42s var(--ease-pop);
}
.msg--bot { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; }
.msg--bot > .ghost { margin-top: 3px; }
.bot-body { min-width: 0; display: grid; gap: 12px; }
.bot-body > * { animation: emerge .55s var(--ease-out) backwards; }
.prose { overflow-wrap: anywhere; }
.prose p { margin: 0 0 8px; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { margin: 4px 0 8px; padding-left: 20px; }
.prose strong { font-weight: 650; }
.status { color: var(--ink-3); font-size: 14.5px; min-height: 22px; display: flex; align-items: center; }
.status .dots { display: inline-flex; gap: 3px; margin-left: 6px; }
.status .dots i { width: 4px; height: 4px; background: currentColor; animation: blink 1s steps(1, end) infinite; }
.status .dots i:nth-child(2) { animation-delay: .33s; }
.status .dots i:nth-child(3) { animation-delay: .66s; }
.msg--error .prose { color: var(--danger); }

@keyframes send { from { transform: translateY(14px) scale(.9); opacity: 0; } }
@keyframes emerge { from { opacity: 0; transform: translateY(8px); filter: blur(4px); clip-path: inset(0 0 40% 0 round 12px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(-4px); } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: .2; } }

/* ---------- cards: chart + table ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 14px 10px; box-shadow: var(--shadow); min-width: 0;
}
.card h3 { margin: 0 0 2px; font-size: 15px; font-weight: 650; letter-spacing: -.005em; }
.card .sub { margin: 0 0 10px; font-size: 13px; color: var(--ink-3); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 8px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.plot { position: relative; touch-action: pan-y; }
.plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.plot .axis text { fill: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.plot .grid line { stroke: var(--line); stroke-width: 1; }
.plot .series path.line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.plot .series path.line { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.1s var(--ease-out) forwards; }
.plot .series path.area { opacity: .08; animation: fade .9s .3s var(--ease-out) backwards; }
.plot .series rect { transform-box: fill-box; transform-origin: bottom; animation: grow .7s var(--ease-out) backwards; }
.plot .cursor { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity .15s; }
.plot.active .cursor { opacity: 1; }
.tip {
  position: absolute; top: 0; pointer-events: none;
  background: var(--ink); color: var(--ground);
  border-radius: 10px; padding: 7px 10px; font-size: 12.5px; line-height: 1.45;
  box-shadow: var(--shadow); white-space: nowrap; opacity: 0;
  transform: translate(-50%, -6px); transition: opacity .15s;
  font-variant-numeric: tabular-nums;
}
.plot.active .tip { opacity: 1; }
.tip b { display: block; font-weight: 650; margin-bottom: 2px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.pie { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 2px 0 6px; }
.pie svg { flex: none; width: 168px; height: 168px; overflow: visible; }
.pie .track { fill: none; stroke: var(--line); stroke-width: 26; opacity: .5; }
.pie .slice {
  fill: none; stroke-width: 26; cursor: pointer;
  transition: stroke-dasharray .9s var(--ease-out), stroke-width .25s var(--ease-out), opacity .25s;
}
.pie.picking .slice { opacity: .28; }
.pie.picking .slice.on { opacity: 1; stroke-width: 32; }
.pie-big { fill: var(--ink); font-size: 24px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.pie-small { fill: var(--ink-3); font-size: 12px; }
.pie-legend { flex: 1 1 150px; min-width: 0; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.pie-legend li {
  display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: 8px;
  min-height: 44px; padding: 7px 8px; border-radius: 10px; font-size: 13.5px; cursor: pointer;
  transition: background-color .2s, opacity .2s; animation: rise .5s var(--ease-out) backwards;
  font-variant-numeric: tabular-nums;
}
.pie-legend li:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.pie-legend i { width: 10px; height: 10px; border-radius: 3px; }
.pie-legend .n { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pie-legend .p { font-weight: 650; color: var(--ink); }
.pie-legend .v { color: var(--ink-3); min-width: 6ch; text-align: right; }
.pie.picking .pie-legend li { opacity: .45; }
.pie.picking .pie-legend li.on { opacity: 1; background: color-mix(in srgb, var(--line) 55%, transparent); }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes grow { from { transform: scaleY(0); } }
@keyframes fade { from { opacity: 0; } }

.table-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12.5px; padding: 6px 10px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px 9px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tbody tr { animation: rise .45s var(--ease-out) backwards; }

/* ---------- composer ---------- */
.composer {
  padding: 8px 12px 2px;
  background: linear-gradient(to top, var(--ground) 70%, transparent);
}
.field {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 26px;
  padding: 5px 5px 5px 16px; box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
}
.field:focus-within { border-color: var(--focus); }
.field textarea {
  flex: 1; border: 0; background: none; resize: none; outline: none;
  padding: 9px 0; max-height: 140px; line-height: 1.4; font-size: 16px;
}
.field textarea::placeholder { color: var(--ink-3); }
.send {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ink); color: var(--ground);
  transition: transform .25s var(--ease-pop), opacity .2s, background-color .2s;
}
.send:disabled { opacity: .25; transform: scale(.88); cursor: default; }
.send:not(:disabled):hover { background: var(--ghost-deep); color: #fff; }
.mic { border-radius: 50%; position: relative; }
.mic[aria-pressed="true"] { color: #fff; background: var(--ghost-deep); }
.mic[aria-pressed="true"]::before, .mic[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--ghost); animation: ring 1.4s var(--ease-out) infinite;
}
.mic[aria-pressed="true"]::after { animation-delay: .7s; }
@keyframes ring { from { transform: scale(1); opacity: .8; } to { transform: scale(1.8); opacity: 0; } }

/* ---------- install sheet ---------- */
.sheet {
  border: 0; padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  width: min(440px, 100%); margin: auto auto 0; border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 -10px 40px -10px rgba(0, 0, 0, .3);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 22px; } }
.sheet[open] { animation: sheet .4s var(--ease-out); }
.sheet::backdrop { background: rgba(13, 14, 26, .45); animation: fade .3s; }
.sheet h2 { margin: 0 0 14px; font-size: 20px; letter-spacing: -.01em; }
.sheet ol { margin: 0; padding-left: 22px; display: grid; gap: 10px; color: var(--ink-2); }
.sheet ol b { color: var(--ink); }
.sheet .ic-inline { width: 18px; height: 18px; vertical-align: -3px; }
.sheet-close { position: absolute; top: 10px; right: 10px; }
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

/* ---------- the app's own confirm (sign out, post a comment) ---------- */
.confirm-sheet h2 { margin-bottom: 8px; }
.confirm-body { color: var(--ink-2); display: grid; gap: 10px; }
.confirm-body p { margin: 0; }
.confirm-on { font-size: 14px; color: var(--ink-3); }
.confirm-body blockquote {
  margin: 0; padding: 12px 14px; max-height: 40dvh; overflow-y: auto;
  background: var(--ground); border: 1px solid var(--line); border-radius: 14px;
  color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere;
}
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.secondary {
  height: 52px; border: 1.5px solid var(--line); border-radius: 14px;
  background: transparent; color: var(--ink); font-weight: 600; font-size: 16px;
  transition: border-color .2s, transform .2s var(--ease-out);
}
.secondary:hover { border-color: var(--ink-3); }
.secondary:active { transform: scale(.98); }
.primary.danger { background: var(--danger); color: #fff; }
.primary.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }


/* ---------- offline + saved chats ---------- */
/* fixed rows, so the hidden banner never shifts the chat */
.app > .bar { grid-row: 1; } .app > .offline { grid-row: 2; } .app > main { grid-row: 3; min-height: 0; } .app > .byline-bar { grid-row: 4; }
.offline {
  margin: 0 12px 4px; padding: 9px 14px; border-radius: 12px;
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--gas) 16%, var(--surface)); color: var(--ink);
  font-size: 14px; font-weight: 550; animation: rise .35s var(--ease-out);
}
.offline-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--gas); flex: none; animation: blink 1.6s steps(1, end) infinite; }
.app[data-offline="yes"] .send { background: var(--gas); }
.saved-head { margin: 4px 0 -4px; font-size: 13px; color: var(--ink-3); }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 60dvh; overflow: auto; }
.history-list button {
  width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 0; border-radius: 12px; background: none; text-align: left; font-size: 15px; color: var(--ink);
}
.history-list button:hover, .history-list button:focus-visible { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.history-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list time { flex: none; color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.history-empty { color: var(--ink-2); padding: 8px 4px; }

/* ---------- motion: the ghost travels, wakes, thinks and reacts ---------- */
/* idle life: the hero ghost blinks every few seconds */
.hero-ghost .g-white, .hero-ghost .g-pupil { transform-box: fill-box; transform-origin: center; }
.hero-ghost .g-white { animation: blink-eye 4.6s steps(1, end) infinite; }
.hero-ghost .g-pupil { animation: blink-eye 4.6s steps(1, end) infinite; }
@keyframes blink-eye { 0%, 95% { transform: scaleY(1); } 96%, 98% { transform: scaleY(.15); } }
.app[data-mood] .hero-ghost .g-white { animation: none; }

/* the live turn: its ghost hops while it works, then does one happy jump when an answer lands */
.msg--bot.live > .ghost { animation: hop .55s var(--ease-out) infinite alternate; }
.msg--bot.landed > .ghost { animation: cheer .5s var(--ease-out); }
@keyframes hop { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes cheer { 0% { transform: translateY(0) scale(1); } 35% { transform: translateY(-7px) scale(1.12, .92); } 70% { transform: translateY(0) scale(.94, 1.06); } 100% { transform: none; } }

/* thinking text: a light pass across the word instead of a spinner */
.status { background: linear-gradient(90deg, var(--ink-3) 0 40%, var(--ink) 50%, var(--ink-3) 60% 100%) 0 0 / 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: sheen 1.6s linear infinite; }
.status .dots i { background: var(--ink-3); }
@keyframes sheen { from { background-position: 100% 0; } to { background-position: -150% 0; } }

/* cards open like a panel sliding up out of the thread */
.bot-body > .card { animation: card-in .6s var(--ease-out) backwards; transform-origin: top left; }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(.97); clip-path: inset(0 0 100% 0 round 16px); } 60% { clip-path: inset(0 0 0 0 round 16px); } }

/* send: the arrow rises when there is something to send, and launches on tap */
.send svg { transition: transform .3s var(--ease-out); }
.send:not(:disabled) svg { transform: translateY(-1px); }
.send.launch svg { animation: launch .38s var(--ease-out); }
@keyframes launch { 40% { transform: translateY(-14px); opacity: 0; } 41% { transform: translateY(12px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

/* view changes: the ghost is one object that moves between screens (View Transitions where supported) */
::view-transition-old(root) { animation: vt-out .18s var(--ease-out) both; }
::view-transition-new(root) { animation: vt-in .32s var(--ease-out) both; }
::view-transition-group(gb-ghost) { animation-duration: .55s; animation-timing-function: var(--ease-out); }
::view-transition-old(gb-ghost), ::view-transition-new(gb-ghost) { height: 100%; image-rendering: pixelated; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .plot .series path.line { stroke-dashoffset: 0; }
  .status { animation: none; color: var(--ink-3); background: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ---------- phone frame ---------- */
/* GreaseBot is a phone app. On anything wider, it keeps the iPhone's 393 × 852 format, centered on the desk,
   instead of stretching into a desktop layout it was never designed for. */
@media (min-width: 640px) and (min-height: 560px) {
  :root { --frame-w: 393px; --frame-h: min(852px, calc(100dvh - 48px)); --frame-r: 44px; --desk: #DFE6E9; }
  html { background: var(--desk); }
  body {
    min-height: 100dvh; display: grid; place-items: center;
    background:
      radial-gradient(60vmax 60vmax at 50% 38%, color-mix(in srgb, var(--ghost) 14%, transparent), transparent 70%),
      var(--desk);
  }
  .app {
    width: var(--frame-w); max-width: none; height: var(--frame-h);
    padding: 0;
    background: var(--ground);
    border-radius: var(--frame-r);
    overflow: hidden;
    transform: translateZ(0); /* anything fixed inside stays inside the phone */
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--ink) 10%, transparent),
      0 2px 4px rgba(20, 21, 41, .06),
      0 30px 70px -24px rgba(20, 21, 41, .35);
  }
  /* sheets rise from the phone's bottom edge, at the phone's width */
  .sheet {
    width: var(--frame-w);
    margin: auto auto calc((100dvh - var(--frame-h)) / 2);
    border-radius: 22px 22px var(--frame-r) var(--frame-r);
    padding-bottom: 28px;
  }
}
@media (min-width: 640px) and (min-height: 560px) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --desk: #06070E; }
}

/* ---------- opening ---------- */
/* The ghost drops in and settles with a pixel squash, its shadow answering the landing; the name types in one
   letter at a time; then the ghost flies to its place in the app (a View Transition, see leaveSplash). */
.app { position: relative; }
.splash {
  position: absolute; inset: 0; z-index: 30;
  display: grid; place-content: center; justify-items: center; gap: 26px;
  background: radial-gradient(48vmax 48vmax at 50% 44%, color-mix(in srgb, var(--ghost) 12%, var(--ground)), var(--ground) 70%);
}
/* GreaseBot stands on GreaseBook: the logo rises first, the ghost lands on it, the logo gives under the weight */
.splash-stage { display: grid; justify-items: center; gap: 10px; }
.splash-base { display: block; height: 32px; width: auto; animation: splash-rise .3s var(--ease-out) both, splash-dip .3s var(--ease-pop) .6s; }
.splash-ghost { position: relative; width: 112px; height: 112px; animation: splash-drop .72s var(--ease-pop) .2s both; }
.splash-ghost::after { /* the shadow it casts on the logo */
  content: ""; position: absolute; left: 22%; right: 22%; bottom: -9px; height: 6px; border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  animation: splash-shadow .72s var(--ease-pop) .2s both;
}
.splash-mark svg { display: block; height: 20px; width: auto; fill: var(--ink); shape-rendering: crispEdges; }
.splash-mark { animation: splash-type .45s steps(9, end) .72s both; }
@keyframes splash-rise { from { transform: translateY(10px); opacity: 0; } }
@keyframes splash-dip { 35% { transform: translateY(4px) scaleY(.92); } }
@keyframes splash-drop {
  0% { transform: translateY(-56px); opacity: 0; }
  55% { transform: translateY(0) scale(1.1, .88); opacity: 1; }
  78% { transform: translateY(-6px) scale(.97, 1.04); }
  100% { transform: none; }
}
@keyframes splash-shadow { 0% { transform: scaleX(.3); opacity: 0; } 55% { transform: scaleX(1.12); opacity: 1; } 100% { transform: none; } }
@keyframes splash-type { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.app:has(.splash) > :not(.splash) { visibility: hidden; } /* nothing half-ready peeks out behind it */
@media (prefers-reduced-motion: reduce) {
  .splash-ghost, .splash-ghost::after, .splash-mark, .splash-base { animation: none; }
}

/* ---------- demo ---------- */
/* "Watch a demo" plays a scripted morning inside the real chat (made-up data). The header says it is a demo,
   a thin teal line under it fills scene by scene, and Exit puts the user's own screen back. */
.watch {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 18px; min-height: 44px; padding: 0 16px 0 6px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink); font-size: 15px; font-weight: 600;
  transition: border-color .2s, transform .2s var(--ease-out);
}
.watch:hover { border-color: var(--ghost-deep); }
.watch:active { transform: scale(.97); }
.watch:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.watch-play { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--ghost); color: #141529; }
.watch-play .ic { width: 16px; height: 16px; fill: currentColor; stroke: none; transform: translateX(1px); }
.watch-len { color: var(--ink-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.watch--quiet { margin-top: 14px; border-color: transparent; background: transparent; }
.app[data-demo] .watch { visibility: hidden; }

.demo-tag {
  display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--ghost) 22%, transparent); color: var(--ink);
  font-size: 13px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.demo-tag span { margin-left: 4px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.pill--quiet { padding: 0 14px; }
.demo-progress {
  position: absolute; left: 16px; right: 16px; bottom: 0; height: 2px; border-radius: 2px;
  background: var(--line); overflow: hidden;
}
.demo-progress::after {
  content: ""; position: absolute; inset: 0; background: var(--ghost-deep);
  transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform .6s var(--ease-out);
}
.app[data-demo] #input { caret-color: var(--ghost-deep); }
#confirm-ok.pressed { transform: scale(.96); background: var(--ghost-deep); color: #fff; }
.app[data-demo] .wordmark { display: none; } /* room for "Demo · sample data" and Exit on a phone */

/* ---------- TinyPumper sensors ---------- */
/* The TinyPumper badge heads the card; each sensor is a status light, what and where it is, and its battery drawn
   as a battery (teal, amber under 30%, red under 15%). Square lights keep the app's pixel grammar. */
.sensors-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.sensors-head img { display: block; width: 53px; height: 32px; object-fit: contain; flex: none; overflow: hidden; color: transparent; font-size: 0; } /* a failed load keeps its box, no alt text spilling */
.sensors-head .sub { margin: 0; }
.sensor-list { list-style: none; margin: 0; padding: 0; }
.sensor-list li {
  display: grid; grid-template-columns: 8px 1fr auto 3.2em; align-items: center; gap: 0 12px;
  padding: 11px 0; border-top: 1px solid var(--line);
  animation: rise .45s var(--ease-out) backwards;
}
.sensor-light { width: 8px; height: 8px; border-radius: 2px; background: var(--ghost-deep); }
.sensor-light[data-health="stale"] { background: var(--gas); animation: blink 1.6s steps(1, end) infinite; }
.sensor-light[data-health="failing"], .sensor-light[data-health="neverReported"] { background: var(--danger); }
.sensor-what { display: grid; min-width: 0; }
.sensor-what b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sensor-what span { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sensor-what span[data-health="stale"] { color: color-mix(in srgb, var(--gas) 70%, var(--ink)); font-weight: 550; }
.sensor-what span[data-health="failing"] { color: var(--danger); font-weight: 550; }
.batt {
  position: relative; width: 24px; height: 12px; border: 1.5px solid var(--ink-3); border-radius: 3px; padding: 1.5px;
  --tone: var(--ghost-deep);
}
.batt::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 3px; border-radius: 0 1px 1px 0; background: var(--ink-3); }
.batt i { display: block; height: 100%; width: var(--b); min-width: 2px; border-radius: 1px; background: var(--tone); }
.batt[data-level="low"] { --tone: var(--gas); }
.batt[data-level="empty"] { --tone: var(--danger); border-color: var(--danger); }
.batt[data-level="empty"]::after { background: var(--danger); }
.batt-pct { font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); }
.batt-pct[data-level="empty"] { color: var(--danger); font-weight: 650; }
.batt-pct[data-level="low"] { font-weight: 650; }

/* ---------- map ---------- */
/* Where a facility or well is: Google's map of the spot, and Go there opening the phone's navigation. */
.map-frame { position: relative; margin: 2px -2px 12px; border-radius: 12px; overflow: hidden; background: color-mix(in srgb, var(--ink) 6%, var(--surface)); aspect-ratio: 4 / 3; max-height: 260px; width: calc(100% + 4px); }
.map-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.map-actions { display: flex; gap: 8px; }
.go {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  border-radius: 14px; background: var(--ink); color: var(--ground); font-weight: 650; font-size: 16px; text-decoration: none;
  transition: transform .2s var(--ease-out), background-color .2s;
}
.go .ic { width: 20px; height: 20px; }
.go:hover { background: var(--ghost-deep); color: #fff; }
.go:active { transform: scale(.98); }
.go:focus-visible, .go-alt:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.go-alt {
  display: inline-flex; align-items: center; padding: 0 16px; min-height: 48px; border-radius: 14px;
  border: 1.5px solid var(--line); color: var(--ink); font-weight: 600; text-decoration: none; background: var(--surface);
}
.go.beckon { animation: beckon 1.4s var(--ease-out) .4s 3; }
@keyframes beckon { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ghost) 70%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
@media (prefers-reduced-motion: reduce) { .go.beckon { animation: none; } }
