/* Stack Master — parchment/ink theme with chat + card panel. */

@font-face {
  font-family: 'Phyrexian';
  src: url('/static/fonts/phyrexian.otf') format('opentype');
}

:root {
  --parchment-primary:   #FFFAF5;
  --parchment-secondary: #FFF6ED;
  --parchment-tertiary:  #F5EFE4;
  --ink-primary:         #2C3E50;
  --ink-secondary:       #34495E;
  --ink-muted:           rgba(44, 62, 80, 0.55);
  --message-assistant:       #3498DB;
  --message-assistant-hover: #2980B9;
  --assistant-text:          #F7FBFE;
  --accent-shadow: rgba(44, 62, 80, 0.1);
  --border-light:  #DEE2E6;
  --border-strong: #CBD2D9;
  --success: #27AE60;
  --error:   #E74C3C;

  --transition: all 0.2s ease;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-lift: 0 6px 18px rgba(44, 62, 80, 0.12);
  --radius: 8px;
  --sidebar-width: 260px;
  --header-height: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--parchment-primary);
  color: var(--ink-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

kbd {
  font-family: 'SF Mono', ui-monospace, 'Menlo', monospace;
  font-size: 0.75em;
  background: var(--parchment-tertiary);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 5px;
}

/* =============================================================== sidebar */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--parchment-secondary);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transform: translateX(0);
  transition: transform 0.22s ease;
}

body[data-sidebar="closed"] .sidebar { transform: translateX(-100%); }

.sidebar-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-chat {
  flex: 1;
  padding: 10px 14px;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  min-width: 0;
}
.new-chat:hover { background: var(--ink-secondary); }

#collapse-sidebar { flex-shrink: 0; }

/* --------------------------------------------- attached deck panel */

.deck-panel {
  padding: 12px;
  border-bottom: 1px solid var(--parchment-tertiary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deck-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.deck-panel-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
}
.deck-panel-add {
  background: transparent;
  border: 1px solid var(--parchment-tertiary);
  color: var(--ink-secondary);
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1;
  padding: 3px 8px;
  cursor: pointer;
  transition: var(--transition);
}
.deck-panel-add:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }

.deck-library {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.deck-library[hidden] { display: none; }
.deck-library li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--ink-secondary);
  transition: background 0.12s ease;
}
.deck-library li:hover { background: var(--parchment-tertiary); }
.deck-library li.active {
  background: var(--parchment-tertiary);
  color: var(--ink-primary);
  font-weight: 500;
}
.deck-library-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-library-meta {
  font-size: 0.7rem;
  color: var(--ink-muted);
}
.deck-library-delete {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 4px;
  visibility: hidden;
}
.deck-library li:hover .deck-library-delete { visibility: visible; }
.deck-library-delete:hover { color: var(--ink-primary); }

.deck-attached-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
  margin-top: 4px;
}
.deck-attached-label[hidden] { display: none; }
.deck-empty p {
  margin: 0 0 8px 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.45;
}
.deck-empty button.secondary {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  color: var(--ink-primary);
  border: 1px solid var(--parchment-tertiary);
  border-radius: var(--radius);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.deck-empty button.secondary:hover {
  background: var(--parchment-tertiary);
}
.deck-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.deck-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--parchment-tertiary);
  border-radius: var(--radius);
}
.deck-chip[hidden] { display: none; }
.deck-chip-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.deck-chip-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-chip-meta {
  font-size: 0.78rem;
  color: var(--ink-muted);
}
.deck-chip-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-top: 2px;
}
.deck-chip-categories[hidden] { display: none; }
.deck-chip-category {
  padding: 1px 6px;
  background: var(--parchment-primary);
  border-radius: 3px;
}
.deck-chip-actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.deck-chip-action {
  padding: 4px 9px;
  font-size: 0.72rem;
  background: transparent;
  color: var(--ink-secondary);
  border: 1px solid var(--parchment-primary);
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}
.deck-chip-action:hover { background: var(--parchment-primary); }
.deck-chip-action.copied { color: var(--ink-primary); font-weight: 500; }
.deck-chip-remove {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.deck-chip-remove:hover {
  background: var(--parchment-primary);
  color: var(--ink-primary);
}

/* --------------------------------------------- deck attach modal */

.deck-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 560px;
  width: 92vw;
  background: var(--parchment-primary);
  color: var(--ink-primary);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.deck-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}
.deck-dialog form {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.deck-dialog h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--ink-primary);
}
.deck-help {
  margin: 0 0 4px 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.45;
}
.deck-help code {
  background: var(--parchment-tertiary);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.8rem;
}
.deck-dialog label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-secondary);
}
.deck-dialog label .muted {
  font-weight: 400;
  color: var(--ink-muted);
}
.deck-dialog input[type="text"],
.deck-dialog textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
  border: 1px solid var(--parchment-tertiary);
  border-radius: var(--radius);
  background: var(--parchment-primary);
  color: var(--ink-primary);
  box-sizing: border-box;
}
.deck-dialog textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 180px;
}
.deck-error {
  padding: 8px 10px;
  background: #fde2e2;
  color: #7a1b1b;
  font-size: 0.85rem;
  border-radius: var(--radius);
}
.deck-error[hidden] { display: none; }
.deck-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.deck-dialog button.tertiary {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.deck-dialog button.tertiary:hover { background: var(--parchment-tertiary); }
.deck-dialog button[type="submit"] {
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}
.deck-dialog button[type="submit"]:hover { background: var(--ink-secondary); }

/* =============================================================== auth (sign-in / profile) */

.auth-control {
  position: relative;
  display: flex;
  align-items: center;
}
.auth-control[hidden] { display: none; }

#sign-in-button {
  /* re-uses .header-action sizing/colors by being marked
     class="header-action" in HTML. Nothing custom needed here. */
}

