/* Orrin's Study — pixel UI. Every box uses stepped "pixel corners" made with box-shadows. */
:root {
  --ink: #26182b;
  --plum: #2a1d30;
  --plum-2: #34253c;
  --plum-3: #433150;
  --plum-4: #5b4166;
  --parch: #efe0bd;
  --parch-2: #e2cfa4;
  --parch-ink: #3b2a22;
  --gold: #e8b64c;
  --gold-2: #b5822f;
  --teal: #3f8a83;
  --teal-2: #2f6f6a;
  --robe: #4a5fa8;
  --robe-2: #36457e;
  --magic: #9be3ff;
  --rose: #c95a6a;
  --text: #f1e8f6;
  --muted: #b9a8c4;
  --px: 3px;
  --panel-w: 400px;
  --font: 'Pixelify Sans', 'VT323', ui-monospace, monospace;
  --mono: 'VT323', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #140e18; color: var(--text); font-family: var(--font); overflow: hidden; }
button { font-family: var(--font); cursor: pointer; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 13px; }
img.pxi { image-rendering: pixelated; display: block; }

/* pixel frame helper */
.pxbox {
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 var(--b, var(--ink)), 0 var(--px) 0 0 var(--b, var(--ink)),
    calc(-1 * var(--px)) 0 0 0 var(--b, var(--ink)), var(--px) 0 0 0 var(--b, var(--ink));
}

/* ---------------------------------------------------------------- panel */
#panel {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--panel-w); z-index: 5;
  display: flex; flex-direction: column;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 6px),
    linear-gradient(180deg, #2c1f33, #251a2b);
  border-right: 4px solid var(--ink);
  box-shadow: inset -3px 0 0 #3a2a44, 6px 0 0 rgba(0,0,0,0.25);
  transition: transform .45s cubic-bezier(.6,.05,.3,1);
}
body.collapsed #panel { transform: translateX(calc(-1 * var(--panel-w) - 4px)); }
.collapse {
  position: absolute; right: -30px; top: 50%; width: 26px; height: 56px; transform: translateY(-50%);
  background: var(--plum-3); color: var(--gold); border: 0; font-size: 14px;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), 3px 0 0 0 var(--ink);
}
body.collapsed .collapse { right: -34px; }

