/* ============================================================
   XAMMAR v2 — Design System
   Keeps the v1 spirit (ink / paper / magenta, bold type, pills)
   but rebuilt as a single coherent system: tokens, one app shell,
   reusable components, organic radii and fluid motion.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,900&family=Playfair+Display:wght@600;700;800;900&family=Inter:wght@400;500;600;700;900&display=swap");

:root {
  /* ---- Color ---- */
  --ink: #0d0d0d;
  --ink-soft: #3a3a3a;
  --muted: #8a857c;
  --paper: #f4f2ec;          /* warm off-white */
  --paper-2: #ebe8e0;
  --white: #ffffff;
  --accent: #ff0080;
  --accent-ink: #c8147d;
  --line: rgba(13, 13, 13, 0.12);
  --line-soft: rgba(13, 13, 13, 0.07);
  --on-dark: #f4f2ec;

  /* ---- Type ---- */
  --font-display: "Fraunces", Georgia, serif;
  --font-headline: "Playfair Display", Georgia, serif;  /* journalistic headlines */
  --font-ui: "Inter", system-ui, sans-serif;

  /* ---- Space scale ---- */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px; --s9: 96px;

  /* ---- Radius ---- */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-xl: 32px;
  --r-pill: 999px;

  /* ---- Elevation ---- */
  --shadow-sm: 0 1px 3px rgba(13, 13, 13, 0.06);
  --shadow-md: 0 6px 24px rgba(13, 13, 13, 0.08);
  --shadow-lg: 0 18px 50px rgba(13, 13, 13, 0.14);

  /* ---- Motion ---- */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 0.28s;
  --dur-slow: 0.55s;

  /* ---- Layout ---- */
  --header-h: 76px;
  --maxw: 1180px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--accent); color: var(--white); }

/* ============================================================
   App shell + header
   ============================================================ */

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 0 var(--s6);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  z-index: 100;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.app-header.on-dark {
  background: color-mix(in srgb, var(--ink) 80%, transparent);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.brand {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 26px;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
  transition: color var(--dur) var(--ease);
}
.on-dark .brand { color: var(--on-dark); }

.header-spacer { flex: 1; }

.header-actions { display: flex; align-items: center; gap: var(--s3); }

/* ---- Icon / pill buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 46px;
  padding: 0 22px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease), transform 0.12s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn:active { transform: scale(0.97); }
.btn svg { width: 20px; height: 20px; }

.btn.icon { width: 46px; padding: 0; }

.btn.accent { border-color: var(--accent); background: var(--accent); color: var(--white); }
.btn.accent:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn.lg { height: 58px; padding: 0 36px; font-size: 17px; }

.on-dark .btn { border-color: var(--on-dark); color: var(--on-dark); }
.on-dark .btn:hover { background: var(--on-dark); color: var(--ink); }
.on-dark .btn.accent { border-color: var(--accent); background: var(--accent); color: var(--white); }

/* ---- Ghost select styled like a pill ---- */
.pill-select {
  height: 46px;
  padding: 0 40px 0 20px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 16px center;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.pill-select:hover {
  background-color: var(--ink); color: var(--paper);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2'><polyline points='6 9 12 15 18 9'/></svg>");
}
.pill-select:focus { outline: none; }

/* ============================================================
   View system — one template, cross-fade between routes
   ============================================================ */

.view {
  display: none;
  padding-top: var(--header-h);
  min-height: 100vh;
  animation: viewIn var(--dur-slow) var(--ease-out);
}
.view.active { display: block; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: var(--s7) var(--s6); }

/* ============================================================
   HOME (hero)
   ============================================================ */

#view-home { background: var(--ink); color: var(--on-dark); position: relative; overflow: hidden; }
#view-home::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: url("assets/image.png") right 18% / cover no-repeat;
  filter: grayscale(1);
}
#view-home::after {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(90deg, var(--ink) 0%, rgba(13,13,13,0.94) 32%, rgba(13,13,13,0.55) 66%, rgba(13,13,13,0.32) 100%);
}
#view-home .hero { position: relative; z-index: 1; }
#view-home .btn:not(.accent) { border-color: var(--on-dark); color: var(--on-dark); }
#view-home .btn:not(.accent):hover { background: var(--on-dark); color: var(--ink); }

