/* Novel line — home tab panel (P0).
 *
 * Scope: everything here is inside #novel-home-panel. The top bar, greeting and mode-tab row belong
 * to the existing home page and must not be restyled from this file.
 *
 * Only --rk-* tokens. The single emerald appears in exactly three places on this screen: the primary
 * button, the progress fill, and the focus ring. */

/* The writing Pudding GIF is an opaque 200px bitmap. Its edge pixels are exactly #f8f5f0, so every
 * novel loading dialog inherits one measured matte instead of maintaining several almost-equal
 * paper colours that expose the GIF as a rectangular sticker. */
:root { --nv-loading-matte: #f8f5f0; }

.nv-home-panel {
  display: block;
  inline-size: 100%;
  margin-block-start: 8px;
  /* The home page centres its hero text, and this panel inherited it — which put the resume card's
   * title, chapter line and word count on the centre axis while the progress bar and buttons stayed
   * on the left edge of the same column. Two axes in one card is exactly the "混乱" Andy saw. The
   * concept art is left-aligned throughout; declare it here rather than per element, so nothing new
   * added to this panel silently inherits centring again. */
  text-align: start;
}
/* An author `display` rule outranks the UA's [hidden] — without this pair the panel stays visible
 * when JS sets .hidden = true. (freestyle §20 铁律 1; only asserting el.hidden is a false positive.) */
.nv-home-panel[hidden] { display: none; }

/* Same trap, other direction: `.composer { display: flex }` kept the shared story composer on screen
 * in Novel mode even with the hidden attribute set. Caught in the browser, not by the attribute
 * assertion — always verify with getComputedStyle. Scoped by [hidden], so no other tab is affected
 * (nothing else ever sets that attribute on the composer). */
.composer[hidden] { display: none; }

/* Regression repair, caused by this feature: the mode-tab row fits five pills but not six (measured
 * natural width 805px), and the existing horizontal-scroll affordance for it only starts at 680px —
 * so adding Novel pushed the row, and with it the whole page, past the viewport from ~681px up to
 * ~959px.
 *
 * This does NOT restyle the row and needs no breakpoint: `inline-flex` still sizes to its content,
 * so wherever six pills fit the row is byte-identical to before. `max-inline-size` only engages when
 * they do not, and then the row scrolls inside itself instead of pushing the page. A first attempt
 * used a 681–940px band and was wrong — the real threshold is 959px, and any fixed number would
 * break again the day a label is translated longer or a seventh tab lands. */
.sb-mode-tabs {
  max-inline-size: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.sb-mode-tabs::-webkit-scrollbar { display: none; }
.sb-mode-tab { flex: 0 0 auto; }

/* ── the book object ───────────────────────────────────────────────────────
 * A novel is TALLER and MUCH THICKER than a picture book, its cover mostly plain cloth with the
 * title set on it. That contrast is what makes the two formats tellable apart on one shelf.
 *
 * Built from four physical parts, because a flat coloured rectangle reads as a tile and a shelf of
 * tiles is not a shelf: the SPINE (left, darker, carries the title vertically the way a real book
 * does), the FACE (cloth, lit from the top-left), the FORE-EDGE (right, the page block), and a
 * CONTACT SHADOW on the ground under it. The shadow lives on the outer wrapper because the inner
 * block clips its own contents. */
.nv-book {
  position: relative;
  display: inline-block;
  inline-size: 96px;
  block-size: 136px;
  isolation: isolate;
}
.nv-book.is-large { inline-size: 172px; block-size: 244px; }

/* The ground shadow: an object standing on a surface, not floating over one. */
.nv-book::after {
  content: "";
  position: absolute;
  inset-inline: 6%;
  inset-block-end: -7px;
  block-size: 12px;
  border-radius: 50%;
  background: var(--rk-book-contact-shadow);
  filter: blur(7px);
  opacity: 0.5;
  z-index: -1;
}
.nv-book.is-large::after { inset-block-end: -10px; block-size: 18px; filter: blur(11px); }

.nv-book-block {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 2px 5px 5px 2px;
  background: var(--nv-cloth, #3a3f55);
  box-shadow: var(--rk-shadow-object);
  overflow: hidden;
}

/* The board thickness, with the title running up it — the single strongest "this is a novel" cue. */
.nv-book-spine {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  inline-size: 13px;
  display: grid;
  place-items: center;
  padding-block: 10px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.42), rgba(255, 255, 255, 0.14) 55%, rgba(0, 0, 0, 0.26));
}
.nv-book.is-large .nv-book-spine { inline-size: 22px; padding-block: 18px; }

.nv-book-spine-text {
  writing-mode: vertical-rl;
  max-block-size: 100%;
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0.08em;
  color: rgba(255, 248, 232, 0.62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nv-book.is-large .nv-book-spine-text { font-size: 11px; letter-spacing: 0.1em; }

/* The cloth face. The light comes from the top-left, consistently with the shelf's book objects. */
.nv-book-face {
  position: absolute;
  inset: 0;
  inset-inline: 13px 5px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 12px 9px;
  background:
    linear-gradient(150deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 42%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0) 38%);
}
.nv-book.is-large .nv-book-face { inset-inline: 22px 8px; padding: 26px 20px; gap: 12px; }

/* The fore-edge: the page block seen from the side. */
.nv-book-edge {
  position: absolute;
  inset-block: 2px;
  inset-inline-end: 0;
  inline-size: 5px;
  background:
    repeating-linear-gradient(90deg, var(--rk-page-edge-a) 0 1px, var(--rk-page-edge-b) 1px 2px);
  box-shadow: inset 2px 0 3px -2px rgba(0, 0, 0, 0.4);
}
.nv-book.is-large .nv-book-edge { inline-size: 8px; inset-block: 3px; }

/* Cloth binding: two thin rules with the title between them. Restrained on purpose — this is what
 * keeps a novel readable as a novel next to the picture books' full-bleed covers. */
.nv-book-rule {
  inline-size: 62%;
  block-size: 1px;
  background: rgba(255, 248, 232, 0.34);
}
.nv-book-printed {
  color: rgba(255, 251, 242, 0.94);
  font-size: 11px;
  line-height: 1.34;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.nv-book.is-large .nv-book-printed { font-size: 18px; line-height: 1.3; -webkit-line-clamp: 5; }

/* A cover image is an INSET, never full-bleed (module-ext-novel §小说封面纪律). */
.nv-book-inset {
  inline-size: 78%;
  aspect-ratio: 4 / 3;
  margin-block-start: 2px;
  border: 1px solid rgba(255, 248, 232, 0.28);
  overflow: hidden;
}
.nv-book-inset img { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; }

/* ── resume card ──────────────────────────────────────────────────────────
 * The main event. A novelist returning is continuing, not choosing. */
.nv-resume {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 44px;
  align-items: center;
  padding: 34px 40px;
  background: var(--rk-surface);
  border: 1px solid var(--rk-line);
  border-radius: var(--rk-radius-lg);
  box-shadow: var(--rk-shadow-card);
}
.nv-resume-book { display: grid; place-items: center; padding: 4px 12px 10px; }
/* Every level unlocks its intrinsic minimum, or a long title pushes the card wider than the page
 * (freestyle §16 长标题布局铁律 — clamping only the text node is not enough). */
.nv-resume-body { min-inline-size: 0; }

.nv-resume-title {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1.2;
  font-weight: 700;
  color: var(--rk-ink);
  overflow-wrap: anywhere;
}
.nv-resume-chapter { margin: 8px 0 0; font-size: 17px; color: var(--rk-ink-soft); overflow-wrap: anywhere; }
.nv-resume-words { margin: 12px 0 0; font-size: 16px; color: var(--rk-ink-soft); }

.nv-progress {
  margin-block-start: 10px;
  inline-size: min(100%, 420px);
  block-size: 5px;
  border-radius: 999px;
  background: var(--rk-progress-track);
  overflow: hidden;
}
.nv-progress-fill { display: block; block-size: 100%; background: var(--rk-emerald); }
.nv-resume-progress { margin: 8px 0 0; font-size: 14px; color: var(--rk-ink-muted); }

.nv-resume-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-block-start: 20px; }

/* ── buttons ──────────────────────────────────────────────────────────────*/
.nv-btn {
  min-block-size: 44px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid var(--rk-line);
  background: var(--rk-surface);
  color: var(--rk-ink);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}
.nv-btn:hover { background: var(--rk-paper-2); }
.nv-btn.is-primary { background: var(--rk-emerald); border-color: var(--rk-emerald); color: #fff; }
.nv-btn.is-primary:hover { background: var(--rk-emerald-hover); border-color: var(--rk-emerald-hover); }
.nv-btn.is-danger { border-color: var(--rk-danger); color: var(--rk-danger); }
.nv-btn.is-danger:hover { background: var(--rk-danger); color: #fff; }
.nv-btn:disabled { opacity: 0.6; cursor: default; }

/* A second way out of a dialog that must never compete with the first. */
.nv-textlink {
  margin-block-start: 14px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--rk-ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--rk-line);
  cursor: pointer;
}
.nv-textlink:hover { color: var(--rk-ink); text-decoration-color: var(--rk-ink-muted); }
.nv-btn:focus-visible,
.nv-shelf-book:focus-visible,
.nv-new-slot:focus-visible,
.nv-empty-input:focus-visible {
  outline: 2px solid var(--rk-emerald);
  outline-offset: 2px;
}

/* ── shelf row ────────────────────────────────────────────────────────────*/
.nv-shelf { margin-block-start: 28px; }
.nv-shelf-label {
  margin: 0 0 14px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--rk-ink-muted);
}
.nv-shelf-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nv-shelf-item { position: relative; min-inline-size: 0; }

.nv-shelf-book {
  display: grid;
  justify-items: center;
  gap: 10px;
  inline-size: 100%;
  min-inline-size: 0;
  padding: 8px 4px 12px;
  border: 0;
  border-radius: var(--rk-radius);
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: center;
}
.nv-shelf-book:hover { background: var(--rk-paper-2); }
.nv-shelf-title {
  max-inline-size: 100%;
  font-size: 15px;
  font-weight: 600;
  color: var(--rk-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nv-shelf-words { font-size: 13px; color: var(--rk-ink-muted); }

/* Delete lives on hover/focus, not on the surface: throwing away a novel should take a deliberate
 * move, and a row of permanent bins turns a bookshelf into a file manager. Keyboard users reach it
 * by tabbing (`:focus-within` keeps it visible while it is the focused element). */
.nv-shelf-del {
  position: absolute;
  inset-block-start: 2px;
  inset-inline-end: 2px;
  display: grid;
  place-items: center;
  inline-size: 30px;
  block-size: 30px;
  padding: 0;
  border: 1px solid var(--rk-line);
  border-radius: 50%;
  background: var(--rk-surface);
  color: var(--rk-ink-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.nv-shelf-item:hover .nv-shelf-del,
.nv-shelf-item:focus-within .nv-shelf-del { opacity: 1; }
.nv-shelf-del:hover { color: var(--rk-danger); border-color: var(--rk-danger); }
.nv-shelf-del:focus-visible { opacity: 1; outline: 2px solid var(--rk-emerald); outline-offset: 2px; }
.nv-shelf-del svg { inline-size: 15px; block-size: 15px; stroke-width: 1.6; }

/* Confirm in place. A modal for "are you sure" over a thumbnail is heavier than the act itself. */
.nv-shelf-confirm {
  position: absolute;
  inset-block-start: 0;
  inset-inline: -6px;
  z-index: 3;
  display: grid;
  gap: 10px;
  padding: 14px 12px;
  border: 1px solid var(--rk-line);
  border-radius: var(--rk-radius);
  background: var(--rk-surface);
  box-shadow: var(--rk-shadow-panel);
  text-align: center;
}
.nv-shelf-confirm p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--rk-ink); }
.nv-shelf-confirm-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.nv-shelf-confirm .nv-btn { min-block-size: 34px; padding: 0 14px; font-size: 14px; }

/* Deliberately quiet: coming back to write is the common case, starting over is not. */
.nv-new-slot {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 10px;
  inline-size: 100%;
  min-block-size: 174px;
  padding: 12px;
  border: 1px dashed var(--rk-line);
  border-radius: var(--rk-radius);
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--rk-ink-muted);
  cursor: pointer;
}
.nv-new-slot:hover { border-color: var(--rk-ink-muted); color: var(--rk-ink-soft); }
.nv-new-plus svg { inline-size: 22px; block-size: 22px; stroke-width: 1.6; }

/* ── empty state — the ONLY place this tab shows an input ─────────────────*/
.nv-empty {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 24px 16px 40px;
  text-align: center;
}
.nv-empty-art { inline-size: 200px; block-size: auto; margin-block-end: 4px; }
.nv-empty-title { margin: 0; font-size: clamp(22px, 2.2vw, 30px); font-weight: 700; color: var(--rk-ink); }
.nv-empty-sub { margin: 8px 0 0; font-size: 16px; color: var(--rk-ink-soft); max-inline-size: 46ch; }

.nv-empty-form {
  display: flex;
  gap: 10px;
  align-items: center;
  inline-size: min(100%, 620px);
  margin-block-start: 22px;
  padding: 8px 8px 8px 18px;
  background: var(--rk-surface);
  border: 1px solid var(--rk-line);
  border-radius: var(--rk-radius-lg);
  box-shadow: var(--rk-shadow-card);
}
.nv-empty-input {
  flex: 1 1 auto;
  min-inline-size: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 17px;
  color: var(--rk-ink);
}
.nv-empty-input::placeholder { color: var(--rk-ink-muted); }
.nv-empty-form .nv-btn { flex: 0 0 auto; }
.nv-chapter-count {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 8px;
  margin-block-start: 14px;
  color: var(--rk-ink-soft);
  font-size: 13px;
  text-align: start;
}
.nv-empty-form .nv-chapter-count { flex: 0 0 150px; margin-block-start: 0; }
.nv-chapter-count select {
  min-inline-size: 52px;
  padding: 6px 24px 6px 8px;
  border: 1px solid var(--rk-line);
  border-radius: var(--rk-radius-sm);
  background: var(--rk-paper);
  color: var(--rk-ink);
  font: inherit;
}
.nv-chapter-count small { grid-column: 1 / -1; color: var(--rk-ink-muted); line-height: 1.35; }

.nv-empty-error { margin: 12px 0 0; font-size: 15px; color: var(--rk-danger); max-inline-size: 52ch; }

/* ── the "start a new novel" dialog ───────────────────────────────────────
 * Two doors, asked out loud. Before this, clicking the quiet slot silently chose "blank sheet" for
 * the author — which is the wrong default for most people and, worse, was never presented as a
 * choice at all. */
.nv-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(43, 42, 38, 0.3);
  text-align: start;
}
.nv-modal-card {
  position: relative;
  inline-size: min(100%, 560px);
  max-block-size: 86vh;
  overflow-y: auto;
  padding: 30px 30px 26px;
  background: var(--rk-surface);
  border-radius: var(--rk-radius-lg);
  box-shadow: var(--rk-shadow-panel);
}
.nv-modal-card.is-narrow {
  inline-size: min(100%, 380px);
  display: grid;
  justify-items: center;
  text-align: center;
  background: var(--nv-loading-matte);
}
.nv-modal-close {
  position: absolute;
  inset-block-start: 14px;
  inset-inline-end: 14px;
  display: grid;
  place-items: center;
  inline-size: 34px;
  block-size: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--rk-ink-muted);
  cursor: pointer;
}
.nv-modal-close:hover { background: var(--rk-paper-2); color: var(--rk-ink); }
.nv-modal-close svg { inline-size: 18px; block-size: 18px; }

.nv-modal-title { margin: 0; padding-inline-end: 34px; font-size: 24px; font-weight: 700; color: var(--rk-ink); }
.nv-modal-sub { margin: 8px 0 0; font-size: 16px; line-height: 1.55; color: var(--rk-ink-soft); }
.nv-modal-error { margin: 12px 0 0; font-size: 15px; line-height: 1.5; color: var(--rk-danger); }
.nv-modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-block-start: 18px; }

