/* canon-engine design system — warm dark, book-adjacent, fluid. */

:root {
  --bg: #0d0f12;
  --bg-raise: #14171c;
  --panel: #181c22;
  --panel-hover: #1d222a;
  --border: #262c36;
  --border-strong: #364050;
  --text: #e8e4da;
  --muted: #8d93a0;
  --faint: #5c6370;
  --accent: #82aaff;
  --accent-dim: #2a3650;
  --gold: #e3b367;
  --green: #95d684;
  --red: #ef8294;
  --violet: #c39ac9;
  --radius: 10px;
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sans: ui-sans-serif, system-ui, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Code', Menlo, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.55;
  font-size: clamp(14px, 1.5vw, 16px);
}

/* ---------- shell ---------- */
nav.shell {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 0.25em;
  padding: 0 clamp(1em, 4vw, 2.5em);
  height: 52px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
nav.shell .brand {
  font-family: var(--serif); font-size: 1.15em; letter-spacing: 0.02em;
  color: var(--text); text-decoration: none; margin-right: 1.2em;
  white-space: nowrap;
}
nav.shell .brand em { color: var(--gold); font-style: normal; }
nav.shell a.tab {
  color: var(--muted); text-decoration: none; padding: 0.35em 0.85em;
  border-radius: 999px; transition: color .15s, background .15s;
  font-size: 0.95em; white-space: nowrap;
}
nav.shell a.tab:hover { color: var(--text); background: var(--panel); }
nav.shell a.tab.active { color: var(--text); background: var(--accent-dim); }
nav.shell a.tab.logout-tab { margin-left: auto; color: var(--faint); font-size: 0.88em; }
nav.shell a.tab.logout-tab:hover { color: var(--red); background: color-mix(in srgb, var(--red) 8%, transparent); }

/* tabs row (desktop: inline flex in the nav bar) */
nav.shell .tabs { display: flex; align-items: center; gap: 0.15em; flex: 1; }

/* hamburger — hidden on wide screens */
.ham-btn {
  display: none; background: none; border: none; cursor: pointer;
  padding: 0.5em; color: var(--text); margin-left: auto;
}
.ham-btn svg { display: block; }

@media (max-width: 640px) {
  nav.shell { flex-wrap: nowrap; }
  .ham-btn { display: flex; align-items: center; margin-left: auto; }
  nav.shell .tabs { display: none; }
  nav.shell .tabs.open {
    display: flex; flex-direction: column; gap: 0;
    position: fixed; top: 52px; left: 0; right: 0;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 0.5em 0; z-index: 49;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: slidedown 0.18s ease;
  }
  nav.shell .tabs.open a.tab {
    padding: 0.75em 1.4em; border-radius: 0;
    font-size: 1.05em;
    border-bottom: 1px solid var(--border);
  }
  nav.shell .tabs.open a.tab:last-child { border-bottom: none; }
  nav.shell .tabs.open a.tab:active { background: var(--accent-dim); }
  @keyframes slidedown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

main {
  max-width: 1080px; margin: 0 auto;
  padding: clamp(1em, 3vw, 2em) clamp(1em, 4vw, 2.5em) 6em;
}

/* ---------- sidebar shell (app_shell.js pages only) ----------
   Perplexity/Claude/ChatGPT-shaped: persistent left rail, settings tucked
   by the profile puck at the bottom. Scoped under body.has-sidebar so the
   public reader (pub.html) and pre-auth pages keep the plain top bar. */
body.has-sidebar { display: flex; min-height: 100vh; }
body.has-sidebar nav.shell {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
  width: 236px; height: 100vh;
  display: flex; flex-direction: column; align-items: stretch;
  gap: 0.2em; padding: 1.1em 0.85em;
  background: var(--bg-raise);
  border-right: 1px solid var(--border);
  border-bottom: none;
  backdrop-filter: none;
  overflow-y: auto;
}
body.has-sidebar nav.shell .brand {
  margin: 0 0 0.15em 0.4em; padding: 0; flex-shrink: 0;
}
body.has-sidebar nav.shell .sidebar-project {
  margin: 0 0 1em 0.4em; color: var(--faint); font-size: 0.8em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0;
}
body.has-sidebar nav.shell .tabs {
  display: flex; flex-direction: column; gap: 0.1em; flex: 1;
  align-items: stretch; overflow-y: auto;
}
body.has-sidebar nav.shell a.tab {
  display: flex; align-items: center; gap: 0.7em;
  padding: 0.55em 0.7em; border-radius: 8px; font-size: 0.92em;
}
body.has-sidebar nav.shell a.tab .tab-icon { font-size: 1.05em; width: 1.2em; text-align: center; }
body.has-sidebar nav.shell a.tab.active { color: var(--text); background: var(--accent-dim); }

body.has-sidebar nav.shell .sidebar-bottom {
  flex-shrink: 0; margin-top: 0.6em; padding-top: 0.7em;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.3em;
}
body.has-sidebar .sidebar-profile {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.4em 0.5em; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
body.has-sidebar .sidebar-profile:hover { background: var(--panel); }
body.has-sidebar .sidebar-profile.active { background: var(--accent-dim); }
body.has-sidebar .sidebar-avatar {
  width: 1.8em; height: 1.8em; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-dim); color: var(--accent);
  display: grid; place-items: center; font-family: var(--serif);
  font-size: 0.95em; font-weight: 600;
}
body.has-sidebar .sidebar-profile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
body.has-sidebar .sidebar-profile-name { font-size: 0.88em; line-height: 1.3; }
body.has-sidebar .sidebar-profile-sub { font-size: 0.76em; color: var(--faint); line-height: 1.3; }
body.has-sidebar .sidebar-gear { color: var(--faint); font-size: 0.95em; flex-shrink: 0; }
body.has-sidebar .sidebar-signout {
  color: var(--faint); text-decoration: none; font-size: 0.8em;
  padding: 0.3em 0.5em;
}
body.has-sidebar .sidebar-signout:hover { color: var(--red); }

body.has-sidebar main { margin-left: 236px; flex: 1; min-width: 0; }
body.has-sidebar .ham-btn {
  display: none; position: fixed; top: 0.7em; left: 0.7em; z-index: 60;
  background: var(--bg-raise); border: 1px solid var(--border); border-radius: 8px;
}

@media (max-width: 860px) {
  body.has-sidebar nav.shell {
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  body.has-sidebar nav.shell.open { transform: translateX(0); }
  body.has-sidebar .ham-btn { display: flex; align-items: center; }
  body.has-sidebar main { margin-left: 0; padding-top: 3.6em; }
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: 0.01em; }
h1 { font-size: clamp(1.6em, 3.5vw, 2.2em); margin: 0.4em 0 0.2em; }
h2 { font-size: 1.25em; margin: 1.6em 0 0.6em; color: var(--text); }
.sub { color: var(--muted); margin: 0 0 1.2em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- cards & grid ---------- */
.grid { display: grid; gap: 0.9em; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  transition: border-color .15s, background .15s, transform .15s;
}
.card.link { cursor: pointer; }
.card.link:hover { border-color: var(--border-strong); background: var(--panel-hover); transform: translateY(-1px); }
.card .big { font-size: 1.9em; font-family: var(--serif); color: var(--text); }
.card .label { color: var(--muted); font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- list items (review, rooms) ---------- */
.item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9em 1.1em;
  margin: 0.55em 0;
  cursor: pointer;
  position: relative;
  transition: border-color .15s, background .15s, opacity .25s;
}
.item:hover { border-color: var(--border-strong); background: var(--panel-hover); }
.item.current { border-color: var(--accent); background: var(--accent-dim); }
.item.confirmed { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); opacity: 0.62; }
.item.rejected { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); opacity: 0.5; }
.item.rejected .fact-head { text-decoration: line-through; }

.badge {
  display: inline-block; font-size: 0.72em; font-family: var(--mono);
  padding: 0.1em 0.6em; border-radius: 999px; margin-right: 0.6em;
  background: var(--bg-raise); border: 1px solid var(--border); color: var(--muted);
  vertical-align: 0.15em;
}
.badge.narrative { color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, var(--border)); }
.badge.claim { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 35%, var(--border)); }
.badge.belief { color: var(--violet); border-color: color-mix(in srgb, var(--violet) 35%, var(--border)); }