.hero {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s7) var(--s6) var(--s9);
}
.hero-kicker {
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: var(--s4);
}
.hero-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(72px, 15vw, 200px);
  line-height: 0.9;
  letter-spacing: -0.03em;
}
.hero-tagline {
  margin-top: var(--s4);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(18px, 2.4vw, 31px);
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.hero-tagline em { font-style: italic; color: var(--accent); }
.hero-sub {
  margin-top: var(--s5);
  font-size: clamp(17px, 2vw, 21px);
  color: rgba(244, 242, 236, 0.72);
  max-width: 54ch;
}
.hero-cta { margin-top: var(--s7); display: flex; gap: var(--s4); flex-wrap: wrap; }

/* ============================================================
   WRITE
   ============================================================ */

.write-grid {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: var(--s8);
  align-items: start;
}
.write-intro-kicker {
  font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent); font-weight: 600; margin-bottom: var(--s3);
}
.write-intro h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(36px, 5vw, 60px);
  line-height: 1;
  letter-spacing: -0.02em;
}
.write-intro p { margin-top: var(--s5); font-size: 18px; color: var(--ink-soft); max-width: 40ch; }

.field { margin-bottom: var(--s4); }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
  margin-bottom: var(--s2);
}
.field input, .field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s4) var(--s5);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  resize: vertical;
}
.field input::placeholder, .field textarea::placeholder { color: #b7b2a8; }
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
}
.field textarea { min-height: 220px; line-height: 1.55; }

/* ============================================================
   COMPOSER (modular editor) + authorship grammar
   ============================================================ */

.composer-wrap { max-width: 860px; }
.composer-head { margin-bottom: var(--s7); }
.composer-title {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(36px, 5vw, 60px); line-height: 1; letter-spacing: -0.02em;
}
.composer-sub { margin-top: var(--s4); font-size: 18px; color: var(--ink-soft); max-width: 62ch; }
.composer-sub strong { color: var(--ink); font-weight: 700; }

.blocks { display: flex; flex-direction: column; gap: var(--s4); }

/* a block card in the canvas */
.cblock {
  background: var(--white);
  border: 1.5px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.cblock-locked { border-left-color: var(--ink); }
.cblock-unlocked { border-left-color: var(--accent); border-left-style: dashed; }

.cblock-bar {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3) var(--s2) var(--s4);
  border-bottom: 1px solid var(--line-soft);
  background: var(--paper);
}
.cblock-name { font-weight: 700; font-size: 14px; flex: 1; }
.cblock-kind {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 9px; border-radius: var(--r-pill); margin-left: var(--s2);
}
.cblock-locked .cblock-kind { background: var(--ink); color: var(--paper); }
.cblock-unlocked .cblock-kind { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-ink); }