.profile-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--parchment-secondary);
  color: var(--ink-primary);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  text-transform: uppercase;
}
.profile-button:hover { background: var(--parchment-tertiary); }
.profile-button[hidden] { display: none; }
.profile-initials { line-height: 1; }

.profile-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-lift);
  z-index: 40;
  font-size: 0.9rem;
}
.profile-dropdown[hidden] { display: none; }
.profile-email {
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--ink-primary);
  word-break: break-all;
}
.profile-help {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--ink-muted);
  line-height: 1.45;
}
.profile-signout {
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--parchment-tertiary);
  border-radius: var(--radius);
  color: var(--ink-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.profile-signout:hover { background: var(--parchment-secondary); }

/* Sign-in dialog mirrors the deck-dialog visual language so the two
   first-class modals in the app feel like the same product. */
.sign-in-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 440px;
  width: 92vw;
  background: var(--parchment-primary);
  color: var(--ink-primary);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.sign-in-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.sign-in-dialog form {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sign-in-dialog h2 {
  margin: 0;
  font-size: 1.15rem;
}
.sign-in-help {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.5;
}
.sign-in-dialog label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-secondary);
}
.sign-in-dialog input[type="email"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid var(--parchment-tertiary);
  border-radius: var(--radius);
  background: var(--parchment-primary);
  color: var(--ink-primary);
  box-sizing: border-box;
}
.sign-in-status {
  padding: 8px 10px;
  background: var(--parchment-tertiary);
  color: var(--ink-secondary);
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin: 4px 0 0;
}
.sign-in-status[hidden] { display: none; }
.sign-in-status.error { background: #fde2e2; color: #7a1b1b; }
.sign-in-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.sign-in-dialog button.tertiary {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.sign-in-dialog button.tertiary:hover { background: var(--parchment-tertiary); }
.sign-in-dialog button[type="submit"] {
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}
.sign-in-dialog button[type="submit"]:hover { background: var(--ink-secondary); }
.sign-in-dialog button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* --------------------------------------------- composer deck-attached badge */

.deck-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: var(--parchment-tertiary);
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: 999px;
  margin-bottom: 6px;
  max-width: 100%;
  border: 0;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.deck-badge:hover { background: var(--parchment-secondary, var(--parchment-tertiary)); color: var(--ink-secondary); }
.deck-badge:focus-visible { outline: 2px solid var(--ink-secondary); outline-offset: 2px; }
.deck-badge[hidden] { display: none; }
.deck-badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-secondary);
}
.deck-badge-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 28ch;
}

.chat-list { list-style: none; padding: 8px; margin: 0; overflow-y: auto; flex: 1; }

.chat-list li {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink-secondary);
  line-height: 1.35;
  transition: background 0.12s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
}
.chat-list li:hover { background: var(--parchment-tertiary); }
.chat-list li.active { background: var(--parchment-tertiary); color: var(--ink-primary); font-weight: 500; }
.chat-list .empty { font-style: italic; color: var(--ink-muted); cursor: default; }
.chat-list .empty:hover { background: transparent; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(44, 62, 80, 0.35);
  z-index: 15;
}

/* =============================================================== card panel */

/* Close button inside the card panel is always clickable. */

/* =============================================================== app shell */

.app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background: var(--parchment-primary);
  transition: left 0.22s ease, right 0.22s ease;
}

body[data-sidebar="open"]       .app { left: var(--sidebar-width); }
/* =============================================================== header */

header {
  flex-shrink: 0;
  height: var(--header-height);
  background: linear-gradient(to bottom, #fff, var(--parchment-primary));
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
}

.icon-button {
  background: transparent;
  border: none;
  color: var(--ink-primary);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-button:hover { background: var(--parchment-tertiary); }

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-logo { height: 32px; width: auto; flex-shrink: 0; }

header h1 {
  font-family: 'Cinzel', 'Inter', serif;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin: 0;
  white-space: nowrap;
}

.tagline {
  color: var(--ink-secondary);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.patreon-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  padding: 6px 10px;
  border-radius: 6px;
  transition: var(--transition);
}
.patreon-link:hover { background: var(--parchment-tertiary); color: var(--ink-primary); }

/* =============================================================== about dropdown */

.about { position: relative; }

.about-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 300px;
  max-width: 360px;
  /* On a short viewport (typically mobile) the panel's content
     extends past the bottom of the screen, so the build version
     sits below the fold with no way to reach it — the dropdown
     itself never scrolls. Cap height to the viewport below the
     header and let the dropdown body scroll. 100dvh tracks the
     iOS Safari address-bar collapse so the cap stays accurate
     when the bar shows/hides. */
  max-height: calc(100dvh - var(--header-height) - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow-lift);
  z-index: 40;
  font-size: 0.9rem;
  color: var(--ink-primary);
}

.about-dropdown[hidden] { display: none; }

.about-dropdown a {
  display: block;
  padding: 7px 10px;
  color: var(--ink-primary);
  text-decoration: none;
  border-radius: 5px;
}
.about-dropdown a:hover { background: var(--parchment-secondary); }

.bug-report {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bug-report label {
  font-size: 0.8rem;
  color: var(--ink-secondary);
  font-weight: 500;
}
.bug-report textarea {
  width: 100%;
  resize: vertical;
  min-height: 64px;
  max-height: 160px;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.45;
  padding: 6px 8px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--parchment-secondary);
  color: var(--ink-primary);
  box-sizing: border-box;
}
.bug-report textarea:focus {
  outline: none;
  border-color: var(--ink-primary);
  box-shadow: 0 2px 10px var(--accent-shadow);
}
.bug-report-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.bug-report-status {
  font-size: 0.75rem;
  color: var(--ink-muted);
}
.bug-report-status.error { color: var(--error); }
.bug-report-status.success { color: var(--success); }
#bug-report-submit {
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
#bug-report-submit:hover:not(:disabled) { background: var(--ink-secondary); }
#bug-report-submit:disabled { opacity: 0.55; cursor: wait; }

.about-dropdown hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 6px 4px;
}

