/* Kioku v1 arena — light mode, white/black/purple/gray, warm rounded feel */

:root {
  --bg:        #faf8f5;
  --bg-1:      #ffffff;
  --bg-2:      #f4f1ec;
  --line:      #e8e3dc;
  --border:    #ddd8d0;
  --ink:       #1a1410;
  --ink-dim:   #55504a;
  --ink-faint: #888880;
  --accent:    #6d3bbf;
  --accent-d:  #572fa0;
  --teal:      #1a8a7a;
  --violet:    #8b5fe0;
  --red:       #b83030;
  --green:     #2e7d4f;
  --mono:      'JetBrains Mono', ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans:      ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif:     'Fraunces', Georgia, serif;
  --radius:    2px;
  --tap:       40px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-d); }
button { font-family: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---- layout ---- */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
header.top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 0 20px; min-height: 56px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .name { font-family: var(--serif); font-size: 18px; font-weight: 600; color: var(--ink); }
.brand .ver {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-faint); align-self: flex-end; margin-bottom: 3px;
}
.tagline { color: var(--ink-dim); font-size: 13px; flex: 1 1 200px; min-width: 0; }
.tagline b { color: var(--ink); font-weight: 600; }

.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-left: auto; }

/* ---- API key input in navbar ---- */
.api-key-wrap { display: flex; align-items: center; gap: 0; }
.api-key-input {
  height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-right: none;
  background: var(--bg-2); color: var(--ink);
  font-family: var(--mono); font-size: 11px;
  border-radius: var(--radius) 0 0 var(--radius);
  width: 160px; outline: none;
}
.api-key-input:focus { border-color: var(--accent); }
.api-key-input::placeholder { color: var(--ink-faint); }
.api-key-save {
  height: 36px; padding: 0 12px;
  border-radius: 0 var(--radius) var(--radius) 0 !important;
  font-size: 11px !important;
}

.mind-chip {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em;
  color: var(--ink-dim); background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- buttons ---- */
.btn {
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--ink-dim);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.10em; text-transform: uppercase;
  border-radius: var(--radius);
  display: inline-flex; align-items: center; gap: 8px;
  transition: border-color .15s, background .15s, color .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { opacity: .85; }
.btn.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-d); border-color: var(--accent-d); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }

/* Researcher CTA — prominent */
.btn.researcher {
  background: var(--accent); color: #fff; border-color: var(--accent);
  font-weight: 500;
}
.btn.researcher:hover { background: var(--accent-d); border-color: var(--accent-d); color: #fff; }

main { flex: 1; display: grid; grid-template-columns: 1fr 360px; gap: 0; min-height: 0; overflow: hidden; }
.arena { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }

/* ---- chat panes ---- */
.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); flex: 1; min-height: 0; overflow: hidden; }
.pane { background: var(--bg-1); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.pane-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.10em; text-transform: uppercase;
}
.pane.kioku .pane-head { color: var(--accent); }
.pane.raw .pane-head { color: var(--ink-faint); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.pane.kioku .dot { background: var(--accent); }
.pane.raw .dot { background: var(--ink-faint); }
.pane-head .sub {
  font-weight: 400; color: var(--ink-faint); font-size: 10px;
  margin-left: auto; letter-spacing: 0.08em;
}

.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg {
  max-width: 92%; padding: 11px 14px;
  font-size: 14.5px; white-space: pre-wrap; word-wrap: break-word;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.msg.user { align-self: flex-end; background: var(--bg-2); }
.msg.bot  { align-self: flex-start; background: var(--bg-1); }
.pane.kioku .msg.bot { border-color: #ccc0e8; background: #f9f6ff; }
.msg .who {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--ink-faint); margin-bottom: 4px;
}
.msg.pack {
  background: transparent; border: 1px dashed #ccc0e8;
  color: var(--ink-dim); font-family: var(--mono); font-size: 12px;
  border-radius: var(--radius);
}
.msg.pack .who { color: var(--accent); }
.empty-hint { color: var(--ink-faint); font-size: 14px; margin: auto; text-align: center; padding: 24px; line-height: 1.7; }
.typing { color: var(--ink-faint); font-style: italic; font-size: 14px; }

/* ---- input bar ---- */
.composer {
  border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; flex-direction: column; gap: 8px; background: var(--bg-2);
  flex-shrink: 0;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; min-height: var(--tap); max-height: 140px;
  padding: 10px 14px;
  background: var(--bg-1); border: 1px solid var(--border); color: var(--ink);
  font-family: inherit; font-size: 15px; outline: none;
  border-radius: var(--radius);
}
.composer textarea:focus { border-color: var(--accent); }
.composer-opts { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--ink-dim); }
.toggle { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; min-height: 28px; }
.toggle input {
  appearance: none; width: 34px; height: 18px; border-radius: 999px;
  background: var(--border); position: relative; transition: background .15s;
}
.toggle input:checked { background: var(--accent); }
.toggle input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s;
}
.toggle input:checked::after { left: 18px; }
.probe {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--violet); background: transparent; border: 1px solid #d0c4ef; padding: 6px 12px;
  border-radius: var(--radius);
}
.probe:hover { border-color: var(--violet); }

