/* =====================================================================
   Rulebook: search on the left, the printed page on the table at right.
   ===================================================================== */
.rulebook { display: flex; flex-direction: column; gap: 1.2rem; }
.rb-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.rb-head h1 { margin: 0 0 .3rem; }
.rb-head p { margin: 0; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }

/* search field */
.rb-search { display: flex; align-items: center; gap: .6rem; padding: .35rem .5rem .35rem .9rem; background: var(--input); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow); }
.rb-search:focus-within { border-color: var(--gilt); box-shadow: var(--shadow), 0 0 0 3px var(--focus); }
.rb-search > .ico { color: var(--muted); width: 1.35rem; height: 1.35rem; }
.rb-search input { flex: 1; min-width: 0; border: 0; background: none; box-shadow: none !important; font-size: 1.15rem; padding: .55rem .2rem; }
.rb-search select { width: auto; max-width: 40%; border-radius: var(--r-sm); }

/* status cards (uploading, reading, admin controls) */
#rb-status { display: flex; flex-direction: column; gap: .6rem; }
#rb-status:empty { display: none; }
.rb-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; margin: 0; }
.rb-card-txt { display: flex; flex-direction: column; gap: .2rem; flex: 1; min-width: 0; }
.rb-card.failed { border-color: var(--bad); }
.rb-prog { display: block; height: 6px; border-radius: 3px; background: var(--line2); overflow: hidden; margin-top: .35rem; max-width: 520px; }
.rb-prog i { display: block; height: 100%; width: 0; background: var(--gilt); transition: width .4s ease; }

.rb-empty { text-align: center; padding: 2.4rem 1.5rem; }
.rb-empty p { max-width: 58ch; margin-inline: auto; }
.rb-drop { display: flex; flex-direction: column; gap: .3rem; align-items: center; justify-content: center; margin: 1.2rem auto 0; max-width: 520px; min-height: 150px;
  border: 2px dashed var(--line); border-radius: var(--r-lg); cursor: pointer; background: var(--panel2); transition: border-color .15s, background .15s; }
.rb-drop:hover, .rb-drop.over { border-color: var(--gilt); background: color-mix(in srgb, var(--gilt) 10%, var(--panel2)); }
.rb-drop strong { font-family: var(--head); font-size: 1.2rem; }