.nv-choices { display: grid; gap: 12px; margin-block-start: 22px; }
.nv-choice {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--rk-line);
  border-radius: var(--rk-radius);
  background: var(--rk-surface);
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}
.nv-choice:hover { border-color: var(--rk-emerald); background: var(--rk-paper); }
.nv-choice:focus-visible { outline: 2px solid var(--rk-emerald); outline-offset: 2px; }
.nv-choice-art { flex: 0 0 auto; border-radius: 50%; }
.nv-choice-icon { flex: 0 0 auto; display: grid; place-items: center; inline-size: 40px; block-size: 40px; color: var(--rk-ink-soft); }
.nv-choice-icon svg { inline-size: 24px; block-size: 24px; stroke-width: 1.5; }
.nv-choice-text { display: grid; gap: 4px; min-inline-size: 0; }
.nv-choice-name { font-size: 17px; font-weight: 600; color: var(--rk-ink); }
.nv-choice-desc { font-size: 14px; line-height: 1.5; color: var(--rk-ink-soft); }

.nv-premise-input {
  inline-size: 100%;
  margin-block-start: 18px;
  padding: 14px 16px;
  border: 1px solid var(--rk-line);
  border-radius: var(--rk-radius);
  background: var(--rk-paper);
  font: inherit;
  font-size: 17px;
  line-height: 1.6;
  color: var(--rk-ink);
  resize: vertical;
}
.nv-premise-input::placeholder { color: var(--rk-ink-muted); }
.nv-premise-input:focus-visible { outline: 2px solid var(--rk-emerald); outline-offset: 1px; }