.excerpt {
  font-family: var(--serif); font-style: italic; color: #a8a288;
  margin-top: 0.45em; font-size: 0.95em;
  border-left: 2px solid var(--border-strong); padding-left: 0.8em;
}
.contradiction {
  color: var(--red); margin-top: 0.5em; font-size: 0.9em;
  background: color-mix(in srgb, var(--red) 8%, transparent);
  border-radius: 6px; padding: 0.5em 0.8em;
}
.conf { float: right; color: var(--faint); font-size: 0.82em; font-family: var(--mono); }
.verdict { position: absolute; top: 0.7em; right: 1em; font-size: 0.85em; }
.verdict.ok { color: var(--green); } .verdict.no { color: var(--red); }

/* ---------- buttons & inputs ---------- */
button, .btn {
  font-family: var(--sans); font-size: 0.9em;
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 7px;
  padding: 0.45em 1em; cursor: pointer; margin-right: 0.4em;
  transition: border-color .15s, background .15s;
}
button:hover { border-color: var(--accent); }
button.accept { color: var(--green); }
button.reject { color: var(--red); }
button.merge { color: var(--gold); }
button.primary { background: var(--accent-dim); border-color: var(--accent); }
.btns { margin-top: 0.7em; }

input[type=text], input[type=number], input[type=password], textarea {
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 7px;
  padding: 0.55em 0.8em; font-family: var(--sans); font-size: 0.95em;
}
input:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type=range] { accent-color: var(--accent); }