.cblock-tools { display: flex; align-items: center; gap: 2px; }
.cblock-tool {
  width: 30px; height: 30px; border-radius: 8px;
  border: none; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.cblock-tool:hover { background: var(--paper-2); color: var(--ink); }
.cblock-tool:disabled { opacity: 0.22; pointer-events: none; }
.cblock-tool svg { width: 16px; height: 16px; }

.cblock-body { padding: var(--s4); }
.cblock-body textarea, .cblock-body input {
  width: 100%; font-family: inherit; color: var(--ink);
  background: transparent; border: none; resize: vertical; line-height: 1.6;
}
.cblock-body textarea::placeholder, .cblock-body input::placeholder { color: #b7b2a8; }
.cblock-body textarea:focus, .cblock-body input:focus { outline: none; }
.cblock-input-title { font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: -0.01em; }
.cblock-input-lead { font-size: 18px; min-height: 64px; font-family: var(--font-display); }
.cblock-para { font-size: 17px; min-height: 96px; }

/* light formatting toolbar */
.blk-edit { display: flex; flex-direction: column; gap: var(--s2); }
.fmt-bar { display: flex; gap: 4px; }
.fmt-btn {
  min-width: 30px; height: 28px; padding: 0 9px;
  border: 1px solid var(--line); background: var(--paper); border-radius: 7px;
  font-size: 13px; color: var(--ink); line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.fmt-btn:hover { background: var(--ink); color: var(--paper); }
.gen-tools { display: flex; gap: var(--s4); align-items: center; margin-top: var(--s3); flex-wrap: wrap; }

/* WYSIWYG contenteditable surface */
.rte { outline: none; min-height: 1.6em; line-height: 1.6; }
.rte:empty::before { content: attr(data-placeholder); color: #b7b2a8; }
.rte p { margin: 0 0 var(--s3); }
.rte p:last-child { margin-bottom: 0; }
.rte ul { margin: var(--s2) 0 var(--s2) var(--s5); }
.rte li { margin-bottom: var(--s1); }
.rte strong { font-weight: 700; }
.rte .source-ref { cursor: pointer; }

.cblock-gen-empty { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: 14.5px; }
.cblock-gen-out { font-size: 17px; line-height: 1.65; }
.cblock-gen-out p { margin-bottom: var(--s3); }
.cblock-gen-out p:last-child { margin-bottom: 0; }
.gen-btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: 40px; padding: 0 18px; border-radius: var(--r-pill);
  border: 1.5px dashed var(--accent); background: transparent; color: var(--accent-ink);
  font-weight: 600; font-size: 14px; transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.gen-btn:hover { background: var(--accent); color: var(--white); border-style: solid; }
.gen-btn svg { width: 16px; height: 16px; }
.regen-link { margin-top: var(--s3); font-size: 13px; color: var(--accent-ink); font-weight: 600; background: none; border: none; padding: 0; }
.regen-link:hover { text-decoration: underline; }
.concept-edit { margin-left: var(--s4); color: var(--ink-soft); }

/* concept editor (Explicació de conceptes block) */
.concept-editor { display: flex; flex-direction: column; gap: var(--s2); }
.concept-row { display: flex; align-items: center; gap: var(--s2); }
.concept-term {
  flex: 1; font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 14px;
}
.concept-term:focus { outline: none; border-color: var(--accent); background: var(--white); }
.concept-add { align-self: flex-start; background: none; border: none; color: var(--accent-ink); font-weight: 600; font-size: 13px; padding: 4px 0; }
.concept-add:hover { text-decoration: underline; }
.concept-cta { display: flex; gap: var(--s3); align-items: center; margin-top: var(--s2); flex-wrap: wrap; }
.gen-btn.gen-go { border-style: solid; background: var(--accent); color: var(--white); }
.gen-btn.gen-go:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.concept-hint { color: var(--muted); font-size: 13px; }

.composer-actions { display: flex; gap: var(--s4); margin-top: var(--s6); flex-wrap: wrap; align-items: center; }
.add-block-btn { border-style: dashed; }
.reset-btn { margin-left: auto; border-color: var(--line); color: var(--muted); }
.reset-btn:hover { background: var(--muted); color: var(--paper); border-color: var(--muted); }
.reset-btn.armed { border-color: var(--accent); color: var(--accent); }
.reset-btn.armed:hover { background: var(--accent); color: var(--white); border-color: var(--accent); }

/* ---- Palette sheet (figure 8.2) ---- */
.palette-sheet { max-width: 900px; max-height: 84vh; overflow-y: auto; }
.palette-banner {
  text-align: center; font-size: 13px; font-weight: 600; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--r-md);
  padding: var(--s3); margin-bottom: var(--s5);
}
.palette-banner span { display: block; color: var(--accent-ink); }
.palette-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.pal-item {
  text-align: left; padding: var(--s4); border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--white);
  transition: border-color var(--dur) var(--ease), transform 0.12s var(--ease), box-shadow var(--dur) var(--ease);
}
.pal-item:not(.soon):hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pal-item-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.pal-item-name { font-weight: 700; font-size: 15px; }
.pal-item-desc { font-size: 12.5px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.pal-tag { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.pal-item.author .pal-tag { background: var(--ink); color: var(--paper); }
.pal-item.rag .pal-tag { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-ink); }
.pal-item.soon { opacity: 0.6; }
.pal-item.soon .pal-tag { background: var(--paper-2); color: var(--muted); }

/* ---- Authorship spine (composed reading preview) ---- */
.aut-block { position: relative; padding-left: var(--s5); margin-bottom: var(--s6); }
.aut-block::before {
  content: ""; position: absolute; left: 0; top: 5px; bottom: 5px; width: 3px; border-radius: 3px;
}
.aut-locked::before { background: var(--ink); }
.aut-unlocked::before {
  background: repeating-linear-gradient(var(--accent) 0 5px, transparent 5px 11px);
  cursor: pointer;
}
.aut-foot {
  margin-top: var(--s2); font-size: 12.5px; font-weight: 600; color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 6px;
}
.aut-foot .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ============================================================
   ARTICLE LIST
   ============================================================ */

.list-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--s6); gap: var(--s4); flex-wrap: wrap; }
.list-title {
  font-family: var(--font-display);
  font-weight: 900; font-size: clamp(32px, 5vw, 52px);
  letter-spacing: -0.02em; line-height: 1;
}
.list-meta { color: var(--muted); font-size: 15px; }

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s5);
}
.card {
  background: var(--white);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex; flex-direction: column;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease);
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.card-img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: var(--paper-2); display: block; }
.card-body { padding: var(--s4) var(--s5) var(--s5); display: flex; flex-direction: column; gap: var(--s2); flex: 1; }
.card-date { font-size: 12.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.card-title { font-family: var(--font-headline); font-weight: 700; font-size: 21px; line-height: 1.22; letter-spacing: -0.005em; }

.pagination { display: flex; align-items: center; justify-content: center; gap: var(--s5); margin: var(--s8) 0 var(--s5); }
.pag-info { font-size: 15px; color: var(--muted); }
.pag-btn { width: 46px; height: 46px; }
.pag-btn[disabled] { opacity: 0.3; pointer-events: none; }

.loading-row { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: var(--s8) 0; font-size: 16px; }

/* ============================================================
   ARTICLE DETAIL / RESULT (shared "reader" template)
   ============================================================ */

#view-reader { background: var(--white); }
.reader { max-width: 760px; margin: 0 auto; padding: var(--s7) var(--s6) var(--s9); }
.reader-cover {
  width: 100%; aspect-ratio: 16/9; object-fit: cover;
  background: var(--paper-2); margin-bottom: var(--s6);
}
.reader-date { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin-bottom: var(--s3); }
.reader-title {
  font-family: var(--font-headline);
  font-weight: 900; font-size: clamp(34px, 5.5vw, 56px);
  line-height: 1.05; letter-spacing: -0.01em; margin-bottom: var(--s4);
}
.reader-lead { font-size: 21px; line-height: 1.5; color: var(--ink-soft); margin-bottom: var(--s6); font-family: var(--font-display); font-weight: 400; }
.reader-body { font-size: 18.5px; line-height: 1.72; }
.reader-body p { margin-bottom: var(--s5); }
.reader-body ul { margin: var(--s4) 0 var(--s5) var(--s5); }
.reader-body li { margin-bottom: var(--s2); }
.reader-body strong { font-weight: 700; }

.reader-caret::after {
  content: "▋"; color: var(--accent); margin-left: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 0%,50% { opacity: 1 } 50.1%,100% { opacity: 0 } }

/* ---- Source chips ---- */
.source-ref {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; padding: 0 6px; margin: 0 1px;
  border-radius: var(--r-pill);
  background: var(--accent); color: var(--white);
  font-family: var(--font-ui); font-size: 11px; font-weight: 700;
  vertical-align: super; cursor: pointer; text-decoration: none;
  transition: background var(--dur) var(--ease), transform 0.12s var(--ease);
}
.source-ref:hover { background: var(--accent-ink); transform: translateY(-1px); }

.sources-panel {
  margin-top: var(--s7);
  padding: var(--s6);
  background: var(--paper);
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
}
.sources-panel h4 {
  font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); margin-bottom: var(--s4); font-weight: 700;
}
.source-item { display: flex; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--line-soft); }
.source-item:first-of-type { border-top: none; }
.source-num { color: var(--accent); font-weight: 700; font-size: 14px; flex-shrink: 0; }
.source-info { display: flex; flex-direction: column; gap: 2px; }
.source-title { font-weight: 600; font-size: 15.5px; line-height: 1.35; text-decoration: none; }
.source-title:hover { color: var(--accent); }
.source-date { font-size: 12.5px; color: var(--muted); }

