/* ============================================================================================
   scroll.css — themed scrollbars + header controls that never sit under a scroller (2026-10-12).
   Owner: "mấy thanh cuộn này thấy xấu quá, nút X này cũng lỗi" — the native Windows scrollbar
   (white track, grey thumb, arrow buttons, ~15 px) showed inside every modal, ate the right edge
   and, as an overlay bar, sat over the header ✕ / ? and right-aligned values.
   Loaded LAST so it wins over every earlier sheet. CSS only.
   ============================================================================================ */

#game {
  --sb-thumb: #d9b77266;        /* gold ~40 % */
  --sb-thumb-hi: #f0d08fb3;     /* hover / drag */
  --sb-size: 4px;
  --sb-fade: 22px;              /* soft edge on inner scroll bodies */
}

/* ---- 1. Chromium / Safari: a slim 4 px gold thumb on a transparent track, no arrow buttons.
   An explicit ::-webkit-scrollbar width also switches off Windows' overlay bar, which is what
   painted over the ✕ and clipped "240 / 280 XP". Chrome ≥121 ignores these pseudo-elements as soon
   as scrollbar-width / scrollbar-color are set, so the standard properties below are reset to auto
   for Chromium and only used by Firefox. */
#game ::-webkit-scrollbar { width: var(--sb-size); height: var(--sb-size); background: transparent; }
#game ::-webkit-scrollbar-track, #game ::-webkit-scrollbar-track-piece { background: transparent; border: 0; box-shadow: none; }
#game ::-webkit-scrollbar-thumb { background: var(--sb-thumb); border: 0; border-radius: 99px; min-height: 28px; }
#game ::-webkit-scrollbar-thumb:hover, #game ::-webkit-scrollbar-thumb:active { background: var(--sb-thumb-hi); }
#game ::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
#game ::-webkit-scrollbar-corner { background: transparent; }

@supports selector(::-webkit-scrollbar) {
  /* earlier sheets set these (brief-scroll: thin + track colour) — in Chrome they re-enable the
     native thin bar with arrows, so hand control back to the pseudo-elements above. */
  #game *, #game .brief .brief-scroll { scrollbar-width: auto; scrollbar-color: auto; }
  /* hidden-scrollbar regions stay hidden */
  #game .map-scroll { scrollbar-width: none; }
}
/* ---- Firefox: standard properties only. */
@supports not selector(::-webkit-scrollbar) {
  #game * { scrollbar-width: thin; scrollbar-color: var(--sb-thumb) transparent; }
  #game .map-scroll { scrollbar-width: none; }
}

/* ---- 2. Inner scroll bodies: a soft top/bottom fade says "more below" instead of a heavy bar.
   Driven by the element's own scroll position, so the top edge is crisp at the start and the
   bottom edge is crisp at the end; an element that does not overflow has an inactive timeline and
   no mask at all. Never on .panel itself (the mask would also fade its painted frame) and never on
   a body that holds an absolutely placed ✕ (.bd: a mask clips every descendant to its box). */
@property --sb-fade-t { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --sb-fade-b { syntax: '<length>'; inherits: false; initial-value: 0px; }
@keyframes sbFade {
  0%   { --sb-fade-t: 0px; --sb-fade-b: var(--sb-fade); }
  10%  { --sb-fade-t: var(--sb-fade); }
  90%  { --sb-fade-b: var(--sb-fade); }
  100% { --sb-fade-t: var(--sb-fade); --sb-fade-b: 0px; }
}
@supports (animation-timeline: scroll()) {
  #game .brief .brief-scroll, #game .well-body, #game .book-body, #game .odds-scroll, #game .hist-list {
    -webkit-mask-image: linear-gradient(#0000, #000 var(--sb-fade-t), #000 calc(100% - var(--sb-fade-b)), #0000);
            mask-image: linear-gradient(#0000, #000 var(--sb-fade-t), #000 calc(100% - var(--sb-fade-b)), #0000);
    animation: sbFade linear both; animation-timeline: scroll(self block);
  }
}

/* ---- 3. Header controls: above the title, never under the scroller, one 36 px round family.
   The title (h2, positioned by the forged type) is later in the DOM and covered the centre of the
   ✕ and ? in Camp and Saga — the click landed on the heading ("nút X lỗi"). */
/* Pinned while the panel scrolls: the .panel IS the scroll container, so an absolute ✕ scrolled away
   with the content. Make the controls sticky blocks at the top of the scroller instead: each is a
   36 px block right-aligned with margin-left:auto and a -36 px bottom margin so it takes no height
   (the title rises to the same line); sticky keeps it 8 px under the scrollport top at every scroll
   position. DOM order is ✕, ?, h2, so the ? sits one slot (44 px) left of the ✕. */
#game .panel > .close-x, #game .camp-panel > .camp-help {
  position: sticky; top: 8px; inset-inline: auto; bottom: auto; z-index: 4; display: grid;
  width: 36px; height: 36px; min-width: 36px; min-height: 36px;
  margin: calc(var(--sb-pull-y, 0px) * -1) calc(var(--sb-pull-x, 0px) * -1) calc(var(--sb-pull-y, 0px) - 36px) auto; }
#game .camp-panel > .camp-help { margin-right: calc(44px - var(--sb-pull-x, 0px)); }
/* pull the pair up/right into the panel padding, where the absolute versions used to sit */
#game .panel { --sb-pull-x: 8px; --sb-pull-y: 8px; }
#game .panel > .close-x ~ h2 { padding-right: 40px; }
#game .camp-panel > .close-x ~ h2 { padding-right: 84px; }
#game .quest-panel > .close-x ~ .quest-titlebar, #game .quest-panel > .close-x ~ .eyebrow { padding-right: 40px; }
/* Quest journal joins the family (it was a borderless 44 px glyph next to the round Camp/Saga ✕). */
#game .quest-panel > .close-x { border: 1px solid #c9a86a66; border-radius: 50%; background: #0b1413e6; color: #e8d39e; }
#game .quest-panel > .close-x .ui-icon { width: 15px; height: 15px; }
#game .panel > .close-x:hover, #game .camp-panel .camp-help:hover { border-color: #e3bf78; color: #fff1cf; }
#game .panel > .close-x:active, #game .camp-panel .camp-help:active { transform: scale(.94); filter: brightness(.85); }

/* Companion detail sheet: the ✕ lived inside the scrolling .bd at right:-8px, which both scrolled
   it away and pushed a horizontal scrollbar under the actions. Anchor it to the (non-scrolling)
   sheet card instead: .bd stops being the containing block. */
#game .bd { position: static; overflow-x: hidden; }
#game .bd > .v2-sheet-close { top: 6px; right: max(6px, env(safe-area-inset-right)); z-index: 3; }

/* ---- 4. No horizontal scroll anywhere in a panel: a vertical scroller with overflow-x left at
   auto turned a 1 px overhang into a second bar. */
#game .panel, #game .well-body, #game .book-body, #game .odds-scroll, #game .hist-list, #game .tipbox { overflow-x: hidden; }
#game .brief.panel { overflow: hidden; }
#game .cs-tile.cs-level > small:last-child { white-space: nowrap; }

/* ---- 5. Norn's Well: the decorative glow (top 46 % + height 62 % = 108 %) overhung the scroll body
   and created ~58 px of phantom scroll at 412×915. End it at the body's bottom edge. */
#game .well-body::before { height: auto; bottom: 0; }
