:root {
  --ink: #0e1618;
  --ink-2: #152226;
  --panel: rgba(18, 32, 36, 0.72);
  --line: rgba(212, 184, 132, 0.18);
  --gold: #d4b884;
  --gold-soft: #b8955c;
  --paper: #e7e1d4;
  --paper-dim: #b9b2a3;
  --user: #24363b;
  --assist: rgba(232, 224, 208, 0.06);
  --danger: #c46b5a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --font-brand: "Cormorant Garamond", Georgia, serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--paper);
  font-family: var(--font-body);
  background: var(--ink);
  overflow: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(212, 184, 132, 0.14), transparent 55%),
    radial-gradient(900px 600px at 90% 10%, rgba(54, 96, 104, 0.35), transparent 50%),
    linear-gradient(165deg, #10191c 0%, #0b1214 45%, #132028 100%);
  pointer-events: none;
  z-index: 0;
}
.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.page-shell {
  position: relative;
  z-index: 1;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  gap: clamp(0.45rem, 1vw, 1rem);
  padding: 0 clamp(0.35rem, 1vw, 0.85rem);
  min-width: 0;
}

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  flex: 1 1 auto;
  min-width: 0;
  /* Grow with the viewport on ultrawide displays */
  max-width: none;
  width: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 1.25rem clamp(0.85rem, 1.5vw, 1.5rem) 1rem;
  gap: 0.75rem;
}

/* Full-height Ionic columns: dedicated capital/base + stretching fluted shaft */
.roman-column {
  flex: 0 0 clamp(64px, 6vw, 100px);
  width: clamp(64px, 6vw, 100px);
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  pointer-events: none;
  opacity: 0.55;
  animation: rise 900ms ease both;
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.32));
}
.roman-column-right {
  animation-delay: 80ms;
}
.roman-column-right img {
  transform: scaleX(-1);
}
.roman-column .col-cap,
.roman-column .col-foot {
  display: block;
  width: 100%;
  height: auto;
  flex: 0 0 auto;
  object-fit: contain;
}
.roman-column .col-shaft {
  display: block;
  /* Match capital flute lead-in (60/120) */
  width: 50%;
  flex: 1 1 auto;
  min-height: 2rem;
  object-fit: fill;
  margin: -1px 0;
}

.workspace {
  --library-width: clamp(300px, 24vw, 420px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(0, 1fr) var(--library-width);
  gap: 0.85rem;
}

.chat-col {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 0.75rem;
}

/* Sessions panel */
.sessions {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(18, 32, 36, 0.55);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 700ms 60ms ease both;
}
.sessions-head {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.sessions-head h2 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-dim);
  font-weight: 500;
}
.sessions-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem;
}
.sess-btn {
  font: inherit;
  font-size: 0.82rem;
  color: var(--paper);
  background: rgba(212, 184, 132, 0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
}
.sess-btn:hover {
  border-color: rgba(212, 184, 132, 0.45);
  background: rgba(212, 184, 132, 0.12);
}
.sess-btn.primary {
  color: #1a140c;
  background: linear-gradient(180deg, #e0c792, #b8955c);
  border: 0;
  font-weight: 600;
}
.sess-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}
.sessions-status {
  margin: 0 0.75rem 0.35rem;
  font-size: 0.78rem;
  color: var(--gold);
  line-height: 1.35;
}
.sessions-status.err { color: var(--danger); }
.sessions-list {
  min-height: 0;
  overflow: auto;
  padding: 0.25rem 0.45rem 0.75rem;
}
.sess-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem;
  align-items: start;
  margin: 0.2rem 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
}
.sess-item:hover {
  background: rgba(212, 184, 132, 0.08);
}
.sess-item.active {
  border-color: rgba(212, 184, 132, 0.35);
  background: rgba(212, 184, 132, 0.12);
}
.sess-item .sess-open {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0.55rem 0.35rem 0.55rem 0.55rem;
  min-width: 0;
  width: 100%;
}
.sess-item .sess-title {
  font-size: 0.9rem;
  color: var(--paper);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.sess-item .sess-meta {
  margin-top: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--paper-dim);
}
.sess-item .sess-del {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--paper-dim);
  font-size: 1rem;
  line-height: 1;
  padding: 0.45rem 0.5rem;
  cursor: pointer;
  border-radius: 6px;
}
.sess-item .sess-del:hover {
  color: var(--danger);
  background: rgba(196, 107, 90, 0.12);
}
.sess-empty {
  padding: 0.75rem 0.55rem;
  color: var(--paper-dim);
  font-size: 0.85rem;
  line-height: 1.4;
}
.sessions-toggle { display: none; }