.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.avatar { width: 44px; height: 44px; image-rendering: pixelated; background: var(--plum-3); --b: var(--ink); }
.avatar { box-shadow: 0 -3px 0 0 var(--gold-2), 0 3px 0 0 var(--gold-2), -3px 0 0 0 var(--gold-2), 3px 0 0 0 var(--gold-2); }
.title { flex: 1; min-width: 0; }
.title h1 { margin: 0 0 3px; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; color: var(--parch); letter-spacing: .5px; text-shadow: 2px 2px 0 var(--ink); }
.model-btn {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--plum-2); color: var(--muted); border: 0; padding: 3px 8px; font-size: 13px;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
}
.model-btn:hover { color: var(--text); }
.model-btn span#model-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; background: var(--muted); display: inline-block; }
.dot.ok { background: #7bd88f; } .dot.bad { background: var(--rose); } .dot.demo { background: var(--gold); }
.head-tools { display: flex; gap: 6px; }
.head-tools .icon-btn { width: 34px; height: 34px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
  background: var(--plum-3); border: 0; color: var(--parch);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 rgba(0,0,0,.25);
  transition: transform .08s, background .15s;
}
.icon-btn:hover { background: var(--plum-4); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.on { background: var(--teal-2); }
.icon-btn.live { background: var(--rose); animation: pulse 1s steps(2) infinite; }
@keyframes pulse { 50% { background: #e07b8a; } }

/* menus */
.menu {
  position: absolute; left: 70px; top: 62px; z-index: 30; min-width: 280px; max-height: 60vh; overflow: auto;
  background: var(--plum-2); padding: 6px;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 6px 6px 0 rgba(0,0,0,.35);
}
.menu .grp { color: var(--gold); font-size: 13px; padding: 8px 8px 4px; display: flex; justify-content: space-between; gap: 10px; }
.menu .grp small { color: var(--muted); font-size: 12px; }
.menu button.item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 5px 10px 5px 18px; font-size: 14px; }
.menu button.item:hover, .menu button.item.cur { background: var(--plum-4); }
.menu button.item.cur::before { content: '✦ '; color: var(--gold); margin-left: -12px; }
.menu button.item:disabled { color: #6e5d78; cursor: default; background: none; }

/* library */
.library { padding: 0 12px; max-height: 38vh; display: flex; flex-direction: column; transition: max-height .35s ease, opacity .25s; }
.library.closed { max-height: 0; opacity: 0; overflow: hidden; }
.lib-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; color: var(--gold); font-size: 14px; }
.chip-btn {
  background: var(--plum-3); color: var(--parch); border: 0; padding: 4px 9px; font-size: 13px; text-decoration: none; display: inline-block;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
}
.chip-btn.primary { background: var(--teal-2); }
.chip-btn:hover { filter: brightness(1.15); }
.tree { overflow: auto; padding: 4px 2px 10px; background: rgba(0,0,0,.18); box-shadow: inset 0 0 0 2px #1d1422; }
.tree .row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; position: relative; }
.tree .row:hover { background: rgba(255,255,255,.05); color: var(--text); }
.tree .row.active { background: var(--plum-4); color: var(--parch); }
.tree .row.drop { outline: 2px dashed var(--gold); }
.tree .row .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree .row .more { opacity: 0; background: none; border: 0; color: var(--muted); padding: 0 4px; font-size: 14px; }
.tree .row:hover .more { opacity: 1; }
.tree .folder > .row { color: var(--parch-2); }
.tree .children { padding-left: 14px; }
.tree .empty { color: #7a6884; font-size: 13px; padding: 6px 8px; }
.tree input.rename { width: 100%; font-family: var(--font); font-size: 14px; background: var(--parch); color: var(--parch-ink); border: 0; padding: 1px 4px; }

.chat-title-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 16px 6px; border-top: 3px solid #1d1422; margin-top: 8px; }
#chat-title { font-size: 15px; color: var(--parch); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-mini { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.messages::-webkit-scrollbar, .tree::-webkit-scrollbar, .nc-body::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .tree::-webkit-scrollbar-thumb, .nc-body::-webkit-scrollbar-thumb { background: var(--plum-4); }
.msg { display: flex; gap: 8px; animation: pop .28s steps(4); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.msg .av { width: 30px; height: 30px; flex: none; image-rendering: pixelated; background: var(--plum-3); box-shadow: 0 0 0 2px var(--ink); }
.msg .card { flex: 1; min-width: 0; padding: 9px 12px; font-size: 15.5px; line-height: 1.38; word-wrap: break-word; }
.msg.user { justify-content: flex-end; }
.msg.queued .card { opacity: 0.6; }
.queued-note { font-size: 11px; opacity: 0.85; margin-top: 4px; }
.queued-note button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
.msg.user .card {
  flex: 0 1 auto; max-width: 86%; background: var(--parch); color: var(--parch-ink);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 var(--parch-2);
}
.msg.assistant .card {
  background: #3a2f55; color: var(--text);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 3px 0 0 #4a3f6a;
}
.msg.error .card { background: #4a2430; color: #ffd9de; box-shadow: 0 0 0 3px var(--ink); }
.card p { margin: 0 0 8px; } .card p:last-child { margin-bottom: 0; }
.card ul, .card ol { margin: 4px 0 8px; padding-left: 20px; }
.card h1, .card h2, .card h3 { font-size: 16px; margin: 8px 0 4px; color: var(--gold); }
.card code { font-family: var(--mono); font-size: 17px; background: rgba(0,0,0,.28); padding: 0 4px; }
.card pre { font-family: var(--mono); font-size: 16px; background: #1d1626; color: #e9e1ff; padding: 8px 10px; overflow-x: auto; box-shadow: 0 0 0 2px var(--ink); }
.card pre code { background: none; padding: 0; }
.card a { color: var(--magic); }
.card .wikilink { color: var(--gold); cursor: pointer; text-decoration: underline dotted; }
.card blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--gold-2); color: var(--muted); }
.msg .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.msg .meta .ctx { background: rgba(232,182,76,.14); color: var(--gold); padding: 1px 6px; cursor: pointer; border: 0; font-size: 12px; font-family: var(--font); }
.msg .meta .ctx.pin { color: var(--magic); background: rgba(155,227,255,.1); }
.msg .meta .mem { color: #8fe0a7; }
.msg .meta .act { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 0 3px; font-family: var(--font); }
.msg .meta .act:hover { color: var(--text); }
.cursor-blink::after { content: '▌'; color: var(--gold); animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.welcome { text-align: center; color: var(--muted); padding: 28px 18px; font-size: 15px; line-height: 1.5; }
.welcome b { color: var(--parch); font-weight: 600; }
.welcome .starters { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.welcome .starters button { background: var(--plum-2); color: var(--text); border: 0; padding: 8px 10px; text-align: left; font-size: 14px; box-shadow: 0 0 0 2px var(--ink); }
.welcome .starters button:hover { background: var(--plum-3); }

/* composer */
.composer { padding: 10px 12px 14px; background: #21172a; border-top: 3px solid #1d1422; }
.composer textarea {
  width: 100%; resize: none; max-height: 160px; border: 0; outline: 0; padding: 9px 10px;
  font-family: var(--font); font-size: 15.5px; background: var(--parch); color: var(--parch-ink);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 3px 0 0 var(--parch-2);
}
.composer textarea::placeholder { color: #9b8662; }
.composer-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.composer-row .left, .composer-row .right { display: flex; gap: 8px; align-items: center; }
.send {
  background: var(--gold); color: var(--ink); border: 0; padding: 6px 14px; font-size: 15px; font-weight: 600;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 var(--gold-2);
}
.send:active { transform: translateY(2px); }
.send.stop { background: var(--rose); color: #fff; box-shadow: 0 0 0 3px var(--ink), inset 0 -3px 0 0 #8c3442; }
.send:disabled { filter: grayscale(.6) brightness(.8); cursor: default; }

/* ---------------------------------------------------------------- stage */
#stage-wrap { position: fixed; top: 0; right: 0; bottom: 0; left: var(--panel-w); transition: left .45s cubic-bezier(.6,.05,.3,1); background: #140e18; }
body.collapsed #stage-wrap { left: 0; }
#stage { position: absolute; inset: 0; overflow: hidden; }
canvas.stage { image-rendering: pixelated; display: block; }

.plaque {
  position: absolute; top: 16px; right: 18px; z-index: 3; display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; font-size: 15px; color: var(--parch); background: #4f2f20;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 3px 0 0 #6e4430, inset 0 -3px 0 0 #3a2219;
  transition: background .3s;
}
.plaque::before, .plaque::after { content: ''; position: absolute; top: -14px; width: 3px; height: 11px; background: var(--gold-2); }
.plaque::before { left: 18px; } .plaque::after { right: 18px; }
.pl-dot { width: 9px; height: 9px; background: #7bd88f; box-shadow: 0 0 0 2px var(--ink); }
.pl-sub { color: #d9b98a; font-size: 13px; }
.plaque[data-phase="listening"] .pl-dot { background: var(--rose); animation: pulse 1s steps(2) infinite; }
.plaque[data-phase="recalling"] .pl-dot, .plaque[data-phase="context"] .pl-dot { background: var(--magic); animation: pulse .7s steps(2) infinite; }
.plaque[data-phase="thinking"] .pl-dot { background: #b48cff; animation: pulse .7s steps(2) infinite; }
.plaque[data-phase="answering"] .pl-dot { background: var(--gold); }
.plaque[data-phase="error"] { background: #5a2430; } .plaque[data-phase="error"] .pl-dot { background: var(--rose); }

.fs-btn { position: absolute; right: 18px; bottom: 18px; z-index: 3; width: 34px; height: 34px; border: 0; background: rgba(42,29,48,.7); color: var(--parch); font-size: 16px; box-shadow: 0 0 0 3px var(--ink); opacity: .55; transition: opacity .2s; }
.fs-btn:hover { opacity: 1; }

/* quote in the mantel frame */
.quote-overlay {
  position: absolute; z-index: 2; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  color: #3b2a22; font-family: var(--mono); line-height: 1.02; padding: 2px 4px; cursor: pointer; overflow: hidden;
  transition: filter .3s;
}
.quote-overlay .q-text { font-size: 15px; }
.quote-overlay .q-author { font-size: 13px; color: #7a4a2a; margin-top: 2px; }
.quote-overlay:hover { filter: brightness(1.1) drop-shadow(0 0 4px rgba(232,182,76,.6)); }

/* speech bubble above the wizard */
.bubble {
  position: absolute; z-index: 4; max-width: 380px; min-width: 120px; padding: 10px 14px; pointer-events: auto;
  background: #fbf3df; color: #2e2028; font-family: var(--font); font-size: 15.5px; line-height: 1.35;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 #e6d6b2, 5px 6px 0 rgba(0,0,0,.25);
  transform-origin: 50% 100%; transition: opacity .25s, transform .25s steps(3);
}
.bubble.enter { opacity: 0; transform: scale(.85) translateY(6px); }
.bubble .b-text { max-height: 168px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
.bubble .b-text.clipped { -webkit-mask-image: linear-gradient(transparent, #000 26px); mask-image: linear-gradient(transparent, #000 26px); }
.bubble .b-tail { position: absolute; bottom: -12px; width: 12px; height: 9px; left: var(--tail, 50%); margin-left: -6px; background: #fbf3df;
  clip-path: polygon(0 0, 100% 0, 100% 34%, 67% 34%, 67% 67%, 34% 67%, 34% 100%, 0 100%); }
.bubble .b-tail::after { content: ''; position: absolute; inset: 0; }
.bubble.thinking .b-text { color: #6b5a72; font-style: italic; }
.bubble.error { background: #ffe0e4; }

.listening { position: absolute; z-index: 4; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(42,29,48,.88); color: var(--parch); padding: 8px 16px; font-size: 15px; box-shadow: 0 0 0 3px var(--ink); max-width: 70%; }
.listening #interim { color: var(--magic); }

#toasts { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); z-index: 6; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--plum-2); color: var(--text); padding: 7px 14px; font-size: 14px; box-shadow: 0 0 0 3px var(--ink), 4px 4px 0 rgba(0,0,0,.3); animation: pop .25s steps(3); }
.toast.mem { background: #24402f; color: #b8f0c6; }
.toast.bad { background: #4a2430; }

/* ---------------------------------------------------------------- brain map */
.brain { position: absolute; inset: 0; z-index: 8; background: radial-gradient(ellipse at center, #1d1730 0%, #110c1a 75%); animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
#brain-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; image-rendering: pixelated; }
.brain-top { position: absolute; top: 14px; left: 16px; right: 16px; display: flex; gap: 12px; align-items: center; }
.brain-title { font-size: 18px; color: var(--parch); text-shadow: 2px 2px 0 var(--ink); }
#brain-search { flex: 0 1 280px; font-family: var(--font); font-size: 14px; padding: 6px 9px; border: 0; background: var(--parch); color: var(--parch-ink); box-shadow: 0 0 0 3px var(--ink); outline: 0; }
.brain-top .icon-btn { margin-left: auto; }
.brain-legend { position: absolute; left: 16px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 10px; font-size: 13px; color: var(--muted); max-width: 60%; }
.brain-legend span { display: inline-flex; align-items: center; gap: 5px; }
.brain-legend i { width: 9px; height: 9px; display: inline-block; box-shadow: 0 0 0 1px var(--ink); }
.note-card { position: absolute; right: 16px; top: 64px; bottom: 16px; width: min(380px, 42%); display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; background: var(--parch); color: var(--parch-ink); box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 rgba(0,0,0,.35); animation: pop .25s steps(3); }
.nc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 17px; }
.nc-head .icon-btn { background: var(--parch-2); color: var(--parch-ink); }
.nc-meta { font-size: 12px; color: #7a6a52; }
.nc-body { flex: 1; overflow: auto; font-size: 14.5px; line-height: 1.4; white-space: normal; }
.nc-body h1, .nc-body h2, .nc-body h3 { font-size: 15px; color: #7a3b2e; margin: 8px 0 4px; }
.nc-body code { font-family: var(--mono); font-size: 16px; }
.nc-body .wikilink { color: #2f6f6a; text-decoration: underline dotted; cursor: pointer; }
.note-card .chip-btn { align-self: flex-start; }

/* ---------------------------------------------------------------- modals */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(12,8,16,.6); animation: fade .2s; }
.modal-box { width: min(620px, 92vw); max-height: 86vh; overflow: auto; padding: 18px 20px; background: var(--plum-2); color: var(--text); box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 rgba(0,0,0,.4); }
.modal-box.parchment { background: var(--parch); color: var(--parch-ink); text-align: center; width: min(560px, 92vw); }
.qc-text { font-family: var(--mono); font-size: 30px; line-height: 1.1; margin: 10px 6px 14px; }
.qc-author { font-size: 18px; color: #7a3b2e; }
.qc-src { margin-top: 6px; color: #8a7a62; }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 18px; }
.modal-box.parchment .modal-actions { justify-content: center; }
.modal-actions .hint { margin-right: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { background: var(--plum-3); color: var(--muted); border: 0; padding: 6px 14px; font-size: 15px; box-shadow: 0 0 0 2px var(--ink); }
.tabs button.on { background: var(--teal-2); color: var(--parch); }
.field { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; align-items: center; margin: 9px 0; font-size: 14px; }
.field label { color: var(--muted); }
.field input[type=text], .field input[type=password], .field input[type=number], .field select, .field textarea {
  font-family: var(--font); font-size: 14px; width: 100%; padding: 6px 8px; border: 0; background: var(--parch); color: var(--parch-ink); box-shadow: 0 0 0 2px var(--ink); outline: 0;
}
.field textarea { min-height: 120px; resize: vertical; }
.field .note { grid-column: 2; font-size: 12px; color: var(--muted); margin-top: -3px; }
.sect { margin: 16px 0 6px; padding-top: 10px; border-top: 2px solid #1d1422; color: var(--gold); font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.sect .st { font-size: 12px; } .sect .st.ok { color: #7bd88f; } .sect .st.bad { color: #ff9aa8; }
.toggle { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.toggle input { accent-color: var(--teal); width: 16px; height: 16px; }

/* tablets and narrow windows that aren't phones: a slimmer panel beside the study */
@media (max-width: 900px) { :root { --panel-w: 330px; } }

/* ---------------------------------------------------------------- typewriter page */
.paper {
  position: absolute; z-index: 4; width: calc(41ch + 36px); max-width: 48%; padding: 14px 18px 12px; pointer-events: auto; cursor: pointer;
  background: repeating-linear-gradient(180deg, #fbf5e6 0 21px, #efe6cf 21px 22px);
  color: #2b2430; font-family: var(--mono); font-size: 19px; line-height: 22px;
  box-shadow: 0 -3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 5px 5px 0 rgba(0,0,0,.25), inset 0 -6px 0 rgba(0,0,0,.06);
  transform-origin: 50% 100%; transition: transform .45s cubic-bezier(.3,.7,.3,1), opacity .4s;
}
.paper.enter { transform: scaleY(0.05); opacity: .4; }
.paper.leave { transform: translateY(-70px); opacity: 0; transition: transform .55s cubic-bezier(.5,0,.7,.4), opacity .5s; }
.paper .p-text { white-space: pre; max-height: 330px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; min-height: 22px; }
.paper.clipped .p-text { -webkit-mask-image: linear-gradient(transparent, #000 44px); mask-image: linear-gradient(transparent, #000 44px); }
.paper .p-text.typing::after { content: '▌'; color: #7a3b2e; animation: blink .7s steps(2) infinite; }
.clock-hot { position: absolute; z-index: 2; cursor: help; }

/* ---------------------------------------------------------------- wardrobe */
.ward-box { width: min(720px, 94vw); }
.ward-title { margin: 0 0 12px; font-size: 20px; color: var(--parch); text-shadow: 2px 2px 0 var(--ink); }
.ward-grid { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
#wardrobe-preview { width: 240px; height: 288px; image-rendering: pixelated; box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 3px #6b4f74; background: #4a3352; }
.ward-label { color: var(--gold); font-size: 15px; margin: 2px 0 8px; }
.ward-hats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; max-height: 330px; overflow: auto; padding: 4px; }
.ward-opt { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; background: var(--plum-3); color: var(--muted); border: 0; font-size: 13px; box-shadow: 0 0 0 2px var(--ink); }
.ward-opt img { width: 52px; height: 52px; }
.ward-opt.on { background: var(--teal-2); color: var(--parch); box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px var(--gold); }
.ward-cols { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { display: flex; align-items: center; gap: 7px; padding: 5px 10px 5px 6px; background: var(--plum-3); color: var(--muted); border: 0; font-size: 14px; box-shadow: 0 0 0 2px var(--ink); }
.swatch i { width: 20px; height: 20px; background: linear-gradient(135deg, var(--c) 0 60%, var(--c2) 60%); box-shadow: 0 0 0 2px var(--ink); }
.swatch.on { color: var(--parch); box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px var(--gold); }
@media (max-width: 640px) { .ward-grid { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- gallery */
.art-hot { position: absolute; z-index: 2; cursor: zoom-in; }
.art-box { width: min(440px, 94vw); text-align: center; }
#art-canvas { width: 384px; max-width: 100%; image-rendering: pixelated; box-shadow: 0 0 0 4px #b5822f, 0 0 0 7px #e8b64c, 0 0 0 10px var(--ink); margin: 10px auto 14px; display: block; }
.art-title { font-size: 19px; color: var(--parch); }
.art-meta { margin-top: 3px; }
.art-box .modal-actions { justify-content: center; }

/* ---------------------------------------------------------------- chess */
.chess-hot { position: absolute; z-index: 2; cursor: pointer; }
.chess { position: absolute; z-index: 7; background: var(--plum-2); padding: 10px 12px 12px; box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 rgba(0,0,0,.35); animation: pop .25s steps(3); }
.ch-head { display: flex; justify-content: space-between; align-items: center; color: var(--gold); font-size: 16px; margin-bottom: 8px; }
.ch-body { display: flex; gap: 12px; }
.ch-board { width: 384px; height: 384px; image-rendering: pixelated; cursor: pointer; box-shadow: 0 0 0 3px #6e4430, 0 0 0 6px var(--ink); }
.ch-side { width: 170px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.ch-status { color: var(--parch); min-height: 38px; font-size: 15px; }
.ch-caps > div { min-height: 18px; display: flex; flex-wrap: wrap; }
.ch-caps img { width: 18px; height: 18px; }
.ch-moves { flex: 1; min-height: 120px; max-height: 190px; overflow: auto; font-family: var(--mono); font-size: 17px; color: var(--text); background: rgba(0,0,0,.2); padding: 4px 8px; box-shadow: inset 0 0 0 2px #1d1422; }
.ch-moves span { color: var(--muted); }
.ch-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ch-row label { color: var(--muted); font-size: 13px; }
.ch-row select { font-family: var(--font); background: var(--parch); border: 0; padding: 3px 6px; box-shadow: 0 0 0 2px var(--ink); }
.ch-promo { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; gap: 6px; padding: 8px; background: var(--parch); box-shadow: 0 0 0 3px var(--ink); }
.ch-promo button { background: var(--parch-2); border: 0; padding: 4px; box-shadow: 0 0 0 2px var(--ink); }
.ch-promo img { width: 36px; height: 36px; }
.invite { position: absolute; z-index: 5; display: flex; gap: 8px; animation: pop .25s steps(3); }
@media (max-width: 1100px) { .ch-board { width: 320px; height: 320px; } .ch-side { width: 150px; } }

/* ---------------------------------------------------------------- profile */
.who-btn { display: inline-flex; align-items: center; gap: 5px; margin-left: 6px; background: none; border: 0; color: var(--parch-2); font-size: 13px; padding: 2px 4px; }
.who-btn:hover { color: var(--gold); }
.who-dot { width: 7px; height: 7px; background: #7bd88f; box-shadow: 0 0 0 1px var(--ink); }

.sfx-btn { right: 60px; }


/* ================================================================ phones
   body.phone is set by js/ui/mobile.js. Layout, portrait:
   [ top bar ] [ the study, following Orrin ] [ dock ]   — the chat sheet slides up over the dock.        */
#m-top, #m-dock, #m-drawer, #m-scrim, #m-stop, #m-sheet-close { display: none; }
body.phone {
  --top-h: 52px; --dock-h: 88px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  position: fixed; left: 0; right: 0; top: var(--vvtop, 0); height: var(--vvh, 100%);
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
body.phone button { touch-action: manipulation; }

/* top bar: the panel's own header, made compact */
body.phone #m-top {
  display: flex; position: absolute; left: 0; right: 0; top: 0; height: calc(var(--top-h) + var(--safe-t)); padding-top: var(--safe-t); z-index: 12;
  background: linear-gradient(180deg, #2c1f33, #251a2b); border-bottom: 3px solid var(--ink);
}
body.phone #m-top .panel-head { flex: 1; padding: 6px 10px; gap: 8px; min-width: 0; }
body.phone #m-top .avatar { width: 34px; height: 34px; flex: none; }
body.phone #m-top .title { display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; row-gap: 2px; }
body.phone #m-top .title h1 { font-size: 15px; margin: 0; flex-basis: 100%; }
body.phone #m-top .model-btn { font-size: 12px; padding: 1px 6px; max-width: 58vw; }
body.phone #m-top .who-btn { margin-left: 0; font-size: 12px; padding: 1px 2px; }
body.phone #m-top #btn-wardrobe, body.phone #m-top #btn-library, body.phone #m-top #btn-brain { display: none; }
body.phone #m-top .head-tools .icon-btn { width: 38px; height: 38px; }
body.phone #model-menu { position: fixed; left: 8px; right: 8px; top: calc(var(--top-h) + var(--safe-t) + 6px); min-width: 0; max-height: 60vh; z-index: 45; }
body.phone .menu.ctx { z-index: 45; }

/* the study */
body.phone #stage-wrap { position: absolute; left: 0; right: 0; top: calc(var(--top-h) + var(--safe-t)); bottom: calc(var(--dock-h) + var(--safe-b)); transition: none; }
body.phone.sheet-open #stage-wrap { bottom: var(--sheet-h); }
body.phone #btn-sfx, body.phone #btn-fullscreen, body.phone .collapse { display: none; }
body.phone .plaque { top: 10px; right: 8px; padding: 3px 8px; font-size: 13px; gap: 6px; max-width: calc(100% - 16px); }
body.phone .plaque::before, body.phone .plaque::after { display: none; }
body.phone .plaque .pl-sub { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.phone #plaque-text { white-space: nowrap; }
body.phone .bubble { max-width: min(300px, 82vw); min-width: 90px; font-size: 14.5px; padding: 8px 11px; }
body.phone .bubble .b-text { max-height: 118px; }
body.phone.keyboard .bubble .b-text { max-height: 60px; }
body.phone .listening { bottom: 12px; font-size: 14px; max-width: 90%; }
body.phone #toasts { top: 46px; width: 92%; }
body.phone .paper { font-size: 13px; line-height: 15px; width: 84%; max-width: 84%; padding: 8px 10px; }
body.phone .paper .p-text { max-height: 150px; white-space: pre-wrap; }
body.phone .invite { flex-direction: column; }

/* the dock */
body.phone #m-dock {
  display: flex; position: absolute; left: 0; right: 0; bottom: 0; z-index: 12; height: calc(var(--dock-h) + var(--safe-b)); padding: 8px 6px var(--safe-b);
  align-items: center; justify-content: space-around; gap: 2px;
  background: linear-gradient(180deg, #2c1f33, #21172a); border-top: 3px solid var(--ink);
}
body.phone.sheet-open #m-dock { display: none; }
.m-btn {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 58px; height: 64px; padding: 0; border: 0; background: none; color: var(--muted); font-size: 11px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.m-btn .m-ico { display: grid; place-items: center; width: 42px; height: 38px; background: var(--plum-3);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 rgba(0,0,0,.25); }
.m-btn:active .m-ico { transform: translateY(2px); }
.m-btn.on .m-ico { background: var(--teal-2); }
.m-btn .m-lbl { white-space: nowrap; }
.m-btn .m-badge { display: none; position: absolute; top: 2px; right: 6px; width: 10px; height: 10px; background: var(--gold); box-shadow: 0 0 0 2px var(--ink); }
.m-btn.unread .m-badge { display: block; animation: pulse 1s steps(2) infinite; }
.m-btn.m-mic { width: 84px; height: 80px; touch-action: none; color: var(--parch); }
.m-btn.m-mic .m-ico { width: 66px; height: 58px; background: var(--rose);
  box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), inset 0 -5px 0 0 #8c3442, 0 0 0 7px rgba(201,90,106,.25); }
.m-btn.m-mic.live .m-ico { background: #ff7b8e; animation: pulse 0.8s steps(2) infinite; box-shadow: 0 0 0 4px var(--ink), 0 0 0 10px rgba(255,123,142,.45); }
.m-btn.m-mic.live .m-lbl::after { content: '…'; }

/* Stop, floating above the dock while he's answering or speaking */
body.phone.can-stop #m-stop { display: flex; }
#m-stop { position: absolute; z-index: 13; left: 50%; transform: translateX(-50%); bottom: calc(var(--dock-h) + var(--safe-b) + 10px);
  align-items: center; gap: 6px; padding: 8px 18px; border: 0; background: var(--rose); color: #fff; font-size: 16px;
  box-shadow: 0 0 0 3px var(--ink), inset 0 -3px 0 0 #8c3442, 4px 4px 0 rgba(0,0,0,.3); }
body.phone.sheet-open #m-stop { bottom: calc(var(--sheet-h) + 10px); }

/* the chat sheet (the panel, reused) */
body.phone #panel {
  position: absolute; left: 0; right: 0; top: auto; bottom: 0; width: auto; height: var(--sheet-h); z-index: 11;
  border-right: 0; border-top: 4px solid var(--ink); box-shadow: 0 -6px 0 rgba(0,0,0,.25);
  transform: translateY(105%); transition: transform .3s cubic-bezier(.3,.7,.3,1); padding-bottom: var(--safe-b);
}
body.phone.sheet-open #panel { transform: none; }
body.phone .chat-title-row { margin-top: 0; border-top: 0; padding: 6px 10px 6px 16px; touch-action: none; position: relative; }
body.phone .chat-title-row::before { content: ''; position: absolute; left: 50%; top: 3px; width: 40px; height: 4px; margin-left: -20px; background: var(--plum-4); }
body.phone #m-sheet-close { display: grid; flex: none; }
body.phone .status-mini { display: none; }
body.phone .messages { padding: 6px 10px 10px; gap: 12px; }
body.phone .msg .card { font-size: 15px; }
body.phone .msg .meta .act { font-size: 13px; padding: 4px 6px; }
body.phone .composer { padding: 8px 10px 10px; }
body.phone .composer textarea { font-size: 16px; }   /* 16px stops iPhones zooming in on focus */
body.phone .composer-row { margin-top: 8px; }
body.phone .composer-row .icon-btn.small { width: 42px; height: 38px; }
body.phone .send { padding: 9px 18px; font-size: 16px; }
body.phone #ptt-hint { font-size: 12px; }

/* the chats drawer */
body.phone #m-drawer {
  display: flex; flex-direction: column; position: absolute; z-index: 30; left: 0; top: 0; bottom: 0; width: min(330px, 86vw);
  padding: calc(var(--safe-t) + 10px) 0 calc(var(--safe-b) + 10px);
  background: linear-gradient(180deg, #2c1f33, #251a2b); border-right: 4px solid var(--ink);
  transform: translateX(-105%); transition: transform .28s cubic-bezier(.3,.7,.3,1);
}
body.phone.drawer-open #m-drawer { transform: none; }
body.phone #m-scrim { position: absolute; inset: 0; z-index: 29; background: rgba(10,6,14,.55); }
body.phone.drawer-open #m-scrim { display: block; }
body.phone #m-drawer .library { max-height: none; flex: 1; min-height: 0; opacity: 1; padding: 0 10px; }
body.phone #m-drawer .lib-head { font-size: 17px; padding: 6px 2px 10px; }
body.phone #m-drawer .chip-btn { padding: 8px 12px; font-size: 14px; }
body.phone #m-drawer .tree { flex: 1; }
body.phone #m-drawer .tree .row { padding: 10px 8px; font-size: 15px; }
body.phone #m-drawer .tree .row .more { opacity: .7; font-size: 18px; padding: 0 8px; }

/* the ⋯ menu */
body.phone #m-menu { position: absolute; right: 8px; left: auto; top: auto; bottom: calc(var(--dock-h) + var(--safe-b) + 8px); min-width: 230px; z-index: 31; }
.m-item { display: flex !important; align-items: center; gap: 12px; padding: 11px 14px !important; font-size: 16px !important; }
.m-item span { display: grid; place-items: center; }

/* modals and big overlays take the whole phone screen */
body.phone .modal { place-items: stretch; background: rgba(12,8,16,.75); }
body.phone .modal-box { width: 100%; max-height: none; height: 100%; padding: calc(var(--safe-t) + 14px) 14px calc(var(--safe-b) + 14px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
body.phone .modal-box.parchment, body.phone .art-box { height: auto; margin: auto 10px; width: auto; align-self: center; }
body.phone .modal-actions { flex-wrap: wrap; position: sticky; bottom: -14px; padding: 10px 0; background: inherit; }
body.phone .modal-actions .chip-btn { padding: 9px 14px; font-size: 15px; }
body.phone .field { grid-template-columns: 1fr; gap: 4px; }
body.phone .field .note { grid-column: 1; }
body.phone .field input[type=range] { width: 100% !important; }
body.phone .tabs { position: sticky; top: calc(-14px - var(--safe-t)); background: var(--plum-2); padding: 6px 0; z-index: 1; }
body.phone .tabs button { flex: 1; padding: 9px 4px; }
body.phone .ward-grid { grid-template-columns: 1fr; justify-items: center; }
body.phone .ward-side { width: 100%; }
body.phone .ward-hats { grid-template-columns: repeat(4, 1fr); max-height: none; }
body.phone #brain { position: fixed; inset: 0; z-index: 40; }
body.phone .brain-top { flex-wrap: wrap; top: calc(var(--safe-t) + 10px); left: 10px; right: 10px; gap: 8px; }
body.phone .brain-top input { flex: 1; min-width: 0; font-size: 16px; }
body.phone #brain-stats { display: none; }
body.phone .brain-legend { max-width: none; right: 10px; left: 10px; bottom: calc(var(--safe-b) + 10px); font-size: 12px; }
body.phone .note-card { left: 8px; right: 8px; width: auto; top: auto; bottom: calc(var(--safe-b) + 8px); height: 58%; }
body.phone .chess { position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; z-index: 35; padding: 10px 10px calc(var(--safe-b) + 10px); }
body.phone .ch-body { flex-direction: column; align-items: center; }
body.phone .ch-board { width: min(92vw, 52vh); height: min(92vw, 52vh); }
body.phone .ch-side { width: 100%; }
body.phone .ch-moves { min-height: 0; max-height: 70px; }

/* phones on their side: the study fills the screen, the dock runs down the right, the chat slides in from the left */
body.phone.landscape { --top-h: 40px; --dock-w: 76px; }
body.phone.landscape #m-top .avatar { width: 28px; height: 28px; }
body.phone.landscape #m-top .title h1 { flex-basis: auto; }
body.phone.landscape #stage-wrap { bottom: 0; right: var(--dock-w); }
body.phone.landscape.sheet-open #stage-wrap { bottom: 0; left: min(420px, 52vw); }
body.phone.landscape #m-dock { flex-direction: column; left: auto; top: calc(var(--top-h) + var(--safe-t)); width: var(--dock-w); height: auto; padding: 4px 0;
  border-top: 0; border-left: 3px solid var(--ink); justify-content: space-evenly; }
body.phone.landscape.sheet-open #m-dock { display: flex; }
body.phone.landscape .m-btn { height: 46px; width: 64px; gap: 2px; }
body.phone.landscape .m-btn .m-ico { height: 30px; width: 38px; }
body.phone.landscape .m-btn.m-mic { height: 66px; }
body.phone.landscape .m-btn.m-mic .m-ico { height: 46px; width: 56px; }
body.phone.landscape #panel { top: calc(var(--top-h) + var(--safe-t)); height: auto; right: auto; width: min(420px, 52vw);
  border-top: 0; border-right: 4px solid var(--ink); transform: translateX(-105%); }
body.phone.landscape.sheet-open #panel { transform: none; }
body.phone.landscape #m-stop { bottom: 14px; left: calc(50% - var(--dock-w) / 2); }
body.phone.landscape.sheet-open #m-stop { bottom: 14px; left: calc(min(420px, 52vw) + (100% - min(420px, 52vw) - var(--dock-w)) / 2); }
body.phone.landscape #m-menu { bottom: auto; top: calc(var(--top-h) + 8px); right: calc(var(--dock-w) + 8px); }
body.phone #m-menu { max-height: calc(var(--vvh, 100vh) - var(--top-h) - 24px); overflow-y: auto; }
body.phone.landscape #m-menu { display: grid; grid-template-columns: 1fr 1fr; min-width: 400px; }
body.phone.landscape #m-menu.hidden { display: none !important; }
body.phone.landscape .m-btn.m-mic .m-lbl { font-size: 10px; }
body.phone.landscape .chess { top: 0 !important; right: var(--dock-w) !important; }
body.phone.landscape .ch-body { flex-direction: row; align-items: flex-start; }
body.phone.landscape .ch-board { width: calc(var(--vvh, 100vh) - 80px); height: calc(var(--vvh, 100vh) - 80px); }
body.phone.landscape .ch-moves { max-height: 90px; }

/* two-factor dialogs (name menu) */
.mfa-box { width: min(440px, 94vw); text-align: center; }
.mfa-qr { display: inline-block; line-height: 0; box-shadow: 0 0 0 3px var(--ink); margin: 6px 0; }
.mfa-qr svg { width: 190px; height: 190px; }
.mfa-secret { font-family: var(--mono); font-size: 18px; color: var(--gold); word-break: break-all; margin: 4px 0 10px; user-select: all; }
.mfa-otp { width: 60%; font-family: var(--mono); font-size: 24px; letter-spacing: 5px; text-align: center; padding: 6px; border: 0; background: var(--parch); color: var(--parch-ink); box-shadow: 0 0 0 3px var(--ink); }
.mfa-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-family: var(--mono); font-size: 20px; color: var(--parch); background: rgba(0,0,0,.25); padding: 10px 14px; margin: 10px 0; user-select: all; }