/* Header share control — button in the top-right that opens a small
   popover with copy / revoke. Modeled on the way Claude / ChatGPT
   surface conversation sharing. The wrapper is hidden until a chat
   is loaded; updateShareVisibility() in app.js toggles it. */
.share-control {
  position: relative;
}
.share-control[hidden] { display: none; }

.header-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: transparent;
  color: var(--ink-secondary);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.header-action:hover {
  background: var(--parchment-tertiary);
  color: var(--ink-primary);
  border-color: var(--border-strong);
}
/* The class-specificity .header-action rule above defeats the
   user-agent [hidden] { display: none } rule, so the button stays
   visible when toggled hidden. Re-assert with matching specificity. */
.header-action[hidden] { display: none; }

.share-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 280px;
  background: var(--parchment-primary);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: var(--shadow-lift);
  padding: 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.share-popover[hidden] { display: none; }

.share-help {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
  line-height: 1.45;
}
.share-actions {
  display: flex;
  gap: 6px;
}
.share-status {
  font-size: 0.72rem;
  color: var(--ink-muted);
  word-break: break-all;
}
.share-status.error { color: var(--error); }
.share-status.success { color: var(--success); }
#share-copy {
  padding: 5px 12px;
  font-size: 0.82rem;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
#share-copy:hover { background: var(--ink-secondary); }
#unshare-button {
  padding: 5px 10px;
  font-size: 0.78rem;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  cursor: pointer;
}
#unshare-button:hover { color: var(--ink-primary); }
#unshare-button[hidden] { display: none; }
.about-content { padding: 8px 10px; }
.about-content h3 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}
.about-content ul {
  margin: 0 0 10px;
  padding-left: 20px;
  font-size: 0.88rem;
}
.about-content li { margin: 2px 0; }
.attribution {
  font-size: 0.72rem;
  color: var(--ink-muted);
  line-height: 1.5;
  margin: 10px 0 8px;
  font-style: italic;
}

.phyrexian-button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  font-family: 'Phyrexian', serif;
  font-size: 1.2rem;
  color: var(--ink-muted);
  opacity: 0.4;
  padding: 6px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}
.phyrexian-button:hover { opacity: 0.9; color: var(--ink-primary); }

.build-version {
  margin: 8px 0 0;
  font-size: 0.65rem;
  color: var(--ink-muted);
  text-align: center;
  font-family: 'SF Mono', ui-monospace, 'Menlo', monospace;
  letter-spacing: 0.02em;
}

/* Phyrexian mode flips major headings over the whole app. */
body.phyrexian-mode,
body.phyrexian-mode header h1,
body.phyrexian-mode .center-message,
body.phyrexian-mode .message,
body.phyrexian-mode .hint,
body.phyrexian-mode .new-chat,
body.phyrexian-mode .example,
body.phyrexian-mode .card-card-name,
body.phyrexian-mode .sidebar-header,
body.phyrexian-mode input,
body.phyrexian-mode textarea {
  font-family: 'Phyrexian', 'Inter', sans-serif !important;
}

/* =============================================================== main */

main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.center-message {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 1.6rem;
  font-weight: 600;
  max-width: 640px;
  padding: 0 1rem;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.center-message.hidden { opacity: 0; }

.thread {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* =============================================================== messages */

.message {
  position: relative;
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  line-height: 1.6;
  max-width: 82%;
  box-shadow: var(--shadow);
  animation: fadeIn 0.22s ease;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--ink-primary), var(--ink-secondary));
  color: var(--parchment-primary);
  white-space: pre-wrap;
}

.message.assistant {
  align-self: flex-start;
  /* Fix the assistant bubble to its natural width from the moment it's
     created so streaming tokens don't make it resize horizontally. */
  width: 82%;
  background: #fff;
  color: var(--ink-primary);
  border: 1px solid var(--border-light);
  padding-bottom: 2.3rem;
  font-size: 0.95rem;
}

.message.assistant.streaming .message-body::after {
  content: '▍';
  color: var(--message-assistant);
  margin-left: 2px;
  animation: blink 1s steps(2, start) infinite;
}

/* Shared-mode read-only view — hides every interactive control so a
   visitor with the link sees just the conversation. Composer, hint,
   sidebar, suggestions, and per-message feedback all disappear. */
body.shared-mode #sidebar,
body.shared-mode #toggle-sidebar,
body.shared-mode #composer,
body.shared-mode .hint,
body.shared-mode #center,
body.shared-mode #examples,
body.shared-mode .feedback,
body.shared-mode #share-control {
  display: none !important;
}
body.shared-mode .app {
  margin-left: 0;
}

/* Inline event chip — deck attached / detached / swapped. Centered,
   muted, no bubble; visually a thin divider rather than a turn. */
.message.system {
  align-self: center;
  max-width: 70%;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border-light);
  box-shadow: none;
  color: var(--ink-muted);
  font-size: 0.82rem;
  font-style: italic;
  text-align: center;
  letter-spacing: 0.01em;
}

.ghost-notice {
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-style: italic;
  margin-top: 6px;
}

