/* ExperienceOS — The Ledger.
   Archival ink, paper text, one cinnabar seal. Memory as a living ledger:
   entries ink in, corrections strike through, forgotten lines are redacted,
   and every authorized change carries a stamped receipt. */

:root {
  --ink: #171310;
  --ink-2: #1e1913;
  --ink-3: #292118;
  --line: #372d20;
  --line-soft: #292118;
  --paper: #f1eadc;
  --paper-dim: #c0b49f;
  --muted: #8d806d;
  --seal: #c8451b;
  --seal-bright: #e8703f;
  --seal-wash: rgba(200, 69, 27, 0.12);
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Instrument Sans", -apple-system, system-ui, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, SFMono-Regular, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --stamp: cubic-bezier(0.2, 1.4, 0.4, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--seal-bright);
  outline-offset: 2px;
  border-radius: 4px;
}
svg { display: block; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  animation: rise 0.5s var(--ease-out) both;
}

.wordmark { display: flex; align-items: center; gap: 11px; }
.wordmark-mark { display: block; width: 26px; height: 26px; }
.wordmark-text { display: flex; align-items: baseline; gap: 12px; }
.wordmark-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.01em;
}
.wordmark-tag {
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-display);
}

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.session-chip {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  margin-right: 6px;
  white-space: nowrap;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--paper-dim);
  transition: color 0.18s, background 0.18s;
}
.icon-btn:hover { color: var(--paper); background: var(--ink-3); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- stage ---------- */

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
}

/* ---------- chat ---------- */

.chat {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

.chat-log {
  width: min(100%, 720px);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 24px 16px;
  scroll-behavior: smooth;
}

/* hero */

.hero {
  padding: 9vh 4px 24px;
  animation: rise 0.6s var(--ease-out) 0.08s both;
}
.hero-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.08;
  letter-spacing: -0.01em;
}
.hero-title em { color: var(--seal-bright); font-style: italic; }
.hero-sub {
  margin-top: 18px;
  max-width: 52ch;
  color: var(--paper-dim);
  font-size: 16.5px;
}
.hero-chips { margin-top: 30px; display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  font-size: 14px;
  color: var(--paper-dim);
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}
.chip:hover { border-color: var(--seal); color: var(--paper); background: var(--seal-wash); }

/* messages */

.msg { margin: 18px 0; animation: rise 0.28s var(--ease-out) both; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .msg-body {
  background: var(--ink-3);
  border-radius: 14px 14px 4px 14px;
  padding: 11px 16px;
  max-width: 78%;
}
.msg-assistant .msg-body {
  max-width: 92%;
  padding: 2px 0;
}
.msg-assistant .msg-body p { margin: 0 0 10px; }
.msg-assistant .msg-body p:last-child,
.msg-assistant .msg-body ul:last-child { margin-bottom: 0; }
.msg-assistant .msg-body ul { margin: 0 0 10px; padding-left: 22px; }
.msg-assistant .msg-body li { margin: 3px 0; }
.msg-assistant .msg-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--ink-3);
  border-radius: 4px;
  padding: 1px 5px;
}

.session-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 30px 0 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: rise 0.3s var(--ease-out) both;
}
.session-divider::before, .session-divider::after {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--line);
}

/* pending */

.pending-dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.pending-dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--paper-dim);
  animation: pulse 1.1s ease-in-out infinite;
}
.pending-dots i:nth-child(2) { animation-delay: 0.18s; }
.pending-dots i:nth-child(3) { animation-delay: 0.36s; }
.pending-note {
  margin-left: 12px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  font-family: var(--font-display);
}
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ---------- per-message inspector ---------- */

.inspect-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 10px 6px 8px;
  min-height: 32px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  transition: color 0.18s, background 0.18s;
}
.inspect-line:hover { color: var(--paper-dim); background: var(--ink-2); }
.inspect-line .tick { color: var(--seal-bright); font-weight: 500; }
.inspect-line .chev { transition: transform 0.2s var(--ease-out); }
.inspect-line[aria-expanded="true"] .chev { transform: rotate(90deg); }
.inspect-line svg { width: 11px; height: 11px; }