/* ---- Floating tooltip ---- */
.source-tooltip {
  position: absolute; z-index: 1000; max-width: 340px;
  padding: var(--s4); background: var(--ink); color: var(--on-dark);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 1.45; pointer-events: none;
}
.source-tooltip .t-title { font-weight: 700; margin-bottom: var(--s2); }
.source-tooltip .t-snip { color: rgba(244,242,236,0.7); margin-bottom: var(--s2); }
.source-tooltip .t-url { color: var(--accent); font-size: 11px; word-break: break-all; }

/* ============================================================
   Reader options (time / expertise) — bottom sheet on first read
   ============================================================ */

.sheet-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(13, 13, 13, 0.55);
  backdrop-filter: blur(4px);
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-overlay.active { display: flex; animation: fadeIn var(--dur) var(--ease); }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  width: 100%; max-width: 640px;
  background: var(--paper);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--s7) var(--s6) var(--s8);
  animation: sheetUp var(--dur-slow) var(--ease-out);
}
@keyframes sheetUp { from { transform: translateY(100%) } to { transform: none } }
.sheet h3 { font-family: var(--font-display); font-weight: 600; font-size: 26px; margin-bottom: var(--s5); letter-spacing: -0.01em; }
.sheet-step + .sheet-step { margin-top: var(--s6); }
.choice-row { display: flex; gap: var(--s3); flex-wrap: wrap; }
.choice {
  flex: 1; min-width: 120px;
  height: 56px; border-radius: var(--r-md);
  border: 1.5px solid var(--ink); background: transparent;
  font-weight: 600; font-size: 16px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform 0.12s var(--ease);
}
.choice:hover, .choice.selected { background: var(--ink); color: var(--paper); }
.choice:active { transform: scale(0.97); }

