/* Most values below are defaults; config.js overwrites the role fonts, sizes, colours and layout vars. */
@property --fade { syntax: "<percentage>"; inherits: false; initial-value: 34%; }

:root {
  --bg: #0c0c0e;
  --text: #e9e6e1;
  --dim: #6f6c68;
  --faint: #3a3936;
  --line: #222226;
  --hint: #9fbfb4;
  --error: #d08474;
  --ui: "IBM Plex Mono", ui-monospace, Consolas, monospace; /* chrome: labels, panel */

  --f-system: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --f-buddy: "IBM Plex Serif", Georgia, serif;
  --f-user: "IBM Plex Sans", system-ui, sans-serif;
  --s-system: 14px; --s-buddy: 16px; --s-user: 15px;
  --c-system: #a9b5b3; --c-thought: #8f8a84; --c-buddy: #e9e6e1; --c-user: #f0c27a;

  --focus-dim: .42;
  --fade-base: 34%;
  --fade-end: 7%;
  --composer-top: 74vh;
  --blur-px: 7px;
  --veil-dim: .35;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.6 var(--ui); -webkit-font-smoothing: antialiased; overflow: hidden; }

.stage { position: relative; height: 100vh; max-width: 760px; margin: 0 auto; padding: 0 20px; }

/* ── History: scrolls underneath the anchored focus line ── */
.history {
  --fade: var(--fade-base);
  position: absolute; left: 20px; right: 20px; top: 0;
  height: calc(var(--composer-top) - 12px);
  overflow-y: auto; scrollbar-width: none; scroll-snap-type: y proximity;
  padding: 30vh 0 8px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade));
          mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade));
  transition: --fade 1s ease;
}
.history::-webkit-scrollbar { display: none; }

