:root {
  --bg: #0b0b0d;
  --bar-bg: rgba(12, 12, 14, 0.84);
  --fg: #f2f0eb;
  --muted: rgba(242, 240, 235, 0.55);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #ffd166;
  --ok: #7bd88f;
  --danger: #ff6b6b;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--sans); }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; border: 0; background: var(--bg); }

/* Build overlay — a live view of the agent coding this hour: its commentary and the
   file it writes, streaming token by token. Covers the stage while a build runs. */
#build-overlay {
  position: fixed; left: 0; right: 0; top: 0; bottom: 110px; z-index: 8;
  display: flex; flex-direction: column; padding: 18px clamp(14px, 5vw, 60px) 12px;
  background: radial-gradient(circle at 50% 0%, #14161f, #0a0a0c 80%);
  color: var(--fg);
}
#build-overlay[hidden] { display: none; }
.bo-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bo-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(255,209,102,0.6); animation: bo-pulse 1.3s ease-out infinite; flex: none; }
@keyframes bo-pulse { 0% { box-shadow: 0 0 0 0 rgba(255,209,102,0.5); } 70% { box-shadow: 0 0 0 9px rgba(255,209,102,0); } 100% { box-shadow: 0 0 0 0 rgba(255,209,102,0); } }
.bo-head { font-size: clamp(16px, 2.4vw, 21px); font-weight: 600; letter-spacing: -0.01em; }
.bo-elapsed { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bo-prompt { font-size: 14px; line-height: 1.4; color: rgba(242,240,235,0.72); margin-bottom: 12px; max-width: 90ch; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bo-prompt::before { content: '“'; } .bo-prompt::after { content: '”'; }
.bo-stream {
  flex: 1; min-height: 0; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(0,0,0,0.35); padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  scroll-behavior: smooth;
}
.bo-waiting { color: var(--muted); }
.bo-text { color: rgba(242,240,235,0.8); white-space: pre-wrap; margin: 2px 0 8px; }
.bo-tool { color: var(--accent); font-weight: 600; margin: 10px 0 4px; }
.bo-tool::before { content: '❯ '; opacity: 0.7; }
.bo-code { white-space: pre-wrap; word-break: break-word; color: #b7c6e0; margin: 0 0 6px; }
.bo-code .cursor { display: inline-block; width: 7px; height: 1em; background: var(--accent); vertical-align: text-bottom; animation: bo-blink 1s step-end infinite; }
@keyframes bo-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .bo-dot { animation: none; } .bo-code .cursor { animation: none; } }
@media (max-width: 640px) { #build-overlay { bottom: 150px; padding-left: 12px; padding-right: 12px; } }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 16; /* above #notice (15) so the open drop-up isn't covered by it */
  background: var(--bar-bg);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  font-size: 14px; line-height: 1.3;
}
.bar-row { display: flex; align-items: center; gap: 12px; }

.caption { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.tag { font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; color: var(--accent); white-space: nowrap; }
.prompt { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Prompt lineage: a "drop-up" that previews the recent prompts on a new hour then fades
   to just the latest, and expands to the full timestamped list on tap. Overlays upward, so
   it never changes the bar height. Gives context — "site is broken" reads as a fix request
   in a chain, not a status. */
.promptstack { position: relative; flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; cursor: pointer; }
.promptstack .prompt { flex: 0 1 auto; }
.ps-hint { font-family: var(--mono); font-size: 11px; color: var(--muted); transition: transform 0.2s; flex: none; }
.promptstack[aria-expanded="true"] .ps-hint { transform: translateY(-1px) rotate(180deg); color: var(--fg); }
.ps-pop {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 14;
  display: flex; flex-direction: column; gap: 1px;
  max-height: 46vh; overflow-y: auto;
  padding: 7px; border: 1px solid var(--line); border-radius: 11px;
  background: rgba(16, 16, 20, 0.97);
  -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
  opacity: 0; transform: translateY(8px); transition: opacity 0.32s ease, transform 0.32s ease; pointer-events: none;
}
.ps-pop.show { opacity: 1; transform: none; pointer-events: auto; }
.ps-pop[hidden] { display: none; }
.ps-item { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; padding: 5px 7px; border: 0; border-radius: 7px; background: transparent; color: rgba(242, 240, 235, 0.8); font: inherit; font-size: 13px; line-height: 1.35; }
.ps-item .ps-time { flex: none; font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 2.6em; text-align: right; }
.ps-item .ps-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-pop.expanded .ps-item .ps-txt { white-space: normal; }
.ps-item.cur { color: var(--fg); background: rgba(255, 255, 255, 0.06); }
.ps-item.cur .ps-time { color: var(--accent); }
.ps-item.click { cursor: pointer; }
.ps-item.click:hover { background: rgba(255, 255, 255, 0.09); }
.ps-empty { color: var(--muted); font-size: 12px; padding: 5px 7px; }
.ps-item.failed { color: var(--muted); cursor: default; }
.ps-item.failed .ps-txt { display: flex; flex-direction: column; gap: 1px; }
.ps-item.failed .ps-ptxt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-pop.expanded .ps-item.failed .ps-ptxt { white-space: normal; }
.ps-item.failed .ps-why { font-family: var(--mono); font-size: 11px; opacity: 0.85; white-space: normal; }
@media (prefers-reduced-motion: reduce) { .ps-pop { transition: opacity 0.2s; } }

.clock { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 20px; display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.clock-label { font-family: var(--sans); font-size: 11px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }

.form { gap: 8px; }
#input {
  flex: 1; min-width: 0;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--fg); border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 15px; outline: none;
}
#input::placeholder { color: var(--muted); }
#input:focus { border-color: var(--accent); }
#input:disabled { opacity: 0.5; }
#go {
  background: var(--accent); color: #111; border: 0; border-radius: 8px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
#go:disabled { opacity: 0.35; cursor: not-allowed; }

.meta { justify-content: space-between; font-size: 12px; color: var(--muted); }
.msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Spectator reactions on the current hour — one tap, deduped, toggles. */
.reactions { display: flex; align-items: center; gap: 4px; flex: none; }
.reactions:empty { display: none; }
.react { display: inline-flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 20px; padding: 2px 8px; font: inherit; font-size: 13px; line-height: 1.4; color: var(--fg); cursor: pointer; }
.react:hover { border-color: var(--accent); }
.react.mine { background: rgba(255, 209, 102, 0.16); border-color: var(--accent); }
.react .rc { font-family: var(--mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.react.mine .rc { color: var(--accent); }
#notify.on { color: var(--ok); border-color: currentColor; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--danger); }
.links { white-space: nowrap; }
.links a { color: var(--muted); text-decoration: none; border-bottom: 1px solid transparent; }
.links a:hover { color: var(--fg); border-color: currentColor; }
.links a[hidden] { display: none; }

/* Tip-jar fuel gauge: a thin strip across the top of the bar (the tank level) plus a
   "⛽ $X · ~N builds" chip that opens the tip panel. Both redden as the pool drains. */
#fuel-bar { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: rgba(255,255,255,0.06); overflow: hidden; }
#fuel-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #59c77a, #7bd88f); transition: width 0.6s ease, background 0.6s ease; }
#fuel-bar.low #fuel-fill { background: linear-gradient(90deg, #e0a53a, var(--accent)); }
#fuel-bar.empty #fuel-fill { background: linear-gradient(90deg, #d84b4b, var(--danger)); }
#chip-in { font-variant-numeric: tabular-nums; }
#chip-in.low { color: var(--accent); }
#chip-in.empty { color: var(--danger); }
.bar[data-slot="depleted"] .tag { color: var(--danger); }
.bar[data-slot="depleted"] #countdown { color: var(--danger); }

.bar[data-slot="open"] .tag { color: var(--ok); }
.bar[data-slot="open"] #countdown { color: var(--ok); }
.bar[data-slot="building"] .tag, .bar[data-slot="screening"] .tag { animation: pulse 1.2s ease-in-out infinite; }
.bar[data-slot="held"] .tag, .bar[data-slot="capped"] .tag { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

#return-live { color: var(--accent); font-weight: 600; }
#return-live[hidden], #live[hidden] { display: none; }

/* History: a right-side drawer on desktop, a bottom sheet on phones. */
#history-panel { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.55); }
#history-panel[hidden] { display: none; }
.history {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
  background: #121215; border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slideIn 0.22s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } }
.history-head { display: flex; align-items: baseline; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.history-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.history-sub { color: var(--muted); font-size: 12px; flex: 1; }
#history-close { background: transparent; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; padding: 2px 6px; }
#history-close:hover { color: var(--fg); }
.history-grid { overflow-y: auto; padding: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start; }
.history-empty { color: var(--muted); text-align: center; padding: 40px 0; }
.hcard { background: #1a1a1e; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; color: inherit; font: inherit; display: flex; flex-direction: column; }
.hcard:hover { border-color: var(--accent); }
.hcard .thumb { position: relative; aspect-ratio: 16 / 10; background: #0b0b0d; overflow: hidden; }
.hcard .thumb iframe { position: absolute; left: 0; top: 0; width: 320%; height: 320%; transform: scale(0.3125); transform-origin: 0 0; border: 0; pointer-events: none; }
.hcard .thumb .shot { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top center; border: 0; display: block; background: #0b0b0d; }
.hcard .thumb .veil { position: absolute; inset: 0; }
.hcard .hp { margin: 0; padding: 8px 10px 3px; font-size: 12.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hcard .hd { margin: 0; padding: 0 10px 9px; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.hcard.current { outline: 1px solid var(--ok); outline-offset: -1px; }

@media (max-width: 640px) {
  .history {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 72vh;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    animation: sheetUp 0.24s ease;
  }
  @keyframes sheetUp { from { transform: translateY(100%); } }
  .history-grid { grid-template-columns: 1fr 1fr; padding-bottom: 28px; }
}

/* A full, wrapping message that sits just above the bar — used for rejections so the
   whole reason is readable (the compact status line truncates). */
#notice {
  position: fixed; left: 0; right: 0; z-index: 15;
  bottom: calc(118px + env(safe-area-inset-bottom));
  margin: 0 10px; padding: 11px 40px 11px 14px;
  background: rgba(40, 20, 22, 0.96); border: 1px solid var(--danger); border-radius: 10px;
  color: #ffdede; font-size: 14px; line-height: 1.45;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.4);
}
#notice[hidden] { display: none; }
#notice.ok { background: rgba(20, 40, 26, 0.96); border-color: var(--ok); color: #daffe4; }
#notice-close { position: absolute; top: 6px; right: 8px; background: transparent; border: 0; color: inherit; opacity: 0.6; font-size: 15px; cursor: pointer; line-height: 1; }
#notice-close:hover { opacity: 1; }
@media (max-width: 640px) { #notice { bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 13.5px; } }

#about-panel { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.72); display: grid; place-items: center; padding: 20px; }
#about-panel[hidden] { display: none; }
.about {
  max-width: 560px; background: #141417; border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 28px; line-height: 1.55; font-size: 15px;
}
.about h2 { margin: 0 0 0.5em; font-weight: 600; font-size: 20px; letter-spacing: -0.01em; }
.about p { margin: 0.6em 0; color: rgba(242, 240, 235, 0.82); }
.about p.fine { font-size: 13px; color: var(--muted); }
.about a { color: var(--accent); }
.about button {
  margin-top: 12px; background: transparent; color: var(--fg); border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer;
}

#feedback-panel { position: fixed; inset: 0; z-index: 22; background: rgba(0, 0, 0, 0.72); display: grid; place-items: center; padding: 20px; }
#feedback-panel[hidden] { display: none; }
.feedback #fb-form { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.feedback textarea, .feedback #fb-email {
  width: 100%; box-sizing: border-box; background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 8px; color: var(--fg);
  font: inherit; padding: 10px 12px; outline: none; resize: vertical;
}
.feedback textarea:focus, .feedback #fb-email:focus { border-color: var(--accent); }
.feedback .fb-check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: rgba(242, 240, 235, 0.85); cursor: pointer; }
.feedback .fb-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.feedback .fb-row { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.feedback #fb-send { margin-top: 0; background: var(--accent); color: #111; font-weight: 600; border: 0; }
.feedback #fb-send:disabled { opacity: 0.5; cursor: default; }
.feedback .fb-msg { font-size: 12.5px; color: var(--muted); }
.feedback .fb-msg.ok { color: var(--ok); }
.feedback .fb-msg.err { color: var(--danger); }

/* Tip panel: amounts labelled by what they buy the site, $5 anchored as default. */
#tip-panel { position: fixed; inset: 0; z-index: 22; background: rgba(0, 0, 0, 0.72); display: grid; place-items: center; padding: 20px; }
#tip-panel[hidden] { display: none; }
.about.tip #tip-balance, .about.tip #tip-builds { color: var(--accent); }
.tip-amounts { display: flex; gap: 10px; margin: 16px 0 6px; }
.tip-amt {
  flex: 1; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.16); border-radius: 10px;
  padding: 14px 8px; cursor: pointer; color: var(--fg); font: inherit; transition: border-color 0.15s, background 0.15s;
}
.tip-amt:hover { border-color: var(--accent); background: rgba(255,209,102,0.08); }
.tip-amt .ta-n { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.tip-amt .ta-b { font-size: 11.5px; color: var(--muted); }
.tip-amt.best { border-color: var(--accent); background: rgba(255,209,102,0.1); position: relative; }
.tip-amt.best::after { content: 'most picked'; position: absolute; top: -9px; font-size: 9.5px; letter-spacing: 0.06em; text-transform: uppercase; color: #111; background: var(--accent); padding: 1px 7px; border-radius: 20px; font-weight: 700; }
.tip-amt[disabled] { opacity: 0.45; cursor: not-allowed; }
.tip-amt.premium { border-color: rgba(123,216,143,0.5); background: rgba(123,216,143,0.08); }
.tip-amt.premium:hover { border-color: var(--ok); background: rgba(123,216,143,0.14); }
.tip-amt.premium .ta-b { color: var(--ok); }
.tip-tier { font-size: 12.5px; line-height: 1.45; color: var(--muted); background: rgba(255,255,255,0.04); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; margin: 4px 0 2px; }
.tip-tier.on { color: #daffe4; background: rgba(20,40,26,0.6); border-color: var(--ok); }
#chip-in.premium { color: var(--ok); }
.tip-to-opus { width: 100%; margin: 8px 0 2px; background: rgba(123,216,143,0.14); color: #daffe4; border: 1px solid var(--ok); border-radius: 10px; padding: 11px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.tip-to-opus:hover { background: rgba(123,216,143,0.22); }
.tip-to-opus[hidden] { display: none; }
.tip-to-opus[disabled] { opacity: 0.5; cursor: default; }
.bar[data-slot="priority"] .tag { color: var(--ok); }
.bar[data-slot="priority"] #countdown { color: var(--ok); }
.tip-custom { display: flex; align-items: center; gap: 8px; margin: 4px 0 2px; }
.tip-custom .tc-dollar { font-size: 18px; color: var(--muted); }
.tip-custom #tip-custom-amt {
  flex: 1; min-width: 0; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.16);
  border-radius: 8px; color: var(--fg); font: inherit; font-size: 16px; padding: 9px 12px; outline: none;
}
.tip-custom #tip-custom-amt:focus { border-color: var(--accent); }
.tip-custom #tip-custom-go { margin: 0; background: var(--accent); color: #111; font-weight: 600; border: 0; border-radius: 8px; padding: 9px 14px; font: inherit; cursor: pointer; white-space: nowrap; }
.tip-custom #tip-custom-go[disabled] { opacity: 0.5; cursor: default; }
.about.tip .fb-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.about.tip .fb-msg { font-size: 12.5px; color: var(--muted); }
.about.tip .fb-msg.ok { color: var(--ok); }
.about.tip .fb-msg.err { color: var(--danger); }

@media (max-width: 640px) {
  .bar { font-size: 13px; padding-left: 10px; padding-right: 10px; }
  .clock { font-size: 17px; }
  .tag { display: none; }
  .meta { flex-wrap: wrap; gap: 4px 12px; }
}
