/* layout.css — deck shell, sidebar rail, pager */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- rail ---------- */
.rail {
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.rail-head { padding: 1.15rem 1.15rem .9rem; border-bottom: 1px solid var(--border); }

.brand { display: flex; align-items: center; gap: .6rem; }
.brand-mark {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #12100a;
  border-radius: 8px; font-size: .95rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text b { font-size: .92rem; letter-spacing: -.015em; }
.brand-text i {
  font-style: normal; font-family: var(--mono);
  font-size: .68rem; letter-spacing: .09em; color: var(--text-3);
}

.rail-progress { margin-top: 1rem; }
.rail-progress .bar {
  height: 4px; border-radius: 99px; background: var(--surface-3); overflow: hidden;
}
.rail-progress .bar span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px; transition: width .45s var(--ease);
}
.rail-progress .meta {
  display: block; margin-top: .45rem;
  font-family: var(--mono); font-size: .68rem; color: var(--text-3);
}
.rail-progress .meta b { color: var(--text-2); font-weight: 500; }

/* ---------- table of contents ---------- */
.toc { flex: 1; overflow-y: auto; padding: .6rem .6rem 1rem; scrollbar-width: thin; }

.toc-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: .5rem .55rem;
  border: 0; background: none; border-radius: var(--r-sm);
  text-align: left; cursor: pointer;
  color: var(--text-2);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.toc-item:hover { background: var(--surface-2); color: var(--text); }

.toc-item .idx {
  font-family: var(--mono); font-size: .7rem;
  width: 22px; height: 22px; border-radius: 5px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-3);
  border: 1px solid transparent;
  transition: all .15s var(--ease);
}
.toc-item .t {
  font-size: .845rem; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-item .m { font-family: var(--mono); font-size: .66rem; color: var(--text-3); }

.toc-item[data-done="1"] .idx {
  background: var(--up-bg); color: var(--up);
}
.toc-item[aria-current="true"] { background: var(--accent-bg); color: var(--text); }
.toc-item[aria-current="true"] .idx {
  background: var(--accent); color: #12100a; border-color: var(--accent);
}
.toc-item[aria-current="true"] .t { font-weight: 620; }

.toc-rule {
  margin: .55rem .55rem .35rem;
  padding-top: .55rem;
  border-top: 1px solid var(--border);
  font-family: var(--mono); font-size: .62rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--text-3);
}
.toc-rule:first-child { border-top: 0; padding-top: .2rem; margin-top: .2rem; }

.rail-foot {
  display: flex; gap: .4rem; padding: .7rem .85rem;
  border-top: 1px solid var(--border);
}

/* ---------- main stage ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.main:focus { outline: none; }

.stage {
  flex: 1;
  /* generous bottom padding: the pager is sticky and would otherwise sit on
     top of the last block of every module */
  padding: clamp(1.5rem, 1rem + 2.6vw, 3.6rem) clamp(1.1rem, .6rem + 2.4vw, 3.2rem) 5rem;
  max-width: 1180px; width: 100%; margin: 0 auto;
}

.module { animation: rise .38s var(--ease) both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

.module-head { margin-bottom: 2rem; }
.module-head .eyebrow { display: flex; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.module-head .eyebrow .dur {
  color: var(--accent); border: 1px solid var(--border-2);
  padding: .1rem .42rem; border-radius: 99px; letter-spacing: .06em;
}
.module-head h1 { margin-bottom: .8rem; text-wrap: balance; }

.block { margin-top: 2.4rem; }
.block > h2 { margin-bottom: .55rem; text-wrap: balance; }
.block > h2 + .lede { margin-bottom: 1.2rem; }
.block > p + * { margin-top: 1.1rem; }

/* Explicit column counts, not auto-fit.
   auto-fit derives the column count from available width, so `.grid-4` could
   render 5 columns and a six-item row would orphan one instead of wrapping to
   a clean 4 + 2. Fixed counts make row alignment predictable, and the
   breakpoints below step them down rather than letting width decide. */
.grid-2, .grid-3, .grid-4 { display: grid; min-width: 0; }
.grid-2 { gap: 1rem;   grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { gap: .85rem; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { gap: .7rem;  grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 940px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- pager ---------- */
.pager {
  position: sticky; bottom: 0;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 1rem;
  padding: .7rem clamp(1.1rem, .6rem + 2.4vw, 3.2rem);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.pager-btn {
  display: flex; align-items: center; gap: .7rem;
  padding: .5rem .8rem; max-width: 340px;
  background: none; border: 1px solid transparent; border-radius: var(--r);
  cursor: pointer; color: var(--text-2); text-align: left;
  transition: all .15s var(--ease);
}
.pager-btn:hover:not(:disabled) { background: var(--surface); border-color: var(--border); color: var(--text); }
.pager-btn:disabled { opacity: .3; cursor: default; }
.pager-btn.next { justify-self: end; flex-direction: row; text-align: right; }
.pager-btn .dir { font-size: 1.05rem; color: var(--text-3); flex: none; }
.pager-btn:hover:not(:disabled) .dir { color: var(--accent); }
.pager-btn .lbl { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.pager-btn .lbl i {
  font-style: normal; font-family: var(--mono);
  font-size: .61rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3);
}
.pager-btn .lbl b {
  font-size: .84rem; font-weight: 560;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.pager-dots { display: flex; gap: 5px; }
.pager-dots i {
  width: 6px; height: 6px; border-radius: 99px;
  background: var(--surface-3); cursor: pointer;
  transition: all .2s var(--ease);
}
.pager-dots i[data-done="1"] { background: var(--up); opacity: .55; }
.pager-dots i[data-on="1"] { background: var(--accent); width: 18px; opacity: 1; }

/* ---------- boot ---------- */
.boot {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-content: center; justify-items: center; gap: .9rem;
  background: var(--bg); color: var(--text-3);
  font-family: var(--mono); font-size: .78rem; letter-spacing: .05em;
  transition: opacity .3s var(--ease);
}
.boot.gone { opacity: 0; pointer-events: none; }
.spin {
  width: 22px; height: 22px; border-radius: 99px;
  border: 2px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: static; height: auto;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .toc {
    display: flex; gap: .4rem; overflow-x: auto; padding: .6rem .8rem;
    scroll-snap-type: x proximity;
  }
  .toc-item { width: auto; flex: none; grid-template-columns: auto auto; scroll-snap-align: start; }
  .toc-item .t { max-width: 148px; }
  .toc-item .m, .toc-rule { display: none; }
  .rail-foot { display: none; }
  .pager-btn .lbl { display: none; }
  .pager { grid-template-columns: auto 1fr auto; }
  .pager-dots { justify-content: center; }
}
