/* MONKbot / bot.monktent.online
   A dead tube left on in an empty room: olive-grey glass, bone text,
   one sodium-amber light. Dark only. */

:root {
  --tube: #1f221e;        /* page */
  --tube-deep: #171916;   /* wells: textareas, chat log */
  --glass: #272b26;       /* raised panels */
  --seam: #3b4038;        /* borders */
  --seam-hi: #545a50;
  --bone: #dcd8c6;        /* text */
  --ash: #9a9786;         /* secondary text */
  --sodium: #e8b04b;      /* the one light */
  --sodium-dim: #a77c2c;
  --sodium-wash: rgba(232, 176, 75, 0.1);
  --ghost: #79b7b5;       /* only in the glitch offset */
  --rust: #e07a5f;
  --rust-wash: rgba(224, 122, 95, 0.12);
  --lichen: #a9c48a;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --gutter: 16px;
  --r-sm: 4px;
  --r-md: 8px;
  --focus: 0 0 0 2px var(--tube), 0 0 0 4px var(--sodium);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--tube);
  background-image:
    radial-gradient(120% 80% at 50% 0%, rgba(232, 176, 75, 0.05), transparent 60%),
    radial-gradient(140% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
  background-attachment: fixed;
  color: var(--bone);
  font: 16px/1.55 var(--sans);
  overflow-x: hidden;
}

/* Scanlines + slow roll bar. Sits over everything, never catches clicks. */
.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    rgba(0, 0, 0, 0.16) 2px 3px
  );
}
.crt::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 22vh;
  top: -22vh;
  background: linear-gradient(to bottom, transparent, rgba(220, 216, 198, 0.025), transparent);
  animation: roll 11s linear infinite;
}
@keyframes roll { to { transform: translateY(130vh); } }

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h2 { font: 600 1.25rem/1.25 var(--mono); letter-spacing: -0.01em; }
h3 { font: 600 1rem/1.3 var(--mono); }
p { margin: 0; }
a { color: var(--sodium); }
code, .mono { font-family: var(--mono); }
code { font-size: 0.9em; background: var(--tube-deep); padding: 0.05em 0.35em; border-radius: var(--r-sm); }
.muted { color: var(--ash); }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--gutter); top: -60px; z-index: 100;
  background: var(--sodium); color: var(--tube); padding: 8px 12px;
  border-radius: var(--r-sm); font-weight: 600;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: 40px;
  padding: 0.5em 1em;
  border: 1px solid var(--seam-hi);
  border-radius: var(--r-sm);
  background: var(--glass);
  color: var(--bone);
  font: 500 0.95rem/1.2 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--ash); background: #2e332c; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }
.btn-primary { background: var(--sodium); border-color: var(--sodium); color: #1c1a12; font-weight: 600; }
.btn-primary:hover { background: #f0c063; border-color: #f0c063; }
.btn-ghost { background: transparent; border-color: var(--seam); }
.btn-ghost:hover { background: var(--glass); }
.btn-danger { background: var(--rust); border-color: var(--rust); color: #1d120e; font-weight: 600; }
.btn-danger:hover { background: #ea8d74; }
.btn-danger-text { color: var(--rust); }
.btn-sm { min-height: 34px; padding: 0.3em 0.75em; font-size: 0.875rem; }
.btn-lg { min-height: 52px; padding: 0.7em 1.5em; font-size: 1.05rem; }
.btn-icon { padding: 0; width: 44px; min-height: 44px; flex: none; }
.icon { flex: none; }

/* ---------- boot ---------- */

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  color: var(--ash);
}
.dots::after {
  content: "";
  display: inline-block;
  width: 1.5em;
  text-align: left;
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

/* ---------- glitch (used on the landing title and the active name) ---------- */

.glitch { position: relative; }
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}
.glitch::before { color: var(--ghost); }
.glitch::after { color: var(--rust); }
@media (prefers-reduced-motion: no-preference) {
  .glitch::before { animation: tear-a 7s infinite steps(1, end); }
  .glitch::after { animation: tear-b 7s infinite steps(1, end); }
  .glitch { animation: jolt 7s infinite steps(1, end); }
}
@keyframes tear-a {
  0%, 91%, 100% { opacity: 0; transform: none; clip-path: inset(0 0 0 0); }
  92% { opacity: 0.8; transform: translate(-3px, 0); clip-path: inset(10% 0 60% 0); }
  93.5% { opacity: 0.8; transform: translate(4px, 0); clip-path: inset(55% 0 20% 0); }
  95% { opacity: 0; }
}
@keyframes tear-b {
  0%, 91.5%, 100% { opacity: 0; transform: none; clip-path: inset(0 0 0 0); }
  92.5% { opacity: 0.6; transform: translate(3px, 0); clip-path: inset(70% 0 5% 0); }
  94% { opacity: 0.6; transform: translate(-2px, 0); clip-path: inset(25% 0 50% 0); }
  95.5% { opacity: 0; }
}
@keyframes jolt {
  0%, 92%, 100% { transform: none; }
  93% { transform: skewX(-4deg); }
  94% { transform: translateX(1px); }
}

/* ---------- landing ---------- */

.landing {
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: 48px var(--gutter);
}
.landing-inner { max-width: 40rem; margin: 0 auto; width: 100%; }
.landing-pre { color: var(--sodium-dim); font-size: 0.85rem; margin-bottom: 1rem; }
.landing-title {
  font: 700 clamp(3.25rem, 17vw, 8rem)/0.9 var(--mono);
  letter-spacing: -0.06em;
  color: var(--sodium);
  text-shadow: 0 0 24px rgba(232, 176, 75, 0.25);
  margin-bottom: 1.5rem;
  overflow-wrap: anywhere;
}
.landing-lede { font-size: 1.125rem; max-width: 34rem; color: var(--bone); margin-bottom: 2rem; }
.landing-foot { margin-top: 1rem; font-size: 0.875rem; color: var(--ash); }
.landing .form-error { margin-bottom: 1.5rem; }

/* ---------- topbar ---------- */

.topbar {
  border-bottom: 1px solid var(--seam);
  background: rgba(31, 34, 30, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { color: var(--sodium); font-weight: 700; letter-spacing: -0.03em; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; color: var(--ash); font-size: 0.9rem; }
.avatar {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  overflow: hidden;
  display: grid; place-items: center;
  background: var(--glass);
  border: 1px solid var(--seam-hi);
  font: 600 0.8rem var(--mono);
  color: var(--sodium);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- layout ---------- */

.wrap {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--gutter) 64px;
}
.wrap:focus { outline: none; }
.block { margin-top: 48px; }
.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.block-head h2:focus { outline: none; }

/* ---------- now inhabiting ---------- */

.inhabit {
  padding: 40px 0 8px;
  border-bottom: 1px dashed var(--seam);
  padding-bottom: 28px;
}
.inhabit-label { color: var(--ash); font-size: 0.85rem; margin-bottom: 0.5rem; }
.inhabit-label::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--sodium);
  box-shadow: 0 0 8px var(--sodium);
  vertical-align: 0.05em;
}
@media (prefers-reduced-motion: no-preference) {
  .inhabit-label::before { animation: breathe 3.2s ease-in-out infinite; }
}
@keyframes breathe { 50% { opacity: 0.35; box-shadow: 0 0 2px var(--sodium); } }

.inhabit-name {
  font: 700 clamp(2.1rem, 9vw, 4.5rem)/1.02 var(--mono);
  letter-spacing: -0.045em;
  color: var(--sodium);
  text-shadow: 0 0 22px rgba(232, 176, 75, 0.22);
  overflow-wrap: anywhere;
  margin-bottom: 0.75rem;
}
.inhabit-name.is-empty { color: var(--ash); text-shadow: none; }
.inhabit-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  color: var(--bone);
}
.inhabit-swap { color: var(--ash); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

/* ---------- flash ---------- */

.flash {
  margin-top: 20px;
  padding: 10px 14px;
  border-left: 3px solid var(--lichen);
  background: rgba(169, 196, 138, 0.08);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.flash[data-kind="error"] { border-left-color: var(--rust); background: var(--rust-wash); }

/* ---------- segmented filter ---------- */

.seg {
  display: inline-flex;
  border: 1px solid var(--seam);
  border-radius: var(--r-sm);
  padding: 2px;
  margin: 0;
  gap: 2px;
}
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block;
  padding: 6px 12px;
  font: 500 0.85rem/1.2 var(--mono);
  color: var(--ash);
  border-radius: 3px;
}
.seg input:checked + span { background: var(--sodium-wash); color: var(--sodium); }
.seg input:focus-visible + span { box-shadow: var(--focus); }
.seg label:hover span { color: var(--bone); }

/* ---------- persona list ---------- */

.plist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--seam); }
.plist-empty { padding: 20px 0; }

.pitem {
  border-bottom: 1px solid var(--seam);
  padding: 14px 0;
  position: relative;
}
.pitem.is-active::before {
  content: "";
  position: absolute;
  left: calc(var(--gutter) * -1);
  top: 0; bottom: 0;
  width: 3px;
  background: var(--sodium);
}
.pitem.is-off .pitem-name { color: var(--ash); text-decoration: line-through; text-decoration-color: var(--seam-hi); }
@media (prefers-reduced-motion: no-preference) {
  .pitem.is-new { animation: arrive 1.6s ease-out; }
}
@keyframes arrive { from { background: var(--sodium-wash); } to { background: transparent; } }

.pitem-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.pitem-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--bone);
  font: 600 1.05rem/1.3 var(--sans);
  text-align: left;
  cursor: pointer;
  border-radius: var(--r-sm);
}
.pitem-toggle .icon { color: var(--ash); transition: transform 0.15s; }
.pitem-toggle[aria-expanded="true"] .icon { transform: rotate(90deg); color: var(--sodium); }
.pitem-toggle:hover .pitem-name { color: var(--sodium); }
.pitem-name { overflow-wrap: anywhere; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; padding-top: 4px; }
.badge {
  font: 500 0.75rem/1 var(--mono);
  padding: 4px 7px;
  border-radius: 3px;
  border: 1px solid var(--seam-hi);
  color: var(--ash);
  white-space: nowrap;
}
.badge-active { border-color: var(--sodium); color: var(--sodium); background: var(--sodium-wash); }
.badge-off { border-color: var(--seam); }