/* About = centered modal, not a bottom sheet */
#aboutSheet { align-items: center; padding: var(--s6); }
#aboutSheet .sheet {
  max-width: 520px;
  border-radius: var(--r-xl);
  animation: sheetPop var(--dur) var(--ease-out);
}
@keyframes sheetPop { from { opacity: 0; transform: scale(0.96) } to { opacity: 1; transform: none } }

/* ============================================================
   LOGIN
   ============================================================ */

.login-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: var(--ink);
  display: none; align-items: center; justify-content: center;
  padding: var(--s6);
}
.login-overlay.active { display: flex; }
.login-card {
  width: 100%; max-width: 420px; text-align: center;
}
.login-card .brand { font-size: 44px; display: block; margin-bottom: var(--s2); color: var(--on-dark); }
.login-card .login-tag { color: rgba(244,242,236,0.6); margin-bottom: var(--s7); }
.login-card input {
  width: 100%; height: 54px; padding: 0 var(--s5);
  background: rgba(255,255,255,0.06); border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: var(--r-md); color: var(--on-dark); font-size: 16px; font-family: inherit;
  margin-bottom: var(--s3);
}
.login-card input::placeholder { color: rgba(244,242,236,0.4); }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button { width: 100%; margin-top: var(--s3); }
.login-error { color: var(--accent); font-size: 14px; margin-top: var(--s4); min-height: 20px; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
  .write-grid { grid-template-columns: 1fr; gap: var(--s6); }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .app-header { padding: 0 var(--s4); }
  .wrap { padding: var(--s6) var(--s4); }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .brand { font-size: 22px; }
  .btn { height: 42px; padding: 0 16px; font-size: 14px; }
  .btn.icon { width: 42px; }
  .header-actions { gap: var(--s2); }
  /* Reading detail: the time/knowledge selectors are the priority; drop the
     back button so both fit (use the browser/OS back gesture instead). */
  .header-actions .reader-back { display: none; }
  .pill-select { height: 42px; font-size: 12px; padding: 0 28px 0 12px; background-position: right 9px center; }
}

/* ============================================================
   PRINT — article only, with its styling (Save as PDF)
   ============================================================ */
@media print {
  .app-header, .header-actions, .composer-actions, .gen-tools, .fmt-bar,
  .sheet-overlay, .login-overlay, .pagination { display: none !important; }
  body { background: #fff !important; }
  .view { display: none !important; padding-top: 0 !important; min-height: 0 !important; animation: none !important; }
  .view.active { display: block !important; }
  #view-reader { background: #fff !important; }
  .reader { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
  .reader-cover { max-height: 70mm; }
  .aut-block::before, .source-ref, .reader-date, .hero-tagline em {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .aut-foot { color: #555 !important; }
  a { text-decoration: none; color: inherit; }
  @page { margin: 16mm; }
}
