/* ============================================================================
   Book Studio - shared look.
   Paper by day, the ops room at 3:12 a.m. by night. One green dot: the tower.
   ========================================================================== */
:root {
  --paper: #f5f0e6; --paper-2: #fbf8f1; --paper-3: #ece5d6;
  --ink: #1c2229; --ink-2: #4a5561; --ink-3: #7d8792;
  --rule: #ddd4c2; --rule-2: #e9e2d3;
  --accent: #1f6f5c; --accent-2: #2f9b7d; --accent-soft: #dcefe7;
  --signal: #c7831f; --signal-soft: #f7e7c9;
  --danger: #b4412f; --danger-soft: #f6dcd5;
  --quiet: #5b5f9a; --quiet-soft: #e3e3f3;
  --shadow: 0 1px 0 rgba(28,34,41,.05), 0 10px 30px -18px rgba(28,34,41,.45);
  --radius: 12px;
  --ui: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  --display: 'Fraunces', Georgia, serif;
  --read: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  color-scheme: light;
}
[data-theme="night"] {
  --paper: #0f1519; --paper-2: #151d22; --paper-3: #1c262c;
  --ink: #e3e8eb; --ink-2: #a9b4bb; --ink-3: #74818a;
  --rule: #26333a; --rule-2: #1f2a30;
  --accent: #4fd1a5; --accent-2: #3fbf8f; --accent-soft: #163a31;
  --signal: #e9ac4c; --signal-soft: #3b2e17;
  --danger: #ef7a66; --danger-soft: #3d1f1a;
  --quiet: #a6a9ee; --quiet-soft: #24264a;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 12px 30px -16px rgba(0,0,0,.8);
  color-scheme: dark;
}
[data-theme="sepia"] {
  --paper: #f1e6d0; --paper-2: #f7eedc; --paper-3: #e7d9bd; --ink: #3b2f22; --ink-2: #6b5a46; --rule: #d8c6a4;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--ui); font-size: 15px; color: var(--ink); background: var(--paper); line-height: 1.5;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -.01em; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 30px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 600; }
h3 { font-size: 17px; font-weight: 600; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; letter-spacing: .02em; }
.mono { font-family: var(--mono); }
.eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------- controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 9px;
  border: 1px solid var(--rule); background: var(--paper-2); cursor: pointer; font-size: 14px; font-weight: 500;
  text-decoration: none; color: var(--ink); white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover:not(:disabled) { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="night"] .btn.primary { color: #06120e; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--paper-3); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn .ico, svg.ico { width: 16px; height: 16px; flex: none; }
.btn { min-width: 0; }
.grid2 > .btn, .grid3 > .btn { justify-content: center; white-space: normal; text-align: center; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--rule); border-radius: 9px; background: var(--paper-2);
  font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.55; }
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; user-select: none; }
.switch input { appearance: none; width: 32px; height: 18px; border-radius: 99px; background: var(--rule); position: relative;
  cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--paper-2); transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 16px; }

.card { min-width: 0; background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px;
  border-radius: 99px; background: var(--paper-3); color: var(--ink-2); white-space: nowrap; }
.pill.green { background: var(--accent-soft); color: var(--accent); }
.pill.amber { background: var(--signal-soft); color: var(--signal); }
.pill.red { background: var(--danger-soft); color: var(--danger); }
.pill.quiet { background: var(--quiet-soft); color: var(--quiet); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); display: inline-block; box-shadow: 0 0 0 3px var(--accent-soft); }

.toast-wrap { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
  animation: rise .2s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--rule); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 8px; background: var(--paper-3); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent-2); border-radius: 99px; transition: width .4s; }

/* --------------------------------------------------------------- prose */
.prose { font-family: var(--read); font-size: 19px; line-height: 1.65; }
.prose p { margin: 0 0 1em; }
.prose h1, .prose h2, .prose h3 { font-family: var(--display); margin: 1.4em 0 .5em; }
.prose blockquote { margin: 1em 0; padding: 2px 0 2px 16px; border-left: 3px solid var(--rule); color: var(--ink-2); }
.prose hr { border: 0; text-align: center; margin: 1.6em 0; }
.prose hr::after { content: '⁂'; color: var(--ink-3); letter-spacing: .3em; }
.prose table { border-collapse: collapse; font-family: var(--ui); font-size: 14px; margin: 1em 0; width: 100%; }
.prose th, .prose td { border: 1px solid var(--rule); padding: 6px 9px; text-align: left; vertical-align: top; }
.prose th { background: var(--paper-3); }
.prose code { font-family: var(--mono); font-size: .85em; background: var(--paper-3); padding: 1px 5px; border-radius: 4px; }
.prose pre { background: var(--paper-3); padding: 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose.ui { font-family: var(--ui); font-size: 14.5px; line-height: 1.6; }
.prose.ui h1 { font-size: 22px; } .prose.ui h2 { font-size: 18px; } .prose.ui h3 { font-size: 15.5px; }

/* ------------------------------------------------------------- modal */
.modal-back { position: fixed; inset: 0; background: rgba(10,14,18,.45); z-index: 500; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 20px;
  animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { max-width: 100%; justify-self: center; background: var(--paper-2); border-radius: 14px; border: 1px solid var(--rule); box-shadow: var(--shadow); width: min(560px, 100%);
  max-height: calc(100vh - 40px); overflow: auto; padding: 22px; }
.modal.wide { width: min(980px, 100%); }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------- offline */
.netpill { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 900; background: var(--ink); color: var(--paper);
  font-size: 12.5px; padding: 6px 14px; border-radius: 99px; box-shadow: var(--shadow); white-space: nowrap; }
.netpill::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--signal); margin-right: 8px; vertical-align: 1px; }

/* The co-author is switched off unless an API key is set. */
.no-ai .ai-only { display: none !important; }