.card-preview {
  position: fixed;
  z-index: 100;
  width: 240px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  filter: drop-shadow(0 10px 28px rgba(44, 62, 80, 0.3));
}
.card-preview.visible {
  opacity: 1;
  transform: translateY(0);
}
.card-preview img {
  width: 100%;
  display: block;
  border-radius: 12px;
}

.text-preview {
  position: fixed;
  z-index: 100;
  width: 360px;
  max-width: calc(100vw - 20px);
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 12px 14px 10px;
  box-shadow: var(--shadow-lift);
  color: var(--ink-primary);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  pointer-events: none;
  font-size: 0.88rem;
  line-height: 1.5;
}
.text-preview.visible {
  opacity: 1;
  transform: translateY(0);
}
.text-preview-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink-primary);
  margin-bottom: 4px;
}
.text-preview-body {
  color: var(--ink-secondary);
  font-style: italic;
}
.text-preview-footer {
  display: block;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--ink-muted);
  text-decoration: none;
  pointer-events: auto;
}
.text-preview-footer:hover { color: var(--ink-primary); }

/* =============================================================== agentic activity */

.thinking {
  margin: 0 0 10px;
  border-left: 2px solid var(--border-strong);
  padding-left: 10px;
}
.thinking summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 2px 0;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before {
  content: '';
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  transition: transform 0.15s ease;
}
.thinking[open] summary::before { transform: rotate(90deg); }
.thinking summary:hover { color: var(--ink-secondary); }
.thinking[open] summary { color: var(--ink-secondary); }
.thinking-body {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--ink-secondary);
  font-style: italic;
  line-height: 1.55;
  white-space: pre-wrap;
  opacity: 0.9;
}

.tool-activity {
  margin: 0 0 10px;
  background: var(--parchment-tertiary);
  border-radius: 6px;
  padding: 2px 0;
}
.tool-summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--ink-secondary);
  padding: 6px 10px;
  user-select: none;
  list-style: none;
}
.tool-summary::-webkit-details-marker { display: none; }
.tool-activity[open] .tool-summary {
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
}
.tool-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 6px 4px;
}
.tool-call {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink-muted);
  padding: 3px 6px;
  border-radius: 4px;
}
.tool-call .tool-icon { width: 14px; text-align: center; flex-shrink: 0; }
.tool-call .tool-label { flex: 1; }
.tool-call.done { color: var(--ink-secondary); }
.tool-call.error { color: var(--error); }
.tool-call.pending .tool-icon {
  animation: spin 1.2s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Activity timeline (app.js createActivity): what the model did, in
   order, above the answer. The header is a live status while the run
   streams and a one-line recap once it's done. The .thinking and
   .tool-activity rules above are still used by the lab page. */
.activity { margin: 0 0 10px; }
.activity-summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--ink-secondary);
  padding: 2px 0;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.activity-summary::-webkit-details-marker { display: none; }
.activity-summary::before {
  content: '';
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid var(--ink-muted);
  transition: transform 0.15s ease;
}
.activity[open] > .activity-summary::before { transform: rotate(90deg); }
.activity.busy .activity-status::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--message-assistant);
  vertical-align: middle;
  animation: activity-pulse 1.2s ease-in-out infinite;
}
@keyframes activity-pulse {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}
.activity-steps {
  list-style: none;
  margin: 6px 0 0;
  padding: 0 0 0 12px;
  border-left: 2px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.step-thinking summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--ink-muted);
  list-style: none;
  user-select: none;
}
.step-thinking summary::-webkit-details-marker { display: none; }
.step-thinking summary::after { content: ' ▸'; font-size: 0.7rem; }
.step-thinking details[open] summary::after { content: ' ▾'; }
.step-thinking.empty summary { cursor: default; pointer-events: none; }
.step-thinking.empty summary::after { content: none; }
.step-thinking.active summary { color: var(--ink-secondary); }
.step-body {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--ink-secondary);
  font-style: italic;
  line-height: 1.55;
  white-space: pre-wrap;
}
.step-tools .tool-list {
  background: var(--parchment-tertiary);
  border-radius: 6px;
  padding: 4px 6px;
}
.step-note {
  font-size: 0.85rem;
  color: var(--ink-secondary);
  line-height: 1.5;
}
.step-note > *:first-child { margin-top: 0; }
.step-note > *:last-child  { margin-bottom: 0; }
/* The status line says what's happening; no lone cursor under it. */
.message.assistant.streaming .activity + .message-body:empty::after { content: none; }

/* markdown inside assistant bubbles */
.message-body { max-width: 100%; }
.message.assistant .message-body > *:first-child { margin-top: 0; }
.message.assistant .message-body > *:last-child  { margin-bottom: 0; }

.message.assistant .message-body h1,
.message.assistant .message-body h2,
.message.assistant .message-body h3,
.message.assistant .message-body h4 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink-primary);
  margin: 1.1em 0 0.45em;
}
.message.assistant .message-body h1 { font-size: 1.15rem; border-bottom: 1px solid var(--border-light); padding-bottom: 4px; }
.message.assistant .message-body h2 { font-size: 1.05rem; color: var(--ink-secondary); }
.message.assistant .message-body h3 { font-size: 0.98rem; color: var(--ink-secondary); }
.message.assistant .message-body h4 { font-size: 0.92rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); }

.message.assistant .message-body p { margin: 0.55em 0; }

.message.assistant .message-body ul,
.message.assistant .message-body ol { margin: 0.5em 0 0.5em 1.4em; padding: 0; }
.message.assistant .message-body li { margin: 0.25em 0; }
.message.assistant .message-body li > p { margin: 0.2em 0; }

.message.assistant .message-body strong { color: var(--ink-primary); font-weight: 700; }
.message.assistant .message-body em     { color: var(--ink-secondary); font-style: italic; }