.mast {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.85rem;
  animation: rise 700ms ease both;
}
.brand {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 0.95;
  color: var(--gold);
}
.tagline {
  margin: 0.35rem 0 0;
  color: var(--paper-dim);
  font-size: 0.98rem;
  max-width: 34rem;
}
.meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--paper-dim);
  text-align: right;
  white-space: nowrap;
}

.stage {
  min-height: 0;
  overflow: auto;
  padding: 0.5rem 0.15rem 1rem;
  scroll-behavior: smooth;
}

.empty {
  min-height: 100%;
  display: grid;
  align-content: center;
  gap: 0.75rem;
  animation: rise 900ms 80ms ease both;
}
.empty h1 {
  margin: 0;
  font-family: var(--font-brand);
  font-weight: 500;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  color: var(--paper);
}
.empty > p {
  margin: 0;
  color: var(--paper-dim);
  max-width: 36rem;
}
.prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.6rem;
}
.prompts button {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(212, 184, 132, 0.06);
  color: var(--paper);
  font: inherit;
  font-size: 0.92rem;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.prompts button:hover {
  border-color: rgba(212, 184, 132, 0.45);
  background: rgba(212, 184, 132, 0.12);
  transform: translateY(-1px);
}

.thread { display: grid; gap: 1rem; padding-bottom: 0.5rem; }

.msg {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  animation: rise 420ms ease both;
}
.msg.user {
  background: linear-gradient(180deg, rgba(36, 54, 59, 0.95), rgba(22, 34, 38, 0.95));
}
.msg.assistant {
  background: var(--assist);
  backdrop-filter: blur(8px);
}
.msg .who {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 0.45rem;
}
.msg .body {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 1.02rem;
}
.msg .body .cite {
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.85em;
  cursor: pointer;
  border-bottom: 1px dotted rgba(212, 184, 132, 0.55);
}
.msg .body .cite:hover {
  color: #efd6a4;
  border-bottom-color: var(--gold);
}
.cite-card {
  cursor: pointer;
  transition: background 160ms ease;
}
.cite-card:hover {
  background: rgba(212, 184, 132, 0.06);
}
.cite-card:focus-visible {
  outline: 1px solid rgba(212, 184, 132, 0.55);
  outline-offset: 2px;
}

.citations {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.55rem;
}
.citations h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-dim);
  font-weight: 500;
}
.cite-card {
  border-left: 2px solid rgba(212, 184, 132, 0.45);
  padding: 0.35rem 0 0.35rem 0.75rem;
}
.cite-card .src {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--gold);
}
.cite-card .snip {
  margin: 0.2rem 0 0;
  color: var(--paper-dim);
  font-size: 0.9rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.composer {
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
  animation: rise 700ms 120ms ease both;
}
#form {
  display: grid;
  gap: 0.55rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.75rem;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
textarea {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--paper);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.45;
  min-height: 3.2rem;
}
.composer-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}
select, #send {
  font: inherit;
  border-radius: 999px;
  border: 1px solid var(--line);
}
select {
  background: transparent;
  color: var(--paper-dim);
  padding: 0.4rem 0.7rem;
}
#send {
  background: linear-gradient(180deg, #e0c792, #b8955c);
  color: #1a140c;
  border: 0;
  font-weight: 600;
  padding: 0.55rem 1.25rem;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease;
}
#send:hover { transform: translateY(-1px); filter: brightness(1.05); }
#send:disabled { opacity: 0.55; cursor: wait; transform: none; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

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

/* Library panel */
.library-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 6px 1fr;
  position: relative;
}
.resize-handle {
  cursor: col-resize;
  touch-action: none;
  border-radius: 999px;
  margin: 0.4rem 0;
  background: transparent;
  position: relative;
  z-index: 2;
}
.resize-handle::after {
  content: "";
  position: absolute;
  inset: 12% 1px;
  border-radius: 999px;
  background: rgba(212, 184, 132, 0.22);
  transition: background 140ms ease, inset 140ms ease;
}
.resize-handle:hover::after,
.resize-handle:focus-visible::after,
body.resizing-library .resize-handle::after {
  background: rgba(212, 184, 132, 0.55);
  inset: 8% 0;
}
body.resizing-library {
  cursor: col-resize;
  user-select: none;
}
.library {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(18, 32, 36, 0.55);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 700ms 100ms ease both;
}
.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.library-head-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.library-head h2 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-dim);
  font-weight: 500;
}
.library-back {
  font: inherit;
  font-size: 0.78rem;
  color: var(--gold);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  cursor: pointer;
}
.library-back:hover {
  border-color: rgba(212, 184, 132, 0.45);
}
.library-body {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-rows: 1fr;
}
.library-toggle { display: none; }
/* Ensure [hidden] wins over .reader { display: grid } */
.library-body > [hidden] {
  display: none !important;
}

