/* ————— Brain ————— */
.wrap.brainwrap { max-width: 1280px; padding-bottom: 40px; }
.brain { margin-top: 22px; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 22px; min-height: calc(100vh - 120px); }
.brail { position: sticky; top: 14px; align-self: start; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 28px); }
.brail .bnew { width: 100%; justify-content: center; }
.btabs { display: flex; flex-direction: column; gap: 2px; }
.btabs button { text-align: left; padding: 8px 12px; border-radius: 10px; color: var(--gray); font-weight: 600; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; }
.btabs button:hover { color: var(--ink); }
.btabs button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(23,19,15,.07); }
.btabs button .n { font-family: var(--serif); color: var(--gray-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.btabs button .n.hot { color: var(--red); }
.bconvos { overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; padding-right: 2px; }
.bconvos .lbl { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--gray-2); font-weight: 800; margin: 8px 12px 4px; }
.bconvo { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; cursor: pointer; color: var(--ink); }
.bconvo:hover { background: #f6f2ec; }
.bconvo.on { background: #fff; box-shadow: 0 2px 8px rgba(23,19,15,.07); }
.bconvo .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.bconvo .x { opacity: 0; color: var(--gray-2); padding: 2px 6px; border-radius: 6px; font-size: 14px; }
.bconvo:hover .x { opacity: 1; }
.bconvo .x:hover { color: var(--red); background: var(--red-soft); }
.bmain { min-width: 0; }
.bmain .banner { background: var(--amber-soft); border: 1px solid #f0dfb6; color: var(--amber); border-radius: 14px; padding: 10px 14px; font-size: 13px; margin-bottom: 12px; }
.bmain .banner b { color: var(--ink); }

/* chat */
.bchat { display: flex; flex-direction: column; height: calc(100vh - 110px); min-height: 520px; }
.bhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 4px 4px 12px; }
.bhead h1 { font-family: var(--serif); font-weight: 500; font-size: 26px; letter-spacing: -0.01em; }
.bhead h1 em { color: var(--red); font-style: italic; }
.bhead .meta { color: var(--gray-2); font-size: 12.5px; }
.bmsgs { flex: 1; overflow: auto; padding: 8px 4px 24px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 76ch; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fffdfa; padding: 12px 16px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; font-size: 15px; line-height: 1.5; }
.msg.ai { align-self: stretch; max-width: 80ch; }
.msg.ai .body { font-size: 15.5px; line-height: 1.62; }
.msg.ai .body p { margin: 0 0 10px; }
.msg.ai .body ul, .msg.ai .body ol { margin: 0 0 10px 20px; }
.msg.ai .body li { margin: 3px 0; }
.msg.ai .body h3 { font-family: var(--serif); font-weight: 600; margin: 16px 0 6px; font-size: 19px; letter-spacing: -0.01em; }
.msg.ai .body code { background: #f3efe9; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg.ai .body pre { background: #f3efe9; padding: 12px; border-radius: 12px; overflow: auto; font-size: 13px; margin: 0 0 10px; white-space: pre-wrap; }
.msg.ai .body blockquote { border-left: 3px solid var(--hair); padding-left: 12px; color: var(--gray); margin: 0 0 10px; }
.msg.ai .body table { border-collapse: collapse; margin: 0 0 12px; font-size: 14px; }
.msg.ai .body td, .msg.ai .body th { border-bottom: 1px solid var(--hair); padding: 5px 10px 5px 0; text-align: left; vertical-align: top; }
.cite { display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .04em; padding: 1px 6px; border-radius: 999px; background: var(--red-soft); color: var(--red); vertical-align: 2px; margin: 0 1px; cursor: pointer; }
.msgfoot { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.msgfoot .pill { padding: 5px 11px; font-size: 12px; }
.msgfoot .modecap { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--gray-2); font-weight: 800; }
.status { color: var(--gray); font-size: 13px; display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: bpulse 1.2s infinite; flex: none; }
@keyframes bpulse { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
.think { color: var(--gray-2); font-size: 12.5px; font-style: italic; white-space: pre-wrap; max-height: 110px; overflow: auto; border-left: 2px solid var(--hair); padding-left: 10px; margin: 0 0 10px; }
.draftnote { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--gray-2); font-weight: 800; margin-bottom: 6px; }
.evid { margin-top: 10px; border: 1px solid var(--hair); border-radius: 14px; background: #fff; overflow: hidden; }
.evid .row { display: grid; grid-template-columns: 44px 1fr; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--hair); font-size: 13px; cursor: pointer; }
.evid .row:first-child { border-top: 0; }
.evid .row:hover { background: #fbf8f4; }
.evid .row .sid { font-weight: 800; color: var(--red); font-size: 11px; letter-spacing: .05em; padding-top: 2px; }
.evid .row .tt { font-weight: 600; }
.evid .row .mt { color: var(--gray-2); font-size: 11.5px; margin-left: 6px; font-weight: 400; }
.evid .row .sn { color: var(--gray); margin-top: 3px; line-height: 1.4; }
.evid .row.hi { background: var(--red-soft); }
.plan { font-size: 12.5px; color: var(--gray); margin-top: 6px; line-height: 1.5; }
.plan b { color: var(--ink); font-weight: 600; }
.crit { font-size: 12.5px; color: var(--gray); margin-top: 8px; background: #fbf8f4; border-radius: 10px; padding: 8px 12px; line-height: 1.5; }
.crit b { color: var(--ink); }
.draftbox { margin-top: 8px; border-left: 3px solid var(--hair); padding-left: 12px; color: var(--gray); font-size: 13.5px; }

/* composer */
.bcomp { border: 1px solid var(--hair); background: #fff; border-radius: 22px; padding: 10px 12px 8px; box-shadow: 0 14px 40px -24px rgba(23,19,15,.25); }
.bcomp textarea { width: 100%; border: 0; outline: none; resize: none; background: none; font-size: 16px; line-height: 1.5; min-height: 44px; max-height: 40vh; padding: 6px 6px 2px; font-family: var(--sans); }
.bcomp .bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.modes { display: flex; gap: 4px; flex-wrap: wrap; }
.modes button { padding: 6px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--gray); background: #f3efe9; }
.modes button:hover { color: var(--ink); }
.modes button.on { background: var(--ink); color: #fff; }
.modes button[data-mode="devil"].on { background: var(--red); }
.bcomp .send { padding: 9px 18px; }
.bcomp .hint { color: var(--gray-2); font-size: 11.5px; }

/* library / facts / review / connect */
.bsec { margin-top: 6px; }
.bsec h2 { font-family: var(--serif); font-weight: 500; font-size: 26px; letter-spacing: -0.01em; }
.bsec h2 em { color: var(--red); font-style: italic; }
.bsec .sub { color: var(--gray); font-size: 13.5px; margin-top: 4px; max-width: 64ch; }
.bstats { display: flex; gap: clamp(20px, 5vw, 56px); margin: 18px 0 6px; flex-wrap: wrap; }
.bstats .n { font-family: var(--serif); font-size: clamp(30px, 4.6vw, 44px); font-weight: 560; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bstats .l { color: var(--gray); font-size: 12px; margin-top: 5px; }
.drop { margin-top: 18px; border: 1.5px dashed #d9d0c5; border-radius: 18px; padding: 26px 20px; text-align: center; color: var(--gray); background: rgba(255,255,255,.55); transition: border-color .2s, background .2s; cursor: pointer; }
.drop.over { border-color: var(--red); background: var(--red-soft); }
.drop .big { font-family: var(--serif); font-style: italic; font-size: 22px; color: var(--ink); }
.drop small { display: block; margin-top: 6px; font-size: 12px; }
.paste { margin-top: 14px; background: #fff; border: 1px solid var(--hair); border-radius: 18px; padding: 14px; display: grid; gap: 10px; }
.paste .grid { display: grid; grid-template-columns: minmax(0, 1fr) 170px 150px; gap: 10px; }
.paste input, .paste select, .paste textarea, .factform input, .factform select { border: 1px solid var(--hair); border-radius: 12px; padding: 10px 12px; background: #fff; width: 100%; outline: none; font-size: 16px; }
.paste textarea { min-height: 120px; resize: vertical; font-family: var(--sans); font-size: 14px; }
.paste input:focus, .paste textarea:focus, .paste select:focus, .factform input:focus { border-color: var(--ink); }
.paste .acts { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.blist { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.brow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--hair); border-radius: 14px; padding: 11px 14px; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.brow:hover { transform: translateY(-1px); box-shadow: 0 8px 22px -14px rgba(23,19,15,.2); }
.brow .t { font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .m { color: var(--gray); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .caps { display: flex; gap: 6px; align-items: center; }
.toolrow { display: flex; gap: 8px; margin-top: 16px; align-items: center; flex-wrap: wrap; }
.toolrow input[type="search"], .toolrow input[type="text"] { flex: 1; min-width: 200px; border: 1px solid var(--hair); border-radius: 999px; padding: 11px 18px; background: #fff; outline: none; }
.toolrow input:focus { border-color: var(--ink); }
.factrow { background: #fff; border: 1px solid var(--hair); border-radius: 14px; padding: 12px 14px; }
.factrow .s { font-size: 14.5px; line-height: 1.45; }
.factrow .q { color: var(--gray); font-style: italic; font-size: 13px; margin-top: 4px; }
.factrow .m { color: var(--gray); font-size: 12px; margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.factrow .m a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--gray-2); cursor: pointer; }
.factrow .acts { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.factrow .acts .pill { padding: 5px 11px; font-size: 12px; }
.factrow.sup { opacity: .72; }
.factform { margin-top: 14px; background: #fff; border: 1px solid var(--hair); border-radius: 18px; padding: 14px; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 120px auto; gap: 10px; align-items: center; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; margin-top: 10px; }
.kv .k { color: var(--gray); }
.codebox { background: #f3efe9; border-radius: 12px; padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; overflow: auto; white-space: pre; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.bempty { padding: 40px 10px; text-align: center; color: var(--gray); }
.bempty .big { font-family: var(--serif); font-style: italic; font-size: 24px; color: var(--ink); margin-bottom: 6px; }
.sheet .bodytext { white-space: pre-wrap; font-size: 13.5px; line-height: 1.5; max-height: 50vh; overflow: auto; background: #faf7f2; padding: 12px; border-radius: 12px; }
.sheet .sumtext { font-size: 14.5px; line-height: 1.55; }
.connect .card2 { background: #fff; border: 1px solid var(--hair); border-radius: 16px; padding: 14px 16px; margin-top: 14px; }
.connect .card2 h3 { font-size: 14px; font-weight: 800; margin-bottom: 6px; }
.connect .card2 p, .connect .card2 li { font-size: 13.5px; color: var(--gray); line-height: 1.5; }
.connect .card2 ol { margin: 6px 0 0 18px; }
.connect .card2 b { color: var(--ink); }
.okdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--green); margin-right: 6px; vertical-align: 0; }
.okdot.bad { background: var(--red); }

@media (max-width: 860px) {
  .brain { grid-template-columns: 1fr; gap: 12px; }
  .brail { position: static; max-height: none; }
  .btabs { flex-direction: row; flex-wrap: wrap; }
  .bconvos { max-height: 26vh; }
  .bchat { height: auto; min-height: 60vh; }
  .paste .grid, .factform { grid-template-columns: 1fr; }
  .msg.ai { max-width: none; }
  .kv { grid-template-columns: 100px 1fr; }
}

/* ————— Extra Brain Cells ————— */
.lvlbtn { padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 800; color: var(--ink); background: #f3efe9; transition: background .2s, color .2s, box-shadow .2s; }
.lvlbtn:hover { background: #ece6de; }
.lvlbtn.cells { color: var(--red); }
@keyframes cellglow { 0%, 100% { box-shadow: 0 6px 18px -8px rgba(224,69,47,.55); } 50% { box-shadow: 0 8px 28px -6px rgba(224,69,47,.9); } }
.neurons { margin: 2px 0 12px; padding: 12px 14px 10px; border-radius: 16px; background: linear-gradient(180deg, #fff, #fbf6f1); border: 1px solid var(--hair); max-width: 80ch; }
.neurons .nh { display: flex; justify-content: space-between; align-items: baseline; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; font-weight: 800; color: var(--red); }
.neurons .nh .t { color: var(--gray-2); font-family: var(--serif); font-size: 16px; letter-spacing: 0; text-transform: none; font-weight: 500; font-variant-numeric: tabular-nums; }
.nrow { display: flex; align-items: flex-start; margin-top: 12px; }
.neuron { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1 1 0; min-width: 0; max-width: 120px; }
.neuron .dot { width: 22px; height: 22px; border-radius: 50%; background: #e8e1d8; border: 2px solid #fff; transition: background .3s, box-shadow .3s; }
.neuron.firing .dot { background: #f2a898; animation: fire 1.1s ease-in-out infinite; }
.neuron.lit .dot { background: var(--red); box-shadow: 0 0 0 4px rgba(224,69,47,.16), 0 0 18px rgba(224,69,47,.55); animation: none; }
@keyframes fire { 0%, 100% { box-shadow: 0 0 0 0 rgba(224,69,47,.35); transform: scale(1); } 50% { box-shadow: 0 0 0 10px rgba(224,69,47,0); transform: scale(1.14); } }
.neuron .lbl { font-size: 10.5px; color: var(--gray); text-align: center; line-height: 1.2; }
.neuron.lit .lbl { color: var(--ink); font-weight: 600; }
.synapse { flex: 1 1 0; height: 2px; background: #e8e1d8; position: relative; overflow: hidden; margin-top: 10px; min-width: 8px; }
.neuron.failed .dot { background: #fff; border-color: var(--red); box-shadow: inset 0 0 0 2px var(--red-soft); animation: none; }
.neuron.failed .lbl { color: var(--red); text-decoration: line-through; }
.synapse::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, var(--red), transparent); transform: translateX(-100%); }
.neurons.flow .synapse { background: #f3cfc7; }
.neurons.flow .synapse::after { animation: flow 1.2s linear infinite; }
@keyframes flow { to { transform: translateX(100%); } }
@media (max-width: 560px) { .neuron .lbl { font-size: 9px; } .neuron .dot { width: 16px; height: 16px; } .synapse { margin-top: 7px; } }
@media (prefers-reduced-motion: reduce) {
  .cellsbtn.on, .neuron.firing .dot, .neurons.flow .synapse::after, .status::before { animation: none; }
  .neuron.firing .dot { background: var(--red); opacity: .55; }
  .neurons.flow .synapse { background: var(--red); }
}

/* ————— Extra Brain Cells: the slider popover ————— */
.bcomp { position: relative; }
.lvlbtn.max { color: #fff; background: linear-gradient(135deg, #7a1f14, var(--red), #ff8a5c, var(--red)); background-size: 300% 100%; animation: cellglow 2.4s ease-in-out infinite, cpflow 4s linear infinite; }
.cellpop { position: absolute; right: 12px; bottom: calc(100% + 10px); width: min(360px, calc(100vw - 32px)); background: #fff; border: 1px solid var(--hair); border-radius: 16px; box-shadow: 0 18px 50px -20px rgba(23,19,15,.35); padding: 14px 16px 12px; z-index: 30; animation: rise .25s cubic-bezier(.2,.8,.25,1) both; }
.cp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.cp-title { font-weight: 800; font-size: 13.5px; }
.cp-level { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--gray); font-variant-numeric: tabular-nums; transition: color .2s; }
.cp-level.max { color: var(--red); text-shadow: 0 0 14px rgba(224,69,47,.45); }
.cp-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--gray-2); margin: 12px 0 6px; }
.cp-track { position: relative; height: 26px; border-radius: 999px; cursor: pointer; outline: none; touch-action: none; user-select: none;
  background: #efeae3 radial-gradient(circle, #d6cec3 1px, transparent 1.4px) 0 0 / 8px 8px; }
.cp-track:focus-visible { box-shadow: 0 0 0 3px rgba(224,69,47,.25); }
.cp-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--red-deep), var(--red), #ff8a5c); transition: width .18s ease; }
.cp-track.max .cp-fill { background: linear-gradient(90deg, #7a1f14, var(--red), #ff9a6a, var(--red), #7a1f14); background-size: 200% 100%; animation: cpflow 3s linear infinite; }
@keyframes cpflow { to { background-position: 200% 0; } }
.cp-particles { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 999px; pointer-events: none; opacity: 0; transition: opacity .35s; }
.cp-track.max .cp-particles { opacity: 1; }
.cp-stops { position: absolute; inset: 0; border-radius: 999px; overflow: hidden; display: flex; justify-content: space-between; align-items: center; padding: 0 9px; pointer-events: none; }
.cp-stops i { width: 4px; height: 4px; border-radius: 50%; background: rgba(23,19,15,.22); }
.cp-track.max .cp-stops { display: none; }
.cp-thumb { position: absolute; top: 50%; left: 10px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transform: translate(-50%, -50%); transition: left .18s ease, box-shadow .2s, border-color .2s; box-shadow: 0 2px 8px rgba(23,19,15,.25); }
.cp-track.max .cp-thumb { border-color: var(--red); box-shadow: 0 0 0 4px rgba(224,69,47,.2), 0 0 18px rgba(224,69,47,.65); }
.cp-hint { font-size: 12.5px; color: var(--gray); margin-top: 10px; line-height: 1.3; display: flex; align-items: baseline; gap: 6px; }
.cp-hint b { color: var(--ink); font-family: var(--serif); font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .cellpop { right: 6px; left: 6px; width: auto; } }
@media (prefers-reduced-motion: reduce) { .lvlbtn.max, .cp-track.max .cp-fill { animation: none; } }

/* ————— the edge stroke (viewport comet) ————— */
#cellFrame { position: fixed; top: 0; left: 0; pointer-events: none; z-index: 35; } /* above the composer + popover (30), under the sheet overlay (40) and toasts */
#cellFrame rect { fill: none; stroke-width: 3; }
#cellFrame .base { stroke: rgba(224,69,47,.14); }
#cellFrame .glow { stroke: rgba(224,69,47,.28); stroke-width: 11; stroke-linecap: round; stroke-dasharray: 16 84; animation: comet 7s linear infinite; }
#cellFrame .comet { stroke: var(--red); stroke-linecap: round; stroke-dasharray: 16 84; animation: comet 7s linear infinite; }
#cellFrame .head { stroke: #ffd9cc; stroke-width: 2; stroke-linecap: round; stroke-dasharray: 3 97; animation: comethead 7s linear infinite; }
#cellFrame.lvl2 .comet, #cellFrame.lvl2 .head, #cellFrame.lvl2 .glow { animation-duration: 6s; }
#cellFrame.lvl3 .comet, #cellFrame.lvl3 .head, #cellFrame.lvl3 .glow { animation-duration: 5s; }
#cellFrame.lvl4 .comet, #cellFrame.lvl4 .head, #cellFrame.lvl4 .glow { animation-duration: 4s; }
#cellFrame.lvl5 .comet { animation-duration: 3s; stroke-dasharray: 16 34 16 34; stroke-width: 4; }
#cellFrame.lvl5 .glow { animation-duration: 3s; stroke-dasharray: 16 34 16 34; stroke-width: 14; stroke: rgba(224,69,47,.38); }
#cellFrame.lvl5 .head { animation-duration: 3s; stroke-dasharray: 3 47 3 47; }
#cellFrame.lvl5 .base { stroke: rgba(224,69,47,.22); }
@keyframes comet { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -100; } }
@keyframes comethead { from { stroke-dashoffset: -13; } to { stroke-dashoffset: -113; } }
@media (prefers-reduced-motion: reduce) { #cellFrame[class] .comet, #cellFrame[class] .head, #cellFrame[class] .glow { animation: none; stroke-dasharray: none; opacity: .35; } }