.message.assistant .message-body code {
  background: var(--parchment-tertiary);
  border: 1px solid var(--border-light);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', ui-monospace, 'Menlo', monospace;
  font-size: 0.85em;
}
.message.assistant .message-body pre {
  background: var(--parchment-tertiary);
  border: 1px solid var(--border-light);
  padding: 10px 12px;
  border-radius: 6px;
  margin: 0.6em 0;
  overflow-x: auto;
  font-size: 0.85em;
}
.message.assistant .message-body pre code { background: transparent; border: none; padding: 0; }

.message.assistant .message-body a {
  color: var(--message-assistant);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.assistant .message-body blockquote {
  border-left: 3px solid var(--message-assistant);
  margin: 0.6em 0;
  padding: 0.2em 0.9em;
  color: var(--ink-secondary);
  background: var(--parchment-secondary);
  border-radius: 4px;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.card-chip {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--parchment-primary);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease;
}
.card-chip:hover { background: rgba(255, 255, 255, 0.28); }

/* themed feedback buttons */
.feedback {
  position: absolute;
  right: 0.65rem;
  bottom: 0.5rem;
  display: flex;
  gap: 0.25rem;
}

.feedback-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border-light);
  background: #fff;
  color: var(--ink-muted);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  padding: 0;
}
.feedback-btn:hover { color: var(--ink-primary); border-color: var(--ink-primary); }
.feedback-btn.active[data-rating='1']  { color: var(--success); border-color: var(--success); background: rgba(39, 174, 96, 0.08); }
.feedback-btn.active[data-rating='-1'] { color: var(--error);   border-color: var(--error);   background: rgba(231, 76, 60, 0.08); }
.feedback-btn.copy-btn.active          { color: var(--success); border-color: var(--success); }
.feedback-btn:disabled { cursor: default; opacity: 0.85; }
.feedback-btn svg { display: block; }

.error-banner {
  align-self: center;
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  max-width: 82%;
}

/* =============================================================== examples */

/* Lives inside <main> as the empty-state suggestion group, sticking
   to the bottom of the main column so they sit above the composer
   with breathing room (footer placement crammed them; in-flow main
   placement gives the empty state its own air). ChatGPT/Cursor-style
   card row rather than a tight pill strip. */
.examples {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 0.6rem;
  padding: 1rem 1rem 1.25rem;
  max-width: 820px;
  margin: 0 auto;
  transition: opacity 0.25s ease, max-height 0.3s ease, padding 0.3s ease;
}

.examples.hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

.example {
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  border-radius: 14px;
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
  text-align: left;
  flex: 0 1 240px;
  max-width: 260px;
}
/* The clamp lives on an inner span: overflow:hidden on the button clips
   at the padding edge, so a clamped-but-still-rendered 4th line used to
   leak half-cut into the bottom padding. The span has no padding, so the
   clamp boundary and the clip boundary coincide. */
.example-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.example:hover { background: var(--ink-secondary); transform: translateY(-1px); }

/* =============================================================== footer */

footer {
  flex-shrink: 0;
  background: var(--parchment-primary);
  border-top: 1px solid var(--border-light);
  box-shadow: 0 -2px 10px var(--accent-shadow);
  padding: 10px 1rem 14px;
}

.composer {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

/* The Turnstile widget sits in its own row above the composer. With
   appearance="interaction-only" it renders 0×0 when no challenge is
   required, so the row collapses and takes no space. When Cloudflare
   *does* demand a checkbox, the widget expands here instead of cramping
   the input row. */
.turnstile-row {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
}
.turnstile-row:not(:empty):has(iframe) {
  margin-bottom: 10px;
}
.turnstile-row .cf-turnstile { max-width: 100%; }
/* Once a token has been captured, hide the row so the "Success!" badge
   doesn't linger above the composer. reset() on send clears the class. */
body.turnstile-verified .turnstile-row { display: none; }
/* QA bypass mode: Turnstile is server-skipped, so hide the widget
   entirely to keep browser-agent QA runs from trying to solve it. */
body.qa-bypass .turnstile-row { display: none; }

/* =============================================================== preview modal (touch) */

/* Touch devices open card / wiki / rule previews as a centered modal
   instead of an anchor-positioned floating tooltip. The previous design
   had two problems near the bottom of the viewport: the preview clipped
   off-screen, and a 5s timeout wiped it mid-read. The modal stays open
   until explicitly dismissed (× button, backdrop tap, or Escape). */
.preview-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(20, 18, 14, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.preview-modal-overlay.visible { opacity: 1; }

.preview-modal {
  position: relative;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(20, 18, 14, 0.45);
  max-width: 100%;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.preview-modal-card {
  width: min(320px, 100%);
  padding: 12px;
  align-items: stretch;
}
.preview-modal-image {
  width: 100%;
  display: block;
  border-radius: 10px;
}
.preview-modal-wiki,
.preview-modal-rule,
.preview-modal-policy {
  width: min(420px, 100%);
  padding: 18px 20px 14px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink-primary);
}
.preview-modal-title {
  font-weight: 600;
  font-size: 1.05rem;
  margin: 4px 28px 10px 0;
}
.preview-modal-body {
  color: var(--ink-secondary);
  white-space: pre-wrap;
}
.preview-modal-link {
  display: inline-block;
  margin-top: 14px;
  font-size: 0.9rem;
  color: var(--ink-primary);
  font-weight: 500;
  text-decoration: none;
  align-self: flex-start;
}
.preview-modal-link:hover { text-decoration: underline; }
.preview-modal-card .preview-modal-link {
  margin: 10px 4px 4px;
  text-align: center;
}

.preview-modal-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 18, 14, 0.08);
  color: var(--ink-primary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.preview-modal-close:hover { background: rgba(20, 18, 14, 0.16); }

/* =============================================================== inline error */

/* Replaces the prior "remove the bubble + show a banner" flow. Keeps any
   partial streamed text visible so the user doesn't lose context, and
   exposes a labelled retry button. */
.message.assistant.errored {
  border-left: 3px solid #c94a3b;
}
.inline-error {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(201, 74, 59, 0.08);
  border: 1px solid rgba(201, 74, 59, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}
.inline-error-text {
  flex: 1;
  color: #8a3328;
}
.inline-error-retry {
  border: 1px solid rgba(201, 74, 59, 0.5);
  background: #fff;
  color: #8a3328;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.inline-error-retry:hover { background: rgba(201, 74, 59, 0.1); }

.input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: linear-gradient(to right, #fff, var(--parchment-secondary));
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 6px 14px;
  transition: var(--transition);
  min-height: 44px;
}

.input-wrap:focus-within {
  border-color: var(--ink-primary);
  box-shadow: 0 2px 10px var(--accent-shadow);
}

.input-wrap.drag-active {
  border-color: var(--ink-primary);
  background: var(--parchment-secondary);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 1;
}

#input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink-primary);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  padding: 8px 0;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
}

.attach-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  margin-bottom: 4px;
}
.attach-btn:hover { color: var(--ink-primary); background: rgba(0, 0, 0, 0.04); }

.attachment-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 0 4px;
}
.attachment-strip[hidden] { display: none; }
.attachment-status {
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-style: italic;
  align-self: center;
}

.attachment-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: visible;
  border: 1px solid var(--border-light);
  background: var(--parchment-secondary);
  flex-shrink: 0;
}
.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 7px;
}
.attachment-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: 2px solid #fff;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Inline image previews on the user's own bubble. The full-size
   versions live only in this page session — phase-1 image attachments
   aren't persisted, so reloading drops the thumbnails but keeps the
   text and any cards Claude looked up. */