/* The one moment the mascot is allowed on this screen. The whole busy card now owns the measured
 * GIF matte, so the bitmap can sit directly on it without a framed sticker boundary. */
.nv-modal-art {
  display: block;
  inline-size: 150px;
  block-size: auto;
  padding: 0;
  border: 0;
  background: var(--nv-loading-matte);
}
.nv-modal-busy { margin: 10px 0 0; font-size: 17px; font-weight: 600; color: var(--rk-ink); }
.nv-modal-wait { margin: 6px 0 0; font-size: 14px; color: var(--rk-ink-muted); }

/* Every network-backed novel control acknowledges the click in the same event turn. The content is
 * made transparent rather than replaced, so labels, icons, button widths, and narrow layouts never
 * jump while a request is in flight. Static buttons receive position:relative from the JS helper;
 * already-positioned controls keep their original absolute/fixed geometry. */
button[data-novel-action-busy="true"] {
  --nv-action-spinner-track: rgba(82, 73, 63, 0.24);
  --nv-action-spinner-head: #5e5449;
  color: transparent !important;
  text-shadow: none !important;
  cursor: progress !important;
  opacity: 0.9 !important;
}
button[data-novel-action-busy="true"] > * { opacity: 0 !important; }
button[data-novel-action-busy="true"]::after {
  content: '';
  position: absolute;
  z-index: 2;
  inset-block-start: 50%;
  left: 50%;
  inline-size: 16px;
  block-size: 16px;
  box-sizing: border-box;
  border: 2px solid var(--nv-action-spinner-track);
  border-block-start-color: var(--nv-action-spinner-head);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: nv-action-spin 0.72s linear infinite;
  pointer-events: none;
}
button:is(.is-primary, .is-danger, .nvx-primary)[data-novel-action-busy="true"] {
  --nv-action-spinner-track: rgba(255, 255, 255, 0.38);
  --nv-action-spinner-head: #fff;
}
input[data-novel-action-busy="true"] { cursor: progress !important; opacity: 0.64; }
@keyframes nv-action-spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