/* layout */
.rbw { display: flex; flex-direction: column; gap: 1rem; }
.rb-grid { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.rb-list { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; padding-right: .3rem; }
.rbw:not(.reading) .rb-grid { grid-template-columns: minmax(0, 720px); }
.rb-back { display: none; }

/* results */
.rb-count { margin: 0 0 .4rem .2rem; }
.rb-hits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.rb-hit { display: flex; flex-direction: column; gap: .25rem; width: 100%; text-align: left; font: inherit; color: var(--ink); background: none;
  border: 1px solid transparent; border-radius: var(--radius); padding: .65rem .75rem; cursor: pointer; transition: background .12s, border-color .12s; }
.rb-hit:hover { background: var(--panel2); }
.rb-hit.on { background: var(--panel); border-color: var(--gilt); box-shadow: var(--shadow); }
.rb-hit-top { display: flex; align-items: baseline; gap: .6rem; }
.rb-hit-top b { font-family: var(--head); font-size: 1.05rem; color: var(--accent); }
.rb-hit-top span { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-snip { color: color-mix(in srgb, var(--ink) 82%, var(--muted)); font-size: .93rem; line-height: 1.45; }
.rb-snip mark, .rb-text mark { background: color-mix(in srgb, var(--gilt) 34%, transparent); color: inherit; border-radius: 2px; padding: 0 .08em; }

/* chapters */
.rb-book { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; padding: 0 .2rem .6rem; border-bottom: 1px solid var(--line2); margin-bottom: .4rem; }
.rb-book strong { font-family: var(--head); font-size: 1.15rem; }
.rb-toc { list-style: none; margin: 0; padding: 0; columns: 2 220px; column-gap: 1.2rem; }
.rb-toc li { break-inside: avoid; }
.rb-toc button { display: flex; justify-content: space-between; gap: .8rem; width: 100%; text-align: left; font: inherit; color: var(--ink); background: none; border: 0;
  border-radius: var(--r-sm); padding: .42rem .55rem; cursor: pointer; }
.rb-toc button:hover { background: var(--panel2); }
.rb-toc .lv1 button { font-weight: 700; }
.rb-toc .lv2 button { padding-left: 1.4rem; color: var(--muted); font-size: .93rem; }
.rb-toc-p { color: var(--muted); font-size: .82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rbw.reading .rb-toc { columns: 1; }

/* viewer: the page lies on the table */
.rb-view { display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
.rb-bar { display: flex; align-items: center; gap: .5rem .9rem; flex-wrap: wrap; }
.rb-where { display: flex; flex-direction: column; line-height: 1.15; margin-right: auto; min-width: 0; }
.rb-where strong { font-family: var(--head); font-size: 1.25rem; }
.rb-where span { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-nav, .rb-tools { display: flex; align-items: center; gap: .3rem; }
.rb-nav .btn { font-size: 1.2rem; line-height: 1; padding: .3rem .7rem; }
.rb-pg { display: flex; align-items: center; gap: .35rem; margin: 0; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.rb-pg input { width: 3.6rem; text-align: center; padding: .3rem; font-variant-numeric: tabular-nums; }
.rb-tools .btn[aria-pressed="true"] { border-color: var(--gilt); color: var(--ink); background: color-mix(in srgb, var(--gilt) 14%, transparent); }

.rb-stage { background: var(--table-bg); border-radius: var(--r-lg); padding: clamp(.8rem, 2vw, 1.6rem); overflow: auto;
  box-shadow: var(--shadow-lg), inset 0 0 0 1px var(--table-line); }
.rb-sheet { position: relative; margin: 0 auto; max-width: min(100%, calc((100vh - 10.5rem) * .773)); }
.rb-sheet img { display: block; width: 100%; height: auto; background: #fbf8f1; border-radius: 2px;
  box-shadow: 0 1px 2px #0006, 0 18px 40px -16px #000c; transition: opacity .15s; min-height: 200px; }
.rbw.loading .rb-sheet img { opacity: .45; }
.rbw.zoomed .rb-sheet { max-width: none; width: 175%; }
.rb-hl { position: absolute; inset: 0; pointer-events: none; }
.rb-hl i { position: absolute; background: #f2c14e; mix-blend-mode: multiply; opacity: .55; border-radius: 2px; outline: 2px solid #f2c14e66;
  animation: rb-hl 1.1s ease-out both; }
@keyframes rb-hl { 0% { opacity: 0; transform: scale(1.6); } 40% { opacity: .75; transform: none; } 100% { opacity: .55; } }
.rb-text { margin: 0 auto; max-width: 75ch; white-space: pre-wrap; font-family: var(--body); font-size: 1rem; line-height: 1.55;
  background: var(--panel); color: var(--ink); padding: 1.2rem 1.4rem; border-radius: var(--radius); max-height: 75vh; overflow: auto; }

/* compact (in the drawer) and phones: list, then a page, with a back button */
.rbw.compact .rb-grid { grid-template-columns: minmax(0, 1fr); gap: .8rem; }
.rbw.compact .rb-list { position: static; max-height: none; overflow: visible; }
.rbw.compact.reading .rb-list { display: none; }
.rbw.compact .rb-back { display: inline-flex; }
.rbw.compact .rb-stage { padding: .6rem; border-radius: var(--radius); }
.rbw.compact .rb-sheet { max-width: 100%; }
.rbw.compact .rb-toc { columns: 1; }
.rbw.compact .rb-search input { font-size: 1rem; }
.rbw.compact .rb-tools .rb-pdf { display: none; }
@media (max-width: 900px) {
  .rb-grid, .rbw:not(.reading) .rb-grid { grid-template-columns: minmax(0, 1fr); }
  .rb-list { position: static; max-height: none; overflow: visible; }
  .rbw.reading .rb-list { display: none; }
  .rb-back { display: inline-flex; }
  .rb-sheet { max-width: 100%; }
  .rb-toc { columns: 1; }
}

/* sidebar search */
.side-search { margin: 0 0 .9rem; }
.side-search label { display: flex; align-items: center; gap: .55rem; padding: .1rem .65rem; border-radius: var(--r-sm); background: var(--side-hover);
  border: 1px solid var(--side-line); color: var(--side-muted); cursor: text; margin: 0; }
.side-search label:focus-within { border-color: var(--side-active); color: var(--side-ink); }
.side-search .ico { width: 1.1rem; height: 1.1rem; }
.side-search input { flex: 1; min-width: 0; background: none; border: 0; box-shadow: none !important; color: var(--side-ink); padding: .5rem 0; font-size: .95rem; }
.side-search input::placeholder { color: var(--side-muted); }
.app.rail .side-search label { justify-content: center; padding: .62rem 0; cursor: pointer; background: none; border-color: transparent; }
.app.rail .side-search input { display: none; }
@media (max-width: 900px) { .app.rail .side-search input { display: block; } .app.rail .side-search label { justify-content: flex-start; padding: .1rem .65rem; } }

/* drawer tabs */
.nd-head { gap: .5rem; }
.nd-tabs { display: flex; gap: 2px; padding: 3px; border-radius: var(--r-sm); background: var(--panel2); border: 1px solid var(--line2); }
.nd-tab { font: inherit; font-weight: 700; font-size: .92rem; border: 0; background: none; color: var(--muted); padding: .35rem .75rem; border-radius: calc(var(--r-sm) - 2px); cursor: pointer; }
.nd-tab.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.notes-drawer { transition: transform .2s ease, width .2s ease; }
.notes-drawer.rules-mode { width: min(560px, 96vw); }
.nd-rules { flex: 1; overflow: auto; margin: 0 -.4rem; padding: 0 .4rem; }
[data-theme="future"] .nd-tab, [data-theme="wasteland"] .nd-tab { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; }

/* themes */
[data-theme="future"] .rb-hl i, [data-theme="wasteland"] .rb-hl i { mix-blend-mode: normal; opacity: .4; }
[data-theme="future"] .rb-hl i { background: #19e3ff; outline-color: #19e3ff88; }
[data-theme="wasteland"] .rb-hl i { background: #7dff5a; outline-color: #7dff5a88; }
[data-theme="wasteland"] .rb-where strong, [data-theme="wasteland"] .rb-hit-top b, [data-theme="wasteland"] .rb-book strong { font-weight: 400; font-size: 1.4rem; }
[data-theme="wasteland"] .rb-sheet img { filter: sepia(.25) contrast(1.05); }
@media print { .rb-search, .rb-list, .rb-bar, #rb-status { display: none !important; } .rb-stage { background: none; box-shadow: none; padding: 0; } }

/* wasteland: drop the CRT lines while a book page is on screen, so the print stays crisp */
[data-theme="wasteland"] body:has(.rb-view:not([hidden]) .rb-sheet:not([hidden]))::after { background: radial-gradient(130% 100% at 50% 50%, transparent 60%, #00000080 100%); }

/* phones: the Notes tab becomes a floating button in the corner instead of covering the page edge */
@media (max-width: 900px) {
  .notes-tab { writing-mode: horizontal-tb; top: auto; bottom: calc(14px + env(safe-area-inset-bottom)); right: 14px; border-radius: 99px;
    padding: .6rem .95rem; border-right-width: 1px; box-shadow: var(--shadow-lg); }
  .notes-tab .ico { transform: none; }
  .page { padding-bottom: 5.5rem; }
}

/* bookmarks */
.rb-mark svg { width: 1rem; height: 1rem; vertical-align: -3px; margin-right: .25rem; }
.rb-mark.on { color: var(--accent); border-color: var(--gilt); }
.rb-mark.on svg { fill: var(--gilt); stroke: var(--gilt); }
.rb-marks { margin-bottom: 1rem; padding-bottom: .6rem; border-bottom: 1px solid var(--line2); }
.rb-sub { font-variant-caps: all-small-caps; letter-spacing: .06em; font-weight: 700; color: var(--muted); padding: 0 .2rem .3rem; }
.rb-marks ul { list-style: none; margin: 0; padding: 0; }
.rb-marks li { display: flex; align-items: center; }
.rb-mark-i { flex: 1; min-width: 0; display: flex; align-items: center; gap: .6rem; text-align: left; font: inherit; color: var(--ink); background: none; border: 0;
  padding: .45rem .55rem; border-radius: var(--r-sm); cursor: pointer; }
.rb-mark-i:hover { background: var(--panel2); }
.rb-mark-i svg { width: 1.05rem; height: 1.05rem; flex: none; fill: var(--gilt); stroke: var(--gilt); }
.rb-mark-i > span { display: flex; flex-direction: column; min-width: 0; }
.rb-mark-i strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.rb-unmark { background: none; border: 0; color: var(--muted); font-size: 1.2rem; padding: .3rem .5rem; cursor: pointer; border-radius: var(--r-sm); }
.rb-unmark:hover { color: var(--bad); background: var(--panel2); }
.n-marks { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line2); }
.n-marks h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.n-mark { display: flex; align-items: center; gap: .3rem; }
.n-mark a { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: .4rem .5rem; border-radius: var(--r-sm); text-decoration: none; color: var(--ink); }
.n-mark a:hover { background: var(--panel2); }
.n-mark strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
