/* Cheet door. One conversation. Constellation ink, readable type.
   Browser layout uses CSS. Application decisions stay in integers in cheet.js. */
:root {
  --bg: #05060a;
  --panel: #0b0f19;
  --paper: #12141f;
  --ink: #f3f0fa;
  --dim: #c4bed6;
  --mint: #62e6c9;
  --gold: #e8b05c;
  --violet: #b48bff;
  --line: #353049;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --serif: Georgia, "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/28px var(--serif);
}
button, input, textarea, summary { font: inherit; color: inherit; }
button, a, input, textarea, summary { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 70%; }
a { color: var(--mint); }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
.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;
}

.cheet-app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  color: var(--ink);
}
.cheet-bar {
  flex-wrap: wrap;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.cheet-bar h1 {
  margin: 0;
  font: 28px/32px var(--mono);
  font-weight: 500;
}
.cheet-bar h1 span { color: var(--gold); }
.cheet-status, .cheet-hint, .cheet-foot, .cheet-cites, .cheet-kicker {
  margin: 0;
  color: var(--dim);
  font: 15px/22px var(--mono);
}
.cheet-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.cheet-app.sheet-open .cheet-stage {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 1fr);
}
.cheet-app[data-layout="wide-studio"].sheet-open .cheet-stage,
.cheet-app[data-layout="magazine"].sheet-open .cheet-stage {
  grid-template-columns: minmax(0, 5fr) minmax(280px, 6fr);
}
.cheet-log {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.cheet-empty { max-width: 38rem; }
.cheet-empty h2 {
  margin: 0 0 8px;
  font: 28px/36px var(--serif);
  font-weight: 500;
}
.cheet-msg { max-width: 42rem; display: flex; flex-direction: column; gap: 4px; }
.cheet-msg.user { align-self: flex-end; }
.cheet-msg.user .cheet-body {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.cheet-who { font: 13px/18px var(--mono); color: var(--gold); }
.cheet-msg.cheet .cheet-who { color: var(--mint); }

.cheet-sheet {
  display: none;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--paper);
  border-left: 1px solid var(--line);
  padding: 22px 28px 48px;
}
.cheet-app.sheet-open .cheet-sheet { display: block; }
.cheet-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--gold);
}
.cheet-sheet-head h2 {
  margin: 4px 0 0;
  font: 28px/36px var(--serif);
  font-weight: 500;
}
.cheet-sheet-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.cheet-sheet .md { max-width: 68ch; }

.cheet-app .md, .cheet-app .cheet-body { font-size: var(--reading-px, 18px); line-height: 160%; }
.cheet-app .md pre, .cheet-app .md code { font-size: calc(var(--reading-px, 18px) - 3px); }
.cheet-app[data-personal-layout="reading"].sheet-open .cheet-stage { grid-template-columns: minmax(0, 1fr); }
.cheet-app[data-personal-layout="reading"].sheet-open .cheet-log { display: none; }
.cheet-app[data-personal-layout="compact"] .md { font-family: var(--mono); }
.cheet-app[data-input="touch"] button { min-height: 48px; }
html[data-motion="reduce"] *, html[data-motion="reduce"] *::before, html[data-motion="reduce"] *::after {
  animation: none !important; transition: none !important; scroll-behavior: auto !important;
}
.personal-dialog { width: min(680px, calc(100vw - 24px)); max-height: 90dvh; overflow: auto;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.personal-dialog::backdrop { background: #05060acc; }
.personal-dialog button { margin: 8px 8px 8px 0; }
.personal-form { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; align-items: center; }
.personal-form input, .personal-form select { font: inherit; width: 100%; min-width: 0; min-height: 44px;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
@media (max-width: 540px) { .personal-form { grid-template-columns: minmax(0,1fr); } .personal-dialog { padding: 16px; } }

.cheet-workshop { max-width: 48rem; padding-bottom: 20px; }
.cheet-workshop[hidden] { display: none; }
.cheet-workshop h2 { color: var(--mint); font-weight: 500; }
.cheet-workshop form { display: grid; gap: 8px; }
.cheet-workshop input, .cheet-workshop textarea {
  width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink);
}
.cheet-workshop textarea { resize: vertical; }
.cheet-workshop pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/20px var(--mono); }
.workshop-history { display: flex; flex-wrap: wrap; gap: 8px; }
.workshop-receipt { margin: 16px 0; overflow-wrap: anywhere; }
.workshop-receipt button, .workshop-receipt a { display: inline-block; margin: 8px 8px 0 0; }
.cheet-workshop summary { cursor: pointer; color: var(--mint); }

.cheet-dock {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 16px 16px;
}
.cheet-composer { display: flex; gap: 8px; align-items: flex-end; }
.cheet-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 168px;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 24px;
}
.cheet-hint { margin-top: 8px; }
.cheet-foot { margin-top: 6px; }
.cheet-embed { margin-top: 8px; color: var(--dim); font: 14px/22px var(--mono); }
.cheet-embed summary { cursor: pointer; color: var(--mint); }
.cheet-embed pre {
  margin: 8px 0;
  padding: 10px 12px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
}