/* ---- inspector ---- */
.inspector { border-left: 1px solid var(--border); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.insp-tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; background: var(--bg-1); }
.insp-tabs button {
  flex: 1; min-width: 58px; min-height: 42px; background: transparent; border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-faint);
}
.insp-tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.insp-body { flex: 1; overflow-y: auto; padding: 16px; }
.panel { display: none; }
.panel.active { display: block; }
.panel h3 {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .14em; color: var(--ink-faint); margin: 0 0 12px;
}

/* pipeline chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip {
  font-family: var(--mono); font-size: 11px; padding: 5px 10px;
  border: 1px solid var(--border); color: var(--ink-faint);
  background: var(--bg-1); border-radius: var(--radius); transition: all .2s;
}
.chip.lit { color: #fff; background: var(--accent); border-color: var(--accent); }
.chip.curious.lit { background: var(--violet); border-color: var(--violet); color: #fff; }
.address {
  font-family: var(--mono); font-size: 12px; color: var(--accent); background: var(--bg-1);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; word-break: break-all;
}
.address .lbl { color: var(--ink-faint); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; display: block; margin-bottom: 4px; }
.event-feed { margin-top: 14px; font-family: var(--mono); font-size: 11px; color: var(--ink-dim); display: flex; flex-direction: column; gap: 4px; }
.event-feed .ev { opacity: .85; }
.event-feed .ev b { color: var(--accent); }

/* ---- auto-conversation box ---- */
.autoconv-box {
  margin-top: 20px;
  background: var(--bg-1);
  border: 1px solid #d0c4ef;
  border-radius: var(--radius);
  padding: 14px;
}
.autoconv-label {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .14em; color: var(--accent); margin-bottom: 8px;
}
.autoconv-hint {
  font-size: 12.5px; color: var(--ink-dim); line-height: 1.5; margin: 0 0 12px;
}
.autoconv-row { margin-bottom: 10px; }
.autoconv-domain {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-2); color: var(--ink);
  font-family: inherit; font-size: 13px; outline: none;
}
.autoconv-domain:focus { border-color: var(--accent); }
.autoconv-domain::placeholder { color: var(--ink-faint); }
.autoconv-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.autoconv-start { font-size: 11px !important; }
.autoconv-status {
  margin-top: 10px; font-family: var(--mono); font-size: 11px;
  color: var(--ink-dim); min-height: 16px;
}
.autoconv-status.running { color: var(--accent); }
.autoconv-status.done { color: var(--green); }
.autoconv-status.error { color: var(--red); }

/* memory lists */
.mem-list, .ret-list, .lex-list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px; font-size: 14px;
}
.card.click { cursor: pointer; }
.card.click:hover { border-color: var(--accent); }
.card .meaning { color: var(--ink); }
.card .meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 7px; font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.tag { padding: 2px 7px; background: var(--bg-2); color: var(--ink-dim); font-family: var(--mono); font-size: 10px; border-radius: 4px; }
.tag.pref { color: var(--accent); }
.tag.semantic { color: var(--teal); }
.tag.smalltalk { color: var(--ink-faint); }
.card.tomb { opacity: .4; text-decoration: line-through; }
.lex-term { color: var(--violet); font-weight: 600; font-family: var(--mono); font-size: 12px; }

/* retention bar */
.ret-bar { height: 5px; background: var(--border); margin-top: 8px; overflow: hidden; border-radius: 3px; }
.ret-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--accent), var(--green)); }

/* substrate gauge */
.gauge { display: flex; flex-direction: column; gap: 14px; }
.gauge .big { font-size: 13px; color: var(--ink); font-family: var(--mono); }
.bar-wrap {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
}
.bar-wrap .label { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-faint); font-family: var(--mono); margin-bottom: 6px; }
.bar { height: 7px; background: var(--bg-2); overflow: hidden; border-radius: 4px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-d)); min-width: 2px; }
.bar.disk > span { background: linear-gradient(90deg, var(--teal), #1a6b5c); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px;
}
.stat .v { font-size: 20px; font-weight: 700; font-family: var(--mono); color: var(--accent); }
.stat .k { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-faint); margin-top: 2px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.25); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-back.open { display: flex; }
.modal {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 640px; width: 100%; max-height: 80vh; overflow: auto; padding: 20px;
}
.modal pre { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); white-space: pre-wrap; word-break: break-word; }
.modal .x { float: right; }

footer.bottom { text-align: center; padding: 10px; font-size: 12px; color: var(--ink-faint); border-top: 1px solid var(--border); flex-shrink: 0; }
footer .gold { color: var(--accent); }
.track-badge { display:inline-block; padding:2px 10px; border-radius:99px; background:var(--accent); color:#fff; font-size:11px; font-weight:600; letter-spacing:.04em; text-transform:uppercase; margin-left:8px; vertical-align:middle; }
.track-badge-sm { color:var(--accent); font-weight:600; }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px; font-size: 14px; z-index: 60; opacity: 0;
  transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
.muted { color: var(--ink-faint); font-size: 12px; }

/* ---- responsive ---- */
@media (max-width: 1024px) {
  main { grid-template-columns: 1fr; }
  .inspector { border-left: none; border-top: 1px solid var(--border); max-height: 46vh; }
}
@media (max-width: 640px) {
  .panes { grid-template-columns: 1fr; }
  .pane.raw { border-top: 1px solid var(--border); }
  .tagline { display: none; }
  .brand .name { font-size: 16px; }
  .api-key-input { width: 120px; }
}