/* ---------- progress / sticky bars ---------- */
#progress {
  position: sticky; top: 3.2em; z-index: 40;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  padding: 0.5em 0; border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 0.9em; color: var(--muted);
}
.batch { color: var(--muted); font-size: 0.9em; margin: 0.7em 0; }

/* ---------- chat ---------- */
.msg {
  padding: 0.8em 1.1em; margin: 0.7em 0; border-radius: 14px;
  max-width: 84%; white-space: pre-wrap; position: relative;
  animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { background: var(--accent-dim); margin-left: auto; border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border)); border-bottom-right-radius: 4px; }
.msg.character { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; font-family: var(--serif); font-size: 1.02em; }
.msg .keeper { position: absolute; right: 0.6em; bottom: 0.35em; cursor: pointer; color: var(--faint); transition: color .15s, transform .15s; }
.msg .keeper:hover { color: var(--gold); transform: scale(1.2); }
.msg .keeper.kept { color: var(--gold); }
.thinking { color: var(--faint); font-style: italic; }
#bar {
  display: flex; gap: 0.6em; align-items: center;
  position: sticky; bottom: 0; padding: 0.8em 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
#text { flex: 1; }
label { color: var(--muted); font-size: 0.85em; white-space: nowrap; }

/* ---------- misc ---------- */
.note { color: var(--faint); font-size: 0.85em; }
.center { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
@media (max-width: 640px) {
  nav.shell { flex-wrap: wrap; }
  .msg { max-width: 95%; }
  .conf { float: none; display: block; margin-top: 0.3em; }
}

/* ---------- scrollbar ---------- */
/* ensure hidden attribute is respected even with display: flex on classes */
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- micro-interactions ---------- */
button:active:not(:disabled) { transform: scale(0.97); }
.card.link { position: relative; overflow: hidden; }
.card.link::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at var(--mx,50%) var(--my,50%), rgba(130,170,255,0.07) 0%, transparent 70%);
  opacity: 0; transition: opacity .2s;
}
.card.link:hover::after { opacity: 1; }

nav.shell a.brand:hover { color: var(--gold); }
nav.shell .brand { transition: color .2s; }