button, .cheet-textbtn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  padding: 8px 14px;
}
button.primary {
  background: var(--mint);
  color: var(--bg);
  border-color: var(--mint);
  font: 16px/22px var(--mono);
}
button.quiet { color: var(--ink); font: 15px/22px var(--mono); }
button.cheet-id1-btn.verified { border-color: var(--mint); color: var(--mint); }

.md { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.md p, .md li { white-space: pre-wrap; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { margin: 4px 0 0; font-weight: 500; }
.md h1 { font: 26px/34px var(--serif); }
.md h2 { font: 22px/30px var(--serif); color: var(--mint); }
.md h3 { font: 18px/26px var(--mono); color: var(--gold); }
.md ul, .md ol { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.md code, .cheet-embed code {
  font: 14px/22px var(--mono);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.md pre {
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 14px/22px var(--mono);
  white-space: pre;
}
.md blockquote {
  margin: 0;
  padding: 8px 14px;
  border-left: 3px solid var(--violet);
  color: var(--dim);
}
.md hr { width: 100%; border: 0; border-top: 1px solid var(--line); }
.md .table-wrap { max-width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.md table { width: 100%; border-collapse: collapse; font: 14px/22px var(--mono); }
.md th, .md td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { color: var(--mint); background: var(--bg); }

.cheet-avatar {
  position: fixed;
  right: 20px;
  bottom: 112px;
  z-index: 6;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: var(--panel);
  display: grid;
  place-items: center;
}
.cheet-avatar svg { width: 40px; height: 40px; display: block; }
.cheet-bar > .cheet-avatar:not(.placed) {
  position: relative; right: auto; bottom: auto; flex: 0 0 48px; width: 48px; height: 48px;
}
.cheet-avatar.placed {
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
}
.cheet-avatar.edge-left .cheet-say { left: 64px; right: auto; }
.cheet-say {
  position: absolute;
  right: 64px;
  bottom: 8px;
  width: max-content;
  max-width: 220px;
  margin: 0;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  font: 15px/22px var(--serif);
  text-align: left;
}
.cheet-say:empty { display: none; }
.cheet-avatar[data-effect] { animation: cheet-hop 400ms ease; }
@keyframes cheet-hop {
  0% { transform: translateY(0); }
  40% { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}
.cheet-avatar.placed[data-effect] {
  animation-name: cheet-hop-placed;
}
@keyframes cheet-hop-placed {
  0% { transform: translate(-50%, -50%); }
  40% { transform: translate(-50%, calc(-50% - 8px)); }
  100% { transform: translate(-50%, -50%); }
}

.cheet-app[data-layout="compact-terminal"] { font-family: var(--mono); }
.cheet-app[data-layout="zen-reader"] .cheet-sheet { font-size: 20px; line-height: 32px; }
.cheet-app[data-layout="compact-terminal"] .md pre,
.cheet-app[data-layout="compact-terminal"] .md code { font-size: 13px; }

.cheet-widget {
  height: auto;
  background: transparent;
}
.cheet-launch {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 7;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--bg);
  border: 1px solid var(--mint);
  font: 16px/22px var(--mono);
}
.cheet-panel {
  position: fixed;
  right: 16px;
  bottom: 68px;
  z-index: 7;
  width: min(380px, calc(100vw - 24px));
  height: min(640px, 70vh);
  display: none;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 70%);
}
.cheet-panel.open { display: flex; }
.cheet-panel .cheet-app { height: 100%; border-radius: 16px; }
.cheet-panel .cheet-avatar { position: absolute; }

@media (max-width: 820px) {
  .cheet-bar { padding: 12px; }
  .cheet-log { padding: 12px; }
  .cheet-app.sheet-open .cheet-stage { grid-template-columns: minmax(0, 1fr); }
  .cheet-app.sheet-open .cheet-sheet {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 5;
    border-left: 0;
  }
  .cheet-msg { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