.tree {
  padding: 0.45rem 0.4rem 0.75rem;
  font-size: 0.88rem;
  min-height: 0;
  overflow: auto;
}
.tree-children {
  list-style: none;
  margin: 0;
  padding: 0 0 0 0.7rem;
  border-left: 1px solid rgba(212, 184, 132, 0.12);
  margin-left: 0.55rem;
}
.tree > .tree-children { padding-left: 0; border-left: 0; margin-left: 0; }
.tree-item { margin: 0.05rem 0; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--paper);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 0.28rem 0.4rem;
  cursor: pointer;
}
.tree-row:hover { background: rgba(212, 184, 132, 0.08); }
.tree-row.dir { color: var(--paper-dim); }
.tree-row.file { color: var(--paper); }
.tree-row.active,
.tree-row.flash {
  background: rgba(212, 184, 132, 0.16);
  color: var(--gold);
  box-shadow: inset 2px 0 0 var(--gold);
}
.tree-twist {
  display: inline-flex;
  width: 1rem;
  flex: 0 0 1rem;
  color: var(--gold-soft);
  font-family: var(--font-mono);
  font-size: 0.7rem;
}
.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-empty,
.tree-loading {
  padding: 1rem 0.9rem;
  color: var(--paper-dim);
  font-size: 0.9rem;
}

.reader {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.reader-main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr);
  overflow: hidden;
}
.reader.outline-collapsed .reader-main {
  grid-template-columns: 1fr;
}
.reader.outline-collapsed .doc-outline {
  display: none;
}
.doc-outline {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(0, 0, 0, 0.14);
}
.doc-outline-head {
  padding: 0.55rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-dim);
  border-bottom: 1px solid var(--line);
}
.doc-outline-list {
  min-height: 0;
  overflow: auto;
  padding: 0.35rem 0.3rem 0.75rem;
}
.doc-outline-empty {
  padding: 0.65rem 0.7rem;
  color: var(--paper-dim);
  font-size: 0.82rem;
  line-height: 1.4;
}
.outline-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--paper);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  cursor: pointer;
}
.outline-item:hover {
  background: rgba(212, 184, 132, 0.1);
  color: var(--gold);
}
.outline-item .pg {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--paper-dim);
  margin-left: 0.35rem;
}
.reader-meta {
  padding: 0.75rem 0.9rem 0.55rem;
  border-bottom: 1px solid var(--line);
}
.reader-meta .cat {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-dim);
  margin: 0 0 0.25rem;
}
.reader-meta h3 {
  margin: 0;
  font-family: var(--font-brand);
  font-weight: 500;
  font-size: 1.25rem;
  color: var(--gold);
  line-height: 1.2;
}
.reader-meta .path {
  margin: 0.3rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--paper-dim);
  word-break: break-all;
}
.reader-content {
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 0.9rem 1.25rem;
}
.reader-content.pdf-embed-host {
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 0;
  overflow: hidden;
  height: 100%;
}
.reader-content.pdf-js-host {
  grid-template-rows: auto 1fr auto;
}
.pdf-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}
.pdf-btn {
  appearance: none;
  font: inherit;
  font-size: 0.82rem;
  color: var(--paper);
  background: rgba(212, 184, 132, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.22rem 0.55rem;
  cursor: pointer;
}
.pdf-btn:hover {
  border-color: rgba(212, 184, 132, 0.45);
  background: rgba(212, 184, 132, 0.14);
}
.pdf-page-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--paper-dim);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.pdf-page-input {
  width: 3.2rem;
  font: inherit;
  font-size: 0.78rem;
  color: var(--paper);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.18rem 0.3rem;
}
.pdf-stage {
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
  background: #0a1012;
}
.pdf-page-wrap {
  position: relative;
  margin: 0 auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.pdf-page-wrap canvas {
  display: block;
  background: #fff;
}
.workspace.reading {
  --library-width: clamp(420px, 36vw, 720px);
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) var(--library-width);
}
.workspace.reading .library {
  min-width: 0;
}
.workspace.reading .library-body {
  overflow: hidden;
}
.workspace.reading .reader {
  height: 100%;
  min-height: 0;
}
.pdf-embed {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 220px);
  border: 0;
  background: #111;
}
.pdf-embed-host > .reader-note {
  margin: 0;
  padding: 0.45rem 0.75rem 0.65rem;
  border-top: 1px solid var(--line);
}
.passage-mark {
  background: rgba(212, 184, 132, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 0.1em;
}
.reader-page {
  margin: 0 0 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid rgba(212, 184, 132, 0.1);
}
.reader-page .pg {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--gold-soft);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0.4rem;
}
.reader-page pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--font-body);
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--paper);
}
.reader-note {
  color: var(--paper-dim);
  font-size: 0.88rem;
  margin: 0.5rem 0 0;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) var(--library-width, 320px);
  }
  .workspace.reading {
    grid-template-columns: minmax(0, 1fr);
  }
  .workspace.reading .library-shell {
    display: grid;
    position: fixed;
    z-index: 22;
    inset: 4.5rem 0.75rem 0.75rem;
    width: auto;
    max-width: none;
    grid-template-columns: 6px 1fr;
  }
  .workspace.reading .library {
    display: grid;
    width: auto;
    max-width: none;
  }
  .sessions-toggle { display: inline-flex; }
  .sessions {
    display: none;
    position: fixed;
    z-index: 21;
    inset: 4.5rem auto 0.75rem 0.75rem;
    width: min(300px, calc(100vw - 1.5rem));
  }
  .sessions.open { display: grid; }
  body.sessions-open { overflow: hidden; }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .library-toggle { display: inline-flex; }
  .library-shell {
    display: none;
    position: fixed;
    z-index: 20;
    inset: 4.5rem 0.75rem 0.75rem;
    width: auto;
    max-width: none;
    grid-template-columns: 6px 1fr;
  }
  .library-shell.open { display: grid; }
  .library {
    display: grid;
    max-width: none;
  }
  body.library-open { overflow: hidden; }
}