.receipt-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s var(--ease-out);
}
.receipt-wrap.open { grid-template-rows: 1fr; }
.receipt-wrap > div { overflow: hidden; }

.receipt {
  position: relative;
  margin: 10px 0 4px;
  max-width: 480px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 18px 18px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
/* perforated top edge */
.receipt::before {
  content: "";
  position: absolute;
  top: -1px; left: 8px; right: 8px;
  height: 2px;
  background-image: radial-gradient(circle at 4px 1px, var(--ink) 2.5px, transparent 3px);
  background-size: 12px 2px;
  background-repeat: repeat-x;
}
.receipt-title {
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}
.receipt-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.receipt-row:last-of-type { border-bottom: 0; }
.receipt-row dt { color: var(--muted); }
.receipt-row dd { color: var(--paper); text-align: right; overflow-wrap: anywhere; }

.seal {
  position: absolute;
  top: 12px; right: 14px;
  width: 84px; height: 84px;
  border: 2px solid var(--seal);
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--seal-bright);
  transform: rotate(-6deg);
  font-size: 9px;
  letter-spacing: 0.14em;
  line-height: 1.5;
  opacity: 0.92;
  pointer-events: none;
}
.receipt-wrap.open .seal { animation: stamp 0.34s var(--stamp) both 0.12s; }
.seal b { display: block; font-size: 10.5px; letter-spacing: 0.2em; font-weight: 500; }
@keyframes stamp {
  0% { transform: rotate(-14deg) scale(1.6); opacity: 0; }
  100% { transform: rotate(-6deg) scale(1); opacity: 0.92; }
}

/* ---------- composer ---------- */

.composer {
  width: min(100%, 720px);
  display: flex;
  gap: 10px;
  padding: 14px 24px calc(20px + env(safe-area-inset-bottom));
}
.composer-input {
  flex: 1;
  min-height: 50px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  color: var(--paper);
  font: inherit;
  transition: border-color 0.18s;
}
.composer-input::placeholder { color: var(--muted); font-style: italic; }
.composer-input:focus { border-color: var(--seal); outline: none; }
.composer-send {
  width: 50px; height: 50px;
  border-radius: 12px;
  background: var(--seal);
  color: #fff8f2;
  display: grid;
  place-items: center;
  transition: background 0.18s, transform 0.12s;
}
.composer-send:hover { background: var(--seal-bright); }
.composer-send:active { transform: scale(0.95); }
.composer-send:disabled { background: var(--ink-3); color: var(--muted); cursor: default; }
.composer-send svg { width: 20px; height: 20px; }

/* ---------- the ledger rail ---------- */

.ledger {
  position: relative;
  border-left: 1px solid var(--line-soft);
  background: var(--ink-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
  animation: rise 0.55s var(--ease-out) 0.16s both;
}
/* the classic ledger margin rule */
.ledger::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 26px;
  width: 1px;
  background: var(--seal);
  opacity: 0.35;
  pointer-events: none;
}

.ledger-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 20px 20px 12px 42px;
}
.ledger-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 20px;
}
.ledger-count { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }

.ledger-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 18px 16px 42px; }

.ledger-empty { color: var(--muted); font-size: 13.5px; font-style: italic; padding-top: 8px; }

.ledger-section { margin-bottom: 20px; }
.ledger-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.ledger-list { list-style: none; }

.entry {
  position: relative;
  padding: 9px 2px 9px 0;
  border-bottom: 1px dashed var(--line-soft);
  font-size: 13.5px;
}
.entry-kind {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}
.entry-text { position: relative; display: inline; }