.message.user .images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.message.user .images img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}

#input::placeholder { color: var(--ink-muted); }

#send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

#send:hover:not(:disabled) { background: var(--ink-secondary); transform: translateY(-1px); }
#send:disabled { opacity: 0.4; cursor: not-allowed; }

.hint {
  max-width: 820px;
  margin: 6px auto 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-muted);
}

/* =============================================================== autocomplete */

.suggestions {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  max-height: 240px;
  overflow-y: auto;
  z-index: 30;
}

.suggestions li {
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--ink-primary);
  transition: background 0.1s ease;
}
.suggestions li:hover,
.suggestions li[aria-selected='true'] { background: var(--parchment-secondary); }

/* =============================================================== animations */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes blink { to { visibility: hidden; } }

/* =============================================================== responsive */

/* ≤ 1280px the sidebar slides over the chat as an overlay instead of
   pushing the main content aside. Keeps the conversation readable on
   mid-size laptops where a 260px sidebar + 820px thread leaves no
   breathing room. */
@media (max-width: 1023px) {
  body[data-sidebar="open"] .app,
  body[data-sidebar="closed"] .app { left: 0; }
  body[data-sidebar="open"] .sidebar { box-shadow: var(--shadow-lift); }
}

/* ≥ 1024px the sidebar becomes a permanent push-column. The viewport
   has room for a 260px sidebar + the chat thread without crowding
   either; below this the sidebar overlays and dismisses on
   outside-click. The external hamburger is redundant while the
   sidebar is open in push mode — the collapse button inside it
   takes over. */
@media (min-width: 1024px) {
  body[data-sidebar="open"] #toggle-sidebar { display: none; }
}

@media (max-width: 640px) {
  .tagline { display: none; }
  /* Hide the wordmark on mobile — the logo is enough brand-identity
     and the header's right side now carries enough chrome (patreon,
     profile/sign-in, about) that the wordmark crashes into them on
     narrow screens. */
  .brand h1 { display: none; }
  .patreon-link span { display: none; }         /* icon only; keep the brand mark */
  .hint { display: none; }                      /* Enter/Shift+Enter irrelevant on touch */
  /* Stack suggestions vertically on phones so they don't compete
     with the center text for horizontal space. */
  .examples { flex-direction: column; align-items: center; }
  .example { flex: 0 1 auto; max-width: 90%; }
  .example-text { -webkit-line-clamp: 2; }
  /* All three header popovers anchor to a button near the viewport's
     right edge, so a fixed-width popover positioned with right:0
     spills off the left side of a narrow phone screen. Re-anchor
     them to viewport edges with an 8px gutter so they fit cleanly
     regardless of where the source button sits. */
  .share-popover,
  .profile-dropdown,
  .about-dropdown {
    position: fixed;
    left: 8px;
    right: 8px;
    top: calc(var(--header-height) + 6px);
    width: auto;
    max-width: none;
  }
  .message { max-width: 94%; padding: 0.8rem 0.95rem; }
  .message.assistant { width: 94%; }
  .center-message { font-size: 1.2rem; top: 32%; }
  .example { font-size: 0.8rem; padding: 0.5rem 0.85rem; }
  .composer { gap: 0.4rem; }
  footer { padding: 8px 0.6rem 12px; }
  .input-wrap { padding: 4px 10px; }
  #send { width: 40px; height: 40px; }
  .card-panel { width: 100vw; }
}

/* =============================================================== lab page */

body.lab-mode {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}

.lab-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-light);
  background: var(--parchment-secondary);
}
.lab-header .brand { display: inline-flex; align-items: baseline; gap: 8px; text-decoration: none; color: inherit; }
.lab-header .brand h1 { margin: 0; font-family: 'Cinzel', serif; font-size: 1.05rem; }
.lab-header .brand-logo { width: 22px; height: 22px; object-fit: contain; }
.lab-subtitle { color: var(--ink-muted); font-size: 0.78rem; }