@media (max-width: 820px) {
  .page-shell {
    gap: 0;
    padding: 0;
  }
  .roman-column { display: none; }
}

@media (max-width: 700px) {
  .mast { flex-direction: column; align-items: start; }
  .meta { text-align: left; white-space: normal; }
  .app { padding: 1rem; }
}

/* Access gate */
.gate-body { overflow: auto; }
.gate {
  position: relative;
  z-index: 1;
  max-width: 420px;
  margin: 12vh auto 4rem;
  padding: 2rem 1.5rem;
  animation: rise 500ms ease both;
}
.gate .brand {
  font-family: var(--font-brand);
  font-size: clamp(2.6rem, 7vw, 3.4rem);
  margin: 0 0 0.35rem;
  letter-spacing: 0.02em;
  color: var(--gold);
}
.gate h1 {
  font-family: var(--font-brand);
  font-weight: 500;
  font-size: 1.55rem;
  margin: 0 0 0.6rem;
  color: var(--paper);
}
.gate .lede {
  color: var(--paper-dim);
  line-height: 1.5;
  margin: 0 0 1.5rem;
}
.gate-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.gate-tabs .tab {
  flex: 1;
  font: inherit;
  background: transparent;
  color: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}
.gate-tabs .tab.active {
  color: #1a140c;
  background: linear-gradient(180deg, #e0c792, #b8955c);
  border-color: transparent;
}
.gate-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--paper-dim);
  margin-bottom: 0.35rem;
}
.gate-form input {
  width: 100%;
  font: inherit;
  color: var(--paper);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.9rem;
}
.gate-form button[type="submit"] {
  width: 100%;
  font: inherit;
  font-weight: 600;
  color: #1a140c;
  background: linear-gradient(180deg, #e0c792, #b8955c);
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  cursor: pointer;
}
.gate-note {
  font-size: 0.85rem;
  color: var(--paper-dim);
  margin: 0.9rem 0 0;
  line-height: 1.45;
}
.gate-msg {
  margin-top: 1.1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  line-height: 1.4;
}
.gate-msg.ok { border-color: rgba(212, 184, 132, 0.45); color: var(--gold); }
.gate-msg.err { border-color: rgba(196, 107, 90, 0.5); color: var(--danger); }
.mast-actions { display: flex; gap: 0.6rem; align-items: center; }
.mast-actions button,
.mast-actions .mast-link {
  font: inherit;
  font-size: 0.8rem;
  color: var(--paper-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  text-decoration: none;
}
.gate-wide { max-width: 520px; }
.gate-form textarea,
.gate-form select,
.gate-form input[type="file"] {
  width: 100%;
  font: inherit;
  color: var(--paper);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.9rem;
}
.gate-form textarea { resize: vertical; min-height: 4.5rem; }
.gate-form select { appearance: auto; }
.gate-msg { white-space: pre-wrap; }