.turn { opacity: var(--focus-dim); transition: opacity .35s; scroll-snap-align: end; padding: 14px 0 10px; border-top: 1px solid #19191c; }
.turn:first-child { border-top: 0; }
.turn.focus { opacity: 1; }

.msg { display: grid; grid-template-columns: 4.5em 1fr; gap: 0 14px; padding: 4px 0; }
.msg.first { margin-top: 14px; }
.turn > .msg.first:first-child { margin-top: 0; }
.msg .who { font: 12px/1.6 var(--ui); color: var(--faint); text-align: right; padding-top: 3px; text-transform: lowercase; }
.msg .who:empty { visibility: hidden; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* System: monospaced. Not dimmed; it reads as the machine, not as an aside. */
.msg.system .body       { font: var(--s-system)/1.6 var(--f-system); color: var(--c-system); }
.msg.system.hint .body  { color: var(--hint); }
.msg.system.error .body { color: var(--error); }
.msg.system .ps         { color: var(--faint); }
.msg.system .cmd        { color: var(--text); opacity: .7; }

/* Buddy: serif. Only the inner thoughts are dimmed. */
.msg.buddy .body         { font: var(--s-buddy)/1.55 var(--f-buddy); color: var(--c-buddy); }
.msg.buddy.thought .body { color: var(--c-thought); font-style: italic; }

/* User: sans. */
.msg.user .body { font: var(--s-user)/1.55 var(--f-user); color: var(--c-user); }
.msg.user .who  { color: #6b5636; }

code { font-family: var(--f-system); font-size: .88em; background: #18181c; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.msg.buddy.tool code { color: #cfe3d6; }

/* The folder's contents: a view-only icon grid. */
.fs-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px 12px;
  margin: 18px 0 6px calc(4.5em + 14px);
}
.fs-item { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--c-system); animation: fade .5s ease both; }
.fs-item svg { width: 40px; height: 46px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.fs-item svg text { fill: currentColor; stroke: none; font: 500 8.5px var(--f-system); letter-spacing: .5px; }
.fs-item.dir svg { width: 48px; }
.fs-item figcaption { font: 12px/1.35 var(--f-system); text-align: center; overflow-wrap: break-word; color: var(--text); opacity: .85; }
.end-spacer { height: 100vh; }

/* ── Composer ── */
.composer { position: absolute; left: 20px; right: 20px; top: var(--composer-top); transition: opacity .6s; }
.composer.gone { opacity: 0; pointer-events: none; }

/* The continue prompt is the system talking: system font and colour, set apart from the user's input. */
.prompt { display: flex; align-items: center; gap: 10px; font: var(--s-system)/1.6 var(--f-system); color: var(--c-system); user-select: none; min-height: 48px; }
.prompt[hidden] { display: none; }
.prompt-caret { color: var(--faint); }
.prompt-text:empty { display: none; }
.cursor { width: .55em; height: 1.1em; background: var(--c-system); animation: blink 1.05s steps(1) infinite; }
.prompt.idle .cursor { background: var(--faint); }
.prompt.acked .cursor { opacity: 0; animation: none; }
@keyframes blink { 50% { opacity: 0; } }

.prompt-text { transition: opacity var(--ack, .3s) ease, transform var(--ack, .3s) ease, background .12s, color .12s; border-radius: 3px; }
.prompt-text.ack-invert { background: var(--c-system); color: var(--bg); }
.prompt.ack-fade .prompt-text { opacity: 0; transform: translateY(-8px); }
.echo { color: var(--text); }

/* Box: an input-field outline, like the user's composer but in the system's voice. */
.prompt[data-style="box"] { padding: 10px 16px; border: 1px solid var(--line); border-radius: 10px; }
/* Bare: a plain shell line. */
.prompt[data-style="bare"] { padding: 10px 0; }
/* Pager: reverse-video, like `more` / `less`. */
.prompt[data-style="pager"] { padding: 10px 0; }
.prompt[data-style="pager"] .prompt-caret, .prompt[data-style="pager"] .cursor { display: none; }
.prompt[data-style="pager"] .prompt-text { background: var(--c-system); color: var(--bg); padding: 0 8px; }
.prompt[data-style="pager"] .prompt-text::before { content: "-- "; }
.prompt[data-style="pager"] .prompt-text::after { content: " --"; }
.prompt[data-style="pager"] .prompt-text.ack-invert { background: transparent; color: var(--c-system); }
/* Status: a full-width bar pinned to the bottom of the window, like a tmux / vim status line. */
.prompt[data-style="status"] { position: fixed; left: 0; right: 0; bottom: 0; min-height: 0; padding: 6px 20px; background: #151518; border-top: 1px solid var(--line); font-size: 12px; }
.prompt[data-style="status"] .prompt-caret { display: none; }
.prompt[data-style="status"] .cursor { margin-left: auto; height: .9em; }
.prompt[data-style="status"].idle .cursor { visibility: hidden; }
/* Breathe: the line alone, centred, slowly breathing. */
.prompt[data-style="breathe"] { justify-content: center; padding: 10px 0; }
.prompt[data-style="breathe"] .prompt-caret, .prompt[data-style="breathe"] .cursor { display: none; }
.prompt[data-style="breathe"].asking .prompt-text { animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; } }

.input-row { display: flex; gap: 10px; }
.input-row[hidden] { display: none; }
.input {
  flex: 1; min-height: 48px; padding: 12px 16px; border: 1px solid #3a3326; border-radius: 10px;
  font: var(--s-user)/1.55 var(--f-user); color: var(--c-user); white-space: pre-wrap; overflow-wrap: anywhere;
}
.send {
  font: 500 14px var(--f-user); padding: 0 18px; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--dim); border: 1px solid var(--line); transition: all .2s;
}
.send:not(:disabled) { color: var(--bg); background: var(--c-user); border-color: var(--c-user); animation: pulse 1.6s ease-in-out infinite; }
.send:disabled { cursor: default; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(240,194,122,.12); } }

.howto { position: absolute; left: 0; right: 0; top: calc(var(--composer-top) + 80px); text-align: center; color: var(--faint); font-size: 12px; transition: opacity .6s; }
.howto.gone { opacity: 0; }

/* ── Plain chat layout, for comparison ── */
body.chat .history { -webkit-mask-image: none; mask-image: none; padding-top: 24px; height: calc(100vh - 110px); }
body.chat .composer { top: auto; bottom: 24px; }
body.chat .turn { opacity: 1; }
body.chat .howto { display: none; }

/* ── Ending ── */
body.ending .history { height: 100vh; scroll-snap-type: none; --fade: var(--fade-end); }
body.chat.ending .history { height: 100vh; }

/* The blur: masked by JS so it is partial at the top row's filenames and full from the bottom row down. */
.veil {
  position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 1.4s ease;
  -webkit-backdrop-filter: blur(var(--blur-px)); backdrop-filter: blur(var(--blur-px));
  background: rgba(12,12,14,var(--veil-dim));
}
.veil.on { opacity: 1; }

.teaser { position: fixed; inset: 0; }
.teaser[hidden] { display: none; }
.signup {
  position: absolute; left: 50%; top: 50%; transform: translateX(-50%);
  width: min(460px, calc(100% - 32px)); padding: 28px; border-radius: 14px;
  background: #121215; border: 1px solid var(--line); text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  animation: rise .9s .2s ease both;
}
.headline { margin: 0 0 6px; font-size: 18px; color: var(--text); font-weight: 500; }
.ask { margin: 0 0 18px; color: var(--dim); font-size: 13px; }
.form { display: flex; gap: 8px; }
.form[hidden] { display: none; }
.form input {
  flex: 1; min-width: 0; font: 14px var(--ui); color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; outline: none;
}
.form input:focus { border-color: #4a4a52; }
.form button { font: 500 14px var(--ui); padding: 0 14px; border-radius: 8px; border: 0; background: var(--text); color: var(--bg); cursor: pointer; }
.thanks { color: var(--c-user); margin: 14px 0 0; font-size: 13px; }
.replay { margin-top: 18px; background: none; border: 0; color: var(--faint); font: 12px var(--ui); cursor: pointer; text-decoration: underline; }
.replay:hover { color: var(--dim); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ── Dev options panel (localhost / ?dev only) ── */
#devbadge {
  position: fixed; top: 10px; right: 12px; z-index: 40; font: 11px var(--ui); color: var(--faint);
  background: none; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; cursor: pointer;
}
#devbadge:hover, #devbadge.on { color: var(--dim); border-color: #33333a; }
#devpanel {
  position: fixed; top: 40px; right: 12px; z-index: 50; width: min(400px, calc(100vw - 24px)); max-height: calc(100vh - 52px);
  overflow: auto; background: rgba(20,20,23,.94); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid #2c2c32; border-radius: 12px; padding: 0 12px 12px; color: #cfcac3;
  font: 12px/1.4 var(--ui); box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
#devpanel[hidden] { display: none; }
#devpanel header { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0 6px; background: #141417; z-index: 1; }
#devpanel .dp-key { color: var(--dim); font-size: 11px; }
#devpanel h3 { font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: #75716b; margin: 14px 0 6px; }
.dp-row { display: grid; grid-template-columns: 1fr 150px 46px; gap: 8px; align-items: center; margin: 5px 0; }
.dp-row.changed label { color: var(--c-user); }
.dp-row.dp-wide { grid-template-columns: 1fr; }
.dp-row input[type=checkbox] { justify-self: start; accent-color: #f0c27a; }
.dp-preset { font-size: 13px !important; padding: 4px 6px !important; }
.dp-restore { margin: 2px 0 4px; background: none; border: 0; padding: 0; color: var(--c-user); font: 11px var(--ui); cursor: pointer; text-decoration: underline; }
.dp-restore[hidden] { display: none; }
.dp-row input[type=range] { width: 100%; accent-color: #f0c27a; }
.dp-row select, .dp-row input[type=text], #devpanel textarea {
  width: 100%; background: #0c0c0e; color: inherit; border: 1px solid #2c2c32; border-radius: 5px; font: inherit; padding: 2px 4px;
}
.dp-row input[type=color] { width: 100%; height: 22px; background: none; border: 1px solid #2c2c32; border-radius: 5px; padding: 0 2px; }
.dp-row label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dp-row output { color: #8f8a84; text-align: right; font-size: 11px; }
#devpanel textarea { height: 96px; resize: vertical; font-size: 11px; }
.dp-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.dp-btns button { font: 11px var(--ui); color: #cfcac3; background: #1d1d21; border: 1px solid #2c2c32; border-radius: 6px; padding: 4px 8px; cursor: pointer; }
.dp-btns button:hover { border-color: #44444c; }
.dp-status { color: var(--c-user); font-size: 11px; }

@media (max-width: 560px) {
  .stage { padding: 0 16px; }
  .history, .composer { left: 16px; right: 16px; }
  .msg { grid-template-columns: 1fr; }
  .msg .who { text-align: left; padding: 0; }
  .msg .who:empty { display: none; }
  .fs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-left: 0; }
  .form { flex-direction: column; }
  .form button { padding: 10px; }
}