.pitem-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  margin: 2px 0 0 24px;
  font-size: 0.875rem;
  color: var(--ash);
}
.pitem-meta time { font-size: 0.8rem; }

.pitem-prompt {
  margin: 12px 0 0 24px;
  padding: 14px 16px;
  background: var(--tube-deep);
  border: 1px solid var(--seam);
  border-radius: var(--r-md);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  line-height: 1.6;
  max-height: 28rem;
  overflow-y: auto;
  max-width: 46rem;
}

.pitem-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0 24px; align-items: center; }
.pitem-actions.is-confirm { padding: 10px 12px; background: var(--rust-wash); border-radius: var(--r-sm); }
.confirm-q { flex-basis: 100%; overflow-wrap: anywhere; }

/* ---------- editor + chat ---------- */

.workbench { display: grid; gap: 32px; }

.field { display: grid; gap: 6px; margin-bottom: 18px; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.field label { font: 600 0.9rem/1.3 var(--mono); color: var(--bone); }
.count { font-size: 0.78rem; color: var(--ash); font-variant-numeric: tabular-nums; text-align: right; }
.count[data-state="under"] { color: var(--sodium); }
.count[data-state="over"] { color: var(--rust); }
.count[data-state="ok"] { color: var(--lichen); }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: var(--tube-deep);
  color: var(--bone);
  border: 1px solid var(--seam-hi);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font: 16px/1.5 var(--sans);
}
input::placeholder, textarea::placeholder { color: #6e6c60; }
input[type="text"]:focus-visible, input[type="number"]:focus-visible, textarea:focus-visible {
  border-color: var(--sodium);
  box-shadow: 0 0 0 1px var(--sodium);
}
#p-prompt { min-height: 18rem; resize: vertical; line-height: 1.65; }
input[type="file"] { font: 0.9rem var(--sans); color: var(--ash); max-width: 100%; }
input[type="file"]::file-selector-button {
  font: 500 0.875rem var(--sans);
  background: var(--glass);
  color: var(--bone);
  border: 1px solid var(--seam-hi);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  margin-right: 10px;
  cursor: pointer;
}
input[type="file"]:focus-visible { box-shadow: var(--focus); border-radius: var(--r-sm); }

.hint { font-size: 0.85rem; color: var(--ash); margin-top: 6px; }
.form-error {
  color: var(--rust);
  background: var(--rust-wash);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  margin: 0 0 14px;
  overflow-wrap: anywhere;
}
.editor-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* style guide */
.guide {
  border: 1px solid var(--seam);
  border-radius: var(--r-md);
  margin-bottom: 18px;
  background: var(--glass);
}
.guide summary, .admin > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--r-md);
}
.guide summary::-webkit-details-marker, .admin > summary::-webkit-details-marker { display: none; }
.guide summary { padding: 12px 14px; font: 600 0.9rem var(--mono); color: var(--sodium); }
.chev { transition: transform 0.15s; color: var(--ash); }
details[open] > summary .chev { transform: rotate(90deg); }
.guide-body { padding: 0 16px 16px; font-size: 0.925rem; }
.guide-body ul { margin: 0 0 14px; padding-left: 1.1em; display: grid; gap: 6px; }
.guide-body strong { color: var(--bone); }
.guide-body li { color: #c4c0ae; }
.guide-eg-label { color: var(--ash); margin-bottom: 6px; font-size: 0.85rem; }
.guide-eg {
  margin: 0;
  padding: 12px 14px;
  background: var(--tube-deep);
  border-radius: var(--r-sm);
  font: 0.82rem/1.6 var(--mono);
  color: var(--bone);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* test chat */
.chat {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--seam);
  border-radius: var(--r-md);
  background: var(--glass);
  padding: 14px;
  min-width: 0;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.sandbox {
  font-size: 0.85rem;
  color: var(--ash);
  padding: 8px 10px;
  border: 1px dashed var(--seam-hi);
  border-radius: var(--r-sm);
  margin-bottom: 12px;
}
.chat-log {
  flex: 1;
  min-height: 16rem;
  max-height: 32rem;
  overflow-y: auto;
  background: var(--tube-deep);
  border-radius: var(--r-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-empty { margin: auto 0; text-align: center; font-size: 0.9rem; padding: 0 8px; }
.bubble { max-width: 92%; display: grid; gap: 3px; }
.bubble-who { font-size: 0.75rem; color: var(--ash); }
.bubble-body { overflow-wrap: anywhere; line-height: 1.55; }
.bubble-user { align-self: flex-end; text-align: left; }
.bubble-user .bubble-who { text-align: right; }
.bubble-user .bubble-body {
  background: #30352e;
  padding: 8px 12px;
  border-radius: var(--r-md) var(--r-md) 2px var(--r-md);
  white-space: pre-wrap;
}
.bubble-assistant { align-self: flex-start; }
.bubble-assistant .bubble-who { color: var(--sodium-dim); }
.bubble-assistant .bubble-body { border-left: 2px solid var(--sodium); padding: 2px 0 2px 12px; }

.typing { color: var(--sodium); font-size: 0.85rem; padding: 8px 2px 0; }
@media (prefers-reduced-motion: no-preference) {
  .typing { animation: flicker 2.4s infinite; }
}
@keyframes flicker { 0%, 100% { opacity: 1; } 47% { opacity: 1; } 48% { opacity: 0.4; } 50% { opacity: 1; } 71% { opacity: 0.7; } }

.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.chat-form textarea { resize: none; min-height: 44px; max-height: 10rem; }
.chat .form-error { margin: 10px 0 0; }

/* ---------- admin ---------- */

.admin { border-top: 1px solid var(--seam); padding-top: 8px; }
.admin > summary { padding: 10px 0; }
.admin > summary h2 { display: inline; }
.admin-grid { display: grid; gap: 16px; margin-top: 12px; }
.panel {
  border: 1px solid var(--seam);
  border-radius: var(--r-md);
  padding: 16px;
  background: var(--glass);
  min-width: 0;
}
.panel h3 { margin-bottom: 10px; }
.panel > .muted { font-size: 0.9rem; margin-bottom: 14px; }
.panel .field { margin-bottom: 12px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.panel-msg { margin-top: 10px; font-size: 0.9rem; min-height: 1.2em; overflow-wrap: anywhere; }
.panel-msg[data-kind="error"] { color: var(--rust); }
.panel-msg[data-kind="ok"] { color: var(--lichen); }
.panel-msg[data-kind="muted"] { color: var(--ash); }
.rot-form { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.rot-form .panel-actions { grid-column: 1 / -1; }
.rot-form label { font-size: 0.8rem; }
.steps { margin: 0 0 14px; padding-left: 1.3em; font-size: 0.9rem; color: #c4c0ae; display: grid; gap: 4px; }

.progress { margin-top: 14px; }
.progress-bar {
  height: 3px;
  background: var(--seam);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
  margin-bottom: 8px;
}
.progress-bar::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 35%;
  background: var(--sodium);
  left: 0;
}
@media (prefers-reduced-motion: no-preference) {
  .progress-bar::after { animation: sweep 1.6s ease-in-out infinite; }
}
@media (prefers-reduced-motion: reduce) {
  .progress-bar::after { width: 100%; opacity: 0.5; }
}
@keyframes sweep { 0% { left: -35%; } 100% { left: 100%; } }
#health-elapsed { font-size: 0.8rem; }

.health {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 14px 0 0;
  font-size: 0.9rem;
}
.health dt { color: var(--ash); font-family: var(--mono); font-size: 0.8rem; padding-top: 0.15em; }
.health dd { margin: 0; overflow-wrap: anywhere; }
.health .is-ok { color: var(--lichen); font-weight: 600; }
.health .is-error { color: var(--rust); font-weight: 600; }
.health .is-warn { color: var(--sodium); }

/* ---------- wider screens ---------- */

@media (min-width: 640px) {
  :root { --gutter: 24px; }
  .confirm-q { flex-basis: auto; margin-right: 4px; }
}

@media (min-width: 960px) {
  :root { --gutter: 32px; }
  .inhabit { padding-top: 64px; }
  .workbench { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
  .chat { position: sticky; top: 72px; }
  .chat-log { min-height: 22rem; }
  .admin-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
}

/* ---------- reduced motion: stop everything ambient ---------- */

@media (prefers-reduced-motion: reduce) {
  .crt::after { display: none; }
  *, *::before, *::after { transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .dots::after { content: "..."; animation: none; }
}