.entry.inked { animation: ink-in 0.5s var(--ease-out) both; }
@keyframes ink-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* superseded: a correction struck through the line */
.entry.superseded .entry-text { color: var(--paper-dim); }
.entry.superseded .entry-text::after {
  content: "";
  position: absolute;
  left: -2px; right: -2px; top: 54%;
  height: 1.5px;
  background: var(--seal);
  opacity: 0.8;
  transform-origin: left center;
}
.entry.struck .entry-text::after { animation: strike 0.4s var(--ease-out) both 0.1s; }
@keyframes strike { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.entry-note {
  display: block;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.entry-note .to { color: var(--seal-bright); }

/* forgotten: redacted */
.entry.forgotten .entry-text { color: var(--muted); }
.entry.forgotten .entry-text::before {
  content: "";
  position: absolute;
  inset: 10% -3px 6% -3px;
  background: var(--ink-3);
  border-radius: 2px;
  opacity: 0.9;
}
.entry.redacted .entry-text::before { animation: redact 0.45s var(--ease-out) both 0.1s; transform-origin: left center; }
@keyframes redact { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.ledger-foot {
  padding: 12px 20px 14px 42px;
  border-top: 1px solid var(--line-soft);
}
.provider-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--paper-dim);
}
.provider-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
}
.provider-chip.live .provider-dot { background: var(--seal-bright); box-shadow: 0 0 8px var(--seal-wash); }

/* ---------- sheets ---------- */

.sheet {
  width: min(440px, calc(100vw - 32px));
  max-height: min(78vh, 720px);
  background: var(--ink-2);
  color: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  margin: auto;
  overflow-y: auto;
}
.sheet.wide { width: min(640px, calc(100vw - 32px)); }
.sheet::backdrop { background: rgba(10, 8, 6, 0.62); backdrop-filter: blur(3px); }
.sheet[open] { animation: rise 0.28s var(--ease-out) both; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet-head h2 { font-family: var(--font-display); font-weight: 500; font-size: 21px; }

.sheet-group {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.sheet-group legend {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 6px;
}

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.radio-row:hover { background: var(--ink-3); }
.radio-row input { margin-top: 4px; accent-color: var(--seal); width: 16px; height: 16px; }
.radio-row.disabled { opacity: 0.45; cursor: not-allowed; }
.radio-row.disabled:hover { background: none; }
.radio-title { display: block; font-weight: 500; }
.radio-sub { display: block; font-size: 12.5px; color: var(--muted); }

.sheet-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: border-color 0.15s, background 0.15s;
}
.sheet-btn:hover { border-color: var(--paper-dim); background: var(--ink-3); }
.sheet-btn.danger { color: var(--seal-bright); border-color: var(--seal-wash); }
.sheet-btn.danger:hover { border-color: var(--seal); background: var(--seal-wash); }
.sheet-btn.confirm { background: var(--seal); border-color: var(--seal); color: #fff8f2; }

.sheet-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.sheet-colophon {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  border-top: 1px dashed var(--line-soft);
  padding-top: 12px;
}

/* engine room */

.engine-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.engine-turn {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.engine-turn-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--paper-dim);
  margin-bottom: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
}
.engine-turn-head .fx { color: var(--seal-bright); font-family: var(--font-mono); font-size: 11px; white-space: nowrap; }
.engine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; }
.engine-grid div { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.engine-grid dt { color: var(--muted); }
.engine-grid dd { color: var(--paper); text-align: right; overflow-wrap: anywhere; }

/* ---------- ledger FAB (mobile) ---------- */

.ledger-fab {
  position: fixed;
  right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  color: var(--paper);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  z-index: 30;
}
.fab-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--seal);
  color: #fff8f2;
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink-3);
  border: 1px solid var(--line);
  color: var(--paper);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  max-width: min(90vw, 480px);
  z-index: 60;
  animation: rise 0.25s var(--ease-out) both;
}

/* ---------- shared ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .stage { grid-template-columns: 1fr; }
  .ledger {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(400px, 92vw);
    z-index: 40;
    transform: translateX(102%);
    transition: transform 0.32s var(--ease-out);
    box-shadow: -24px 0 60px rgba(0, 0, 0, 0.5);
    animation: none;
  }
  .ledger.open { transform: none; }
  .ledger-fab[hidden] { display: none; }
  .ledger-fab:not([hidden]) { display: flex; }
  .wordmark-tag { display: none; }
}

@media (max-width: 520px) {
  .chat-log { padding: 20px 16px 10px; }
  .composer { padding-left: 16px; padding-right: 16px; }
  .hero { padding-top: 5vh; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  .chat-log { scroll-behavior: auto; }
}