/* ---------- toasts ---------- */
#toast-tray {
  position: fixed; top: 1.1em; right: 1.2em;
  z-index: 9999; display: flex; flex-direction: column; gap: 0.5em;
  pointer-events: none; max-width: 22em;
}
.toast {
  display: flex; align-items: flex-start; gap: 0.6em;
  padding: 0.7em 1em; border-radius: 10px;
  font-size: 0.9em; line-height: 1.45;
  pointer-events: auto; cursor: pointer;
  border: 1px solid var(--border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  transform: translateX(120%); opacity: 0;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
  backdrop-filter: blur(10px);
}
.toast.toast-in  { transform: translateX(0); opacity: 1; }
.toast.toast-out { transform: translateX(120%); opacity: 0; transition-timing-function: ease-in; transition-duration: .18s; }
.toast-icon { font-size: 0.95em; flex-shrink: 0; margin-top: 0.05em; }
.toast.toast-success { background: color-mix(in srgb, var(--green) 12%, var(--panel)); color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, var(--border)); }
.toast.toast-error   { background: color-mix(in srgb, var(--red)   12%, var(--panel)); color: var(--red);   border-color: color-mix(in srgb, var(--red)   30%, var(--border)); }
.toast.toast-warn    { background: color-mix(in srgb, var(--gold)  12%, var(--panel)); color: var(--gold);  border-color: color-mix(in srgb, var(--gold)  30%, var(--border)); }
.toast.toast-info    { background: color-mix(in srgb, var(--accent)12%, var(--panel)); color: var(--accent);border-color: color-mix(in srgb, var(--accent)30%, var(--border)); }
.toast-msg { color: var(--text); }

/* ---------- skeleton loaders ---------- */
.skeleton {
  display: inline-block; border-radius: 6px;
  background: linear-gradient(90deg, var(--panel) 25%, var(--panel-hover) 50%, var(--panel) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}
.skeleton-block { display: block; width: 100%; height: 1em; margin: 0.5em 0; border-radius: 6px; }
.skeleton-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1em 1.2em; animation: skeleton-pulse 1.8s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes skeleton-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- page-load stagger ---------- */
.fade-up {
  opacity: 0; transform: translateY(14px);
  animation: fade-up-in .4s ease forwards;
}
@keyframes fade-up-in { to { opacity: 1; transform: none; } }
.stagger-1 { animation-delay: .05s; }
.stagger-2 { animation-delay: .10s; }
.stagger-3 { animation-delay: .15s; }
.stagger-4 { animation-delay: .20s; }
.stagger-5 { animation-delay: .25s; }
.stagger-6 { animation-delay: .30s; }

/* ---------- item decide animation ---------- */
.item.deciding {
  transition: transform .25s ease, opacity .25s ease, max-height .3s ease;
}
.item.decided-out {
  transform: translateX(40px); opacity: 0; max-height: 0;
  padding: 0; margin: 0; border: none; overflow: hidden;
}

/* ---------- keyboard shortcut hint bar ---------- */
.kbd-bar {
  display: flex; flex-wrap: wrap; gap: 0.5em 1.1em;
  padding: 0.5em 0; font-size: 0.82em; color: var(--muted);
  border-bottom: 1px solid var(--border); margin-bottom: 0.8em;
}
.kbd-bar kbd {
  display: inline-block; background: var(--bg-raise);
  border: 1px solid var(--border-strong); border-radius: 4px;
  padding: 0.05em 0.45em; font-family: var(--mono);
  font-size: 0.9em; color: var(--text);
}

/* ---------- search input ---------- */
.search-wrap { position: relative; margin-bottom: 1.2em; }
.search-wrap input { width: 100%; padding-left: 2.2em; }
.search-wrap::before {
  content: '🔍'; position: absolute; left: 0.6em; top: 50%;
  transform: translateY(-50%); font-size: 0.85em; pointer-events: none;
}

/* ---------- stat counter ---------- */
.stat-big { font-size: 2.2em; font-family: var(--serif); color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- quick action cards ---------- */
.qa-grid { display: grid; gap: 0.8em; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 2em; }
.qa-card {
  display: flex; align-items: center; gap: 0.8em;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9em 1.1em;
  text-decoration: none; color: var(--text);
  transition: border-color .15s, background .15s, transform .15s;
}
.qa-card:hover { border-color: var(--accent); background: var(--panel-hover); transform: translateY(-1px); text-decoration: none; }
.qa-card .qa-icon { font-size: 1.5em; }
.qa-card .qa-label { font-size: 0.9em; font-weight: 500; }
.qa-card .qa-sub { font-size: 0.8em; color: var(--muted); }