/* ── loading / error ──────────────────────────────────────────────────────*/
.nv-loading { padding: 24px 0; }
.nv-skeleton {
  display: block;
  block-size: 236px;
  border-radius: var(--rk-radius-lg);
  background: linear-gradient(90deg, var(--rk-paper-2) 25%, var(--rk-surface) 50%, var(--rk-paper-2) 75%);
  background-size: 220% 100%;
  animation: nv-shimmer 1.4s ease-in-out infinite;
}
@keyframes nv-shimmer { from { background-position: 120% 0; } to { background-position: -20% 0; } }
@media (prefers-reduced-motion: reduce) {
  .nv-skeleton,
  button[data-novel-action-busy="true"]::after { animation: none; }
}

.nv-error { display: grid; justify-items: center; gap: 14px; padding: 48px 16px; text-align: center; }
.nv-error p { margin: 0; color: var(--rk-ink-soft); }

/* ── responsive ───────────────────────────────────────────────────────────*/
@media (max-width: 720px) {
  .nv-resume { grid-template-columns: 1fr; gap: 20px; padding: 22px 20px; justify-items: center; text-align: center; }
  .nv-resume-body { inline-size: 100%; }
  .nv-progress { margin-inline: auto; }
  .nv-resume-actions { justify-content: center; }
  .nv-shelf-row { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; }
  .nv-book { inline-size: 78px; block-size: 112px; }
  .nv-new-slot { min-block-size: 150px; }
  .nv-empty-form { flex-wrap: wrap; padding: 12px; }
  .nv-empty-input { inline-size: 100%; padding-inline: 6px; }
  .nv-empty-form .nv-btn { inline-size: 100%; }
  .nv-empty-form .nv-chapter-count { flex-basis: 100%; }
}