.lab-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
  min-height: 0;
}

.lab-column {
  display: flex;
  flex-direction: column;
  background: var(--parchment-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.lab-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--parchment-tertiary);
  border-bottom: 1px solid var(--border-light);
}
.lab-arm-label {
  font-family: 'SF Mono', ui-monospace, 'Menlo', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
}
.lab-arm-treatment { color: var(--message-assistant); }
.lab-status {
  font-size: 0.72rem;
  color: var(--ink-muted);
  font-style: italic;
}
.lab-status[data-kind="done"] { color: var(--success); font-style: normal; }
.lab-status[data-kind="error"] { color: var(--error); font-style: normal; }

.lab-column-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  font-size: 0.94rem;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lab-column-body .message {
  /* Lab columns are narrower than the main chat — give bubbles the
     full width minus a small margin so long markdown doesn't wrap
     awkwardly inside an 82%-of-column box. */
  max-width: 96%;
}
.lab-column-body .message.assistant { width: auto; min-width: 0; }
.lab-column-body pre,
.lab-column-body code {
  background: var(--parchment-tertiary);
  border-radius: 4px;
}
.lab-column-body pre { padding: 8px 10px; overflow-x: auto; }
.lab-column-body code { padding: 1px 4px; font-size: 0.86em; }

.lab-note {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 0.82rem;
}
.lab-note-error { background: rgba(231, 76, 60, 0.08); color: var(--error); }

.lab-target-picker {
  display: inline-flex;
  background: var(--parchment-primary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow: hidden;
}
.lab-target {
  padding: 4px 12px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border-light);
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.lab-target:last-child { border-right: none; }
.lab-target:hover { background: var(--parchment-tertiary); color: var(--ink-secondary); }
.lab-target.active {
  background: var(--ink-primary);
  color: var(--parchment-primary);
}
.lab-target.active:hover { background: var(--ink-secondary); }

.lab-footer {
  border-top: 1px solid var(--border-light);
  background: var(--parchment-secondary);
  padding: 10px 14px 12px;
}
.lab-composer { display: flex; flex-direction: column; gap: 8px; }
.lab-composer-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--ink-muted);
}
.lab-composer-controls label { font-weight: 500; }
.lab-composer-controls select {
  flex: 1;
  max-width: 360px;
  padding: 5px 8px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--parchment-primary);
  color: var(--ink-primary);
  font-family: inherit;
  font-size: 0.84rem;
}
.lab-clear {
  margin-left: auto;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  color: var(--ink-secondary);
  font-size: 0.78rem;
  cursor: pointer;
}
.lab-clear:hover { background: var(--parchment-tertiary); }

.lab-input-wrap {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
#lab-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--parchment-primary);
  color: var(--ink-primary);
  font-family: inherit;
  font-size: 0.94rem;
  resize: vertical;
  min-height: 56px;
  max-height: 200px;
}
#lab-input:focus { outline: 2px solid var(--ink-secondary); outline-offset: 1px; }
#lab-send {
  padding: 0 18px;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
#lab-send:disabled { background: var(--border-strong); cursor: not-allowed; }
#lab-send:not(:disabled):hover { background: var(--ink-secondary); }

.lab-hint {
  margin: 0;
  font-size: 0.7rem;
  color: var(--ink-muted);
}

