* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--rk-paper);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.014) 1px, transparent 1px),
    var(--rk-paper);
  background-size: 26px 26px, 26px 26px, auto;
  color: var(--rk-ink);
  font-family: var(--rk-font-body);
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.rk-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 144px minmax(0, 1fr);
}

.rk-rail {
  position: sticky;
  inset-block-start: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-inline-end: 1px solid var(--rk-line);
  background: var(--rk-rail-bg);
  padding-block: 34px 28px;
  z-index: 4;
}

.rk-main {
  min-width: 0;
  padding: 40px 56px 34px 36px;
}

/* Home starts on the rail wordmark's centerline: 18px + 58px / 2 = 47px, matching the
   26px-tall logo at the rail's 34px inset. Other V3 workspaces keep their existing top rhythm. */
@media (min-width: 1021px) {
  .rk-main:has(.rk-home-grid) {
    padding-block-start: 18px;
  }
}

.rk-content {
  max-width: 1360px;
  margin-inline: auto;
}

.rk-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 24px;
  row-gap: 12px;
  margin-block-end: 34px;
}

.rk-topbar-left {
  min-inline-size: 0;
  display: flex;
  align-items: center;
}

.rk-home-grid {
  display: grid;
  gap: 22px;
}

.rk-home-grid > * {
  min-inline-size: 0;
}

.rk-hero {
  display: grid;
  justify-items: center;
  gap: 18px;
  text-align: center;
}

.rk-shelf-section {
  margin-block-start: 2px;
  /* paint above the sticky rail so the plank's left overhang crosses the hairline like the mock */
  position: relative;
  z-index: 5;
}

.rk-section-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-block-end: 10px;
}

.rk-continue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

/* Keep the home header and creation-mode tabs on the same compact rhythm on short laptops.
   Shelf-only spacing remains scoped below so non-picture-book modes keep their own workspaces. */
@media (min-width: 1021px) and (max-height: 760px) {
  .rk-main:has(.rk-home-grid) {
    padding-block-start: 12px;
    padding-block-end: 20px;
  }

  .rk-content:has(> .rk-home-grid) > .rk-topbar.has-home-greeting {
    min-block-size: 48px;
    margin-block-end: 10px;
  }

  .rk-home-grid {
    gap: 12px;
  }

  .rk-home-grid .rk-hero {
    gap: 10px;
  }

  .rk-home-grid:has(.rk-shelf-section:not([hidden])) .rk-shelf-section {
    margin-block-start: 0;
  }

  .rk-home-grid:has(.rk-shelf-section:not([hidden])) .rk-section-header {
    margin-block-end: 4px;
  }
}

@media (max-width: 1020px) {
  .rk-shell {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .rk-main {
    padding: 28px 26px 30px;
  }

  .rk-topbar {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .rk-topbar.has-home-greeting {
    margin-block-end: 16px;
  }

  .rk-top-actions {
    justify-self: start;
  }

  .rk-continue-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .rk-shell {
    display: block;
  }

  .rk-rail {
    min-height: auto;
    position: fixed;
    inset-block: auto 0;
    inset-inline: 0;
    /* Keep the fixed mobile navigation above shelf content while leaving desktop stacking intact. */
    z-index: 40;
    flex-direction: row;
    justify-content: flex-start;
    gap: 0;
    border-inline-end: 0;
    border-block-start: 1px solid var(--rk-line);
    padding-block: 8px 10px;
    padding-inline: 8px;
    background: rgba(250, 248, 244, 0.98);
  }

  .rk-main {
    padding: 14px 16px 126px;
  }

  .rk-content {
    max-width: none;
  }

  .rk-section-header {
    align-items: start;
    flex-direction: column;
    gap: 4px;
  }

  .rk-topbar.has-home-greeting {
    margin-block-end: 14px;
  }

  .rk-home-grid {
    gap: 18px;
  }

  .rk-shelf-section {
    margin-block-start: 2px;
    margin-block-end: 168px;
  }
}

/* ── Chromeless immersive shell (storybook creation: thinking + co-creation). No rail, no topbar,
   no corner home icon — full-bleed content that sits high on the page. Used by renderBareShell(). ── */
.rk-bare {
  min-height: 100vh;
  background: var(--rk-paper);
}
.rk-bare-main {
  min-height: 100vh;
  padding: 24px 40px 40px;
}
@media (max-width: 680px) {
  .rk-bare-main {
    padding: 18px 16px 24px;
  }
}

/* ── 让位给全站置顶运营通栏（2026-08-10）──────────────────────────────────
   通栏是 sticky，自身高度已经在文档流里，所以页面内容天然从它下面开始——**不需要**给 body 补偏移。
   要补的只有两类元素：
     ① 同样 sticky 到视口顶端的东西（左侧栏、账户/书架页的页头）——不下移就会滚到通栏底下被盖住；
     ② 写死 100vh 的容器——不减去通栏高度，整页会凭空多出一条与通栏等高的滚动。
   `--rk-opsbar-h` 由 lib/ops-strip.js 实测写入（文案换行时高度会变，配 ResizeObserver 跟随）。
   没有通栏时 `.rk-has-opsbar` 不存在，下面所有规则一条都不生效——这是「空态零成本」的兑现处。 */
.rk-has-opsbar .rk-rail {
  inset-block-start: var(--rk-opsbar-h, 0px);
  min-height: calc(100vh - var(--rk-opsbar-h, 0px));
}

.rk-has-opsbar .rk-shell,
.rk-has-opsbar .rk-bare,
.rk-has-opsbar .rk-bare-main {
  min-height: calc(100vh - var(--rk-opsbar-h, 0px));
}

/* The story co-creation desk is a viewport-owned workspace: prose and page-plan columns scroll
   internally while their refine/continue controls stay at the lower edge. Once the sticky ops strip
   enters normal flow, a full 100dvh story page would make the document one strip-height too tall and
   carry both controls with the outer scrollbar. Budget the strip into the workspace height instead. */
.rk-has-opsbar .sb-flow-page {
  height: calc(100vh - var(--rk-opsbar-h, 0px));
  height: calc(100dvh - var(--rk-opsbar-h, 0px));
}

/* 账户页与书架页把自己的页头钉在视口顶端（各自 css 里 inset-block-start: 0）。这里的选择器多一层
   祖先类，特异性更高，所以与那两个文件的加载顺序无关。 */
.rk-has-opsbar .rk-content:has(.account-page) > .rk-topbar,
.rk-has-opsbar .rk-content:has(.works-page) > .rk-topbar {
  inset-block-start: var(--rk-opsbar-h, 0px);
}