@media (max-width: 900px) {
  .lab-main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

/* =============================================================== debug pill */

.debug-pill {
  position: fixed;
  right: 14px;
  bottom: 14px;
  /* Below dropdowns and popovers (z-index 40): on a short viewport the
     About drawer reaches the bottom-right corner, and a pill stacked
     above it swallowed clicks on the drawer's links — Aiqaramba's
     discovery crawler reported "element click intercepted" on the
     Commander Matchmaker link (2026-09-02). A debug aid must never win
     a click over real UI. */
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border-radius: 8px;
  font-size: 0.74rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  max-width: 240px;
}
.debug-pill[hidden] { display: none; }
/* While the About drawer is open the pill must not take any click. */
.debug-pill.debug-pill-suppressed { visibility: hidden; pointer-events: none; }
.debug-pill-arms { display: flex; flex-direction: column; gap: 3px; }
.debug-pill-arm {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: 'SF Mono', ui-monospace, 'Menlo', monospace;
}
.debug-pill-arm-name { color: rgba(255, 255, 255, 0.65); }
.debug-pill-arm-value { font-weight: 600; }
.debug-pill-arm-overridden {
  color: #f9d77a;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.debug-pill-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 6px;
}
.debug-pill-link {
  color: var(--parchment-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.74rem;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}
.debug-pill-link:hover { background: rgba(255, 255, 255, 0.08); }
.debug-pill-close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.debug-pill-close:hover { color: var(--parchment-primary); }

/* ====================================================== sources rail */

.content-row {
  flex: 1;
  display: flex;
  min-height: 0;
}
.content-row > main { flex: 1; }

.context-rail {
  display: none;
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border, #DEE2E6);
  background: var(--parchment-secondary, #FFF6ED);
  overflow-y: auto;
  padding: 1rem 0.9rem 1.5rem;
  flex-direction: column;
  gap: 0.75rem;
}
@media (min-width: 1101px) {
  .context-rail:not([hidden]) { display: flex; }
}

.context-rail-header { display: flex; flex-direction: column; gap: 0.15rem; }
.context-rail-title {
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--ink-primary);
  text-decoration: none;
}
.context-rail-title:hover { color: var(--accent, #3498DB); }
.context-rail-sub { font-size: 0.75rem; color: rgba(44, 62, 80, 0.55); }

.rail-group-label {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(44, 62, 80, 0.45);
  margin-top: 0.5rem;
}

.rail-rule {
  background: var(--parchment-primary, #FFFAF5);
  border: 1px solid var(--border, #DEE2E6);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
}
.rail-rule-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.rail-rule-ref { font-weight: 650; font-size: 0.85rem; color: var(--ink-primary); }
.rail-rule-meta { font-size: 0.7rem; color: rgba(44, 62, 80, 0.55); }
.rail-badge {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #E74C3C;
  color: #fff;
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
}
.rail-rule-text {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rail-rule.expanded .rail-rule-text { display: block; -webkit-line-clamp: unset; }
.rail-rule-open {
  display: none;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--accent, #3498DB);
  text-decoration: none;
}
.rail-rule.expanded .rail-rule-open { display: inline-block; }

.rail-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--parchment-primary, #FFFAF5);
  border: 1px solid var(--border, #DEE2E6);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--ink-primary);
}
.rail-card img { width: 30px; border-radius: 3px; }

/* Mobile / narrow: sources as a chip row under the answer */
.sources-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
}
@media (min-width: 1101px) { .sources-row { display: none; } }
.sources-row-label {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(44, 62, 80, 0.45);
}
.source-chip {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border, #DEE2E6);
  border-radius: 999px;
  background: var(--parchment-secondary, #FFF6ED);
  color: var(--ink-primary);
  text-decoration: none;
  cursor: pointer;
}
.source-chip .arch { color: #E74C3C; font-weight: 700; }

/* ====================================================== rules overlay */

.rules-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(44, 62, 80, 0.45);
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.rules-overlay[hidden] { display: none; }
.rules-overlay-panel {
  position: relative;
  background: var(--parchment-primary, #FFFAF5);
  width: min(920px, 100%);
  margin: 1.25rem;
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.rules-overlay-close {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--parchment-secondary, #FFF6ED);
  color: var(--ink-primary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.rules-overlay-close:hover { background: var(--ink-primary); color: var(--parchment-primary); }
.rules-overlay-frame { flex: 1; width: 100%; border: none; }
@media (max-width: 700px) {
  .rules-overlay-panel { margin: 0; border-radius: 0; }
}

/* Consulted refs in tool rows: interactable but visibly unvetted —
   dotted underline, inherits the muted row color until hover. */
.tool-call .tool-ref {
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.tool-call .tool-ref:hover { color: var(--accent, #3498DB); }

/* ---------------------------------------------------- goldfish handoff card */
.goldfish-card {
  margin-top: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--parchment-secondary);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.goldfish-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goldfish-card-name { font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: 15px; }
.goldfish-card-meta, .goldfish-card-deck, .goldfish-card-hint { font-size: 12px; color: var(--ink-muted); }
.goldfish-card-q { font-weight: 600; }
.goldfish-card-nums { display: flex; flex-wrap: wrap; gap: 4px 16px; font-variant-numeric: tabular-nums; }
.goldfish-card-nums b { font-size: 18px; }
.goldfish-card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 4px; }
.goldfish-card-open {
  background: var(--ink-primary);
  color: var(--parchment-primary);
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 500;
  text-decoration: none;
}
.goldfish-card-open:hover { background: var(--ink-secondary); }

.deck-library-goldfish {
  border: none;
  background: none;
  padding: 0 4px;
  font-size: 13px;
  cursor: pointer;
  visibility: hidden;
}
.deck-library li:hover .deck-library-goldfish,
.deck-library-goldfish:focus-visible { visibility: visible; }
@media (hover: none) { .deck-library-goldfish { visibility: visible; } }

/* ---------------------------------------------------- deck chooser for deck chips */
.deck-picker {
  max-width: 560px;
  margin: 0 auto 0.5rem;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.deck-picker-title { margin: 0; font-weight: 600; }
.deck-picker-question { margin: 0; color: var(--ink-muted); font-size: 0.85rem; }
.deck-picker-empty { margin: 0; font-size: 0.85rem; }
.deck-picker-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 260px; overflow-y: auto; }
.deck-picker-deck {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  text-align: left;
  border: 1px solid var(--border-light);
  background: var(--parchment-secondary);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.deck-picker-deck:hover, .deck-picker-deck:focus-visible { border-color: var(--ink-secondary); box-shadow: var(--shadow); }
.deck-picker-name { font-weight: 600; }
.deck-picker-meta { font-size: 0.75rem; color: var(--ink-muted); white-space: nowrap; }
.deck-picker-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.deck-picker-action {
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  color: inherit;
  cursor: pointer;
}
.deck-picker-action.primary-action { background: var(--ink-primary); border-color: var(--ink-primary); color: var(--parchment-primary); }
.deck-picker-action:hover { box-shadow: var(--shadow); }

/* ---------------------------------------------------- remembered house rules */
.memory-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.memory-list li {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ink-secondary);
}
.memory-list li .memory-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.memory-list li .memory-tag {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--error);
  margin-right: 4px;
}
.memory-list li .memory-remove {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 0.95rem;
  line-height: 1.2;
}
.memory-list li .memory-remove:hover { color: var(--ink-primary); }
.memory-empty { margin: 0; font-size: 0.75rem; color: var(--ink-muted); }
.memory-form { display: flex; flex-direction: column; gap: 6px; }
.memory-form select, .memory-form input {
  font: inherit;
  font-size: 0.8rem;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-primary);
}
.memory-form-actions { display: flex; align-items: center; gap: 8px; }
.memory-error { font-size: 0.75rem; color: var(--error); }
body.shared-mode .memory-panel { display: none; }
