/* ==========================================================================
   Role-writing guide — player side (guide.php, apply.php tab + "ดูตัวอย่าง")
   and the reading-panel preview in admin/guide.php.
   Layout B "คลังหัวข้อแบบการ์ด" from dev/guide-layouts.html.
     gb-  guide blocks (rendered by includes/guide.php)   gc-  card library
     read / lb  reading panel + lightbox                  ep-  entry points (apply)
   Blocks read tokens, so they work on pearl paper (data-theme="paper") and dark glass.
   ========================================================================== */

/* ---------- placeholder cover art (no cover image) ---------- */
.ph {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ph-bg, linear-gradient(150deg, #2A1A4A, #0F0D16));
}
.ph::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(251, 244, 226, 0.55) 1px, transparent 1.6px),
    radial-gradient(circle, rgba(180, 155, 255, 0.45) 1px, transparent 1.6px);
  background-size: 26px 26px, 41px 41px;
  background-position: 0 0, 13px 17px;
  opacity: 0.45;
}
.ph > img { position: relative; width: 34%; max-width: 7rem; height: auto; object-fit: contain; filter: drop-shadow(0 0 30px rgba(142, 108, 240, 0.6)); }
.ph--v0 { --ph-bg: radial-gradient(50% 60% at 50% 45%, rgba(142, 108, 240, 0.55), transparent 70%), linear-gradient(160deg, #1B1233, #08070C); }
.ph--v1 { --ph-bg: radial-gradient(60% 60% at 50% 35%, rgba(203, 179, 122, 0.5), transparent 70%), linear-gradient(160deg, #2A1A4A, #120E1E 70%); }
.ph--v2 { --ph-bg: radial-gradient(50% 50% at 70% 25%, rgba(141, 179, 255, 0.45), transparent 70%), linear-gradient(170deg, #142246, #0A0F1F); }
.ph--v3 { --ph-bg: radial-gradient(55% 55% at 30% 70%, rgba(95, 211, 154, 0.35), transparent 70%), radial-gradient(40% 40% at 80% 20%, rgba(203, 179, 122, 0.3), transparent 70%), linear-gradient(160deg, #13291F, #08100C); }

/* =====================================================================
   Guide blocks
   ===================================================================== */
.gb-doc { display: flow-root; overflow-wrap: anywhere; }
.gb-doc > :first-child { margin-top: 0; }
.gb-h { margin: var(--sp-6) 0 var(--sp-3); font-size: var(--fs-xl); font-weight: var(--fw-heading-lg); line-height: var(--lh-tight); }
.gb-p { margin: 0 0 var(--sp-4); line-height: 1.85; }
.gb-empty { color: var(--text-muted); }
.gb-ul,
.gb-ol { margin: 0 0 var(--sp-4); padding-inline-start: 1.5rem; line-height: 1.75; }
.gb-ul li + li,
.gb-ol li + li { margin-top: var(--sp-1); }
.gb-ul li::marker { color: var(--primary-text); }
.gb-ol li::marker { color: var(--gold-text); font-weight: var(--fw-semibold); }

/* Readable measure: when the reading panel is wide, text blocks stay ≤ --measure (centred) while
   full-size images, galleries and good/bad comparisons use the whole width. */
.gb-doc { --measure: 46rem; }
.gb-doc > .gb-h,
.gb-doc > .gb-p,
.gb-doc > .gb-ul,
.gb-doc > .gb-ol,
.gb-doc > .gb-callout,
.gb-doc > .gb-divider { max-width: var(--measure); margin-inline: auto; }

/* Click-to-zoom (every guide image is a button that opens the zoom viewer) */
.gb-zoom {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: inherit;
  cursor: zoom-in;
}
.gb-zoom:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.gb-zoom__icon {
  position: absolute;
  inset-inline-end: 0.4rem;
  bottom: 0.4rem;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: rgba(8, 7, 12, 0.72);
  color: #FFFFFF;
  pointer-events: none;
}
.gb-zoom__icon svg.lucide { width: 0.95rem; height: 0.95rem; }

.gb-fig { margin: 0 0 var(--sp-5); }
.gb-fig__media {
  width: fit-content;           /* hug the image: small images are never stretched (no blur) */
  max-width: 100%;
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}
.gb-fig--half .gb-fig__media,
.gb-fig--small .gb-fig__media { width: 100%; }
.gb-fig__media > img { display: block; width: auto; max-width: 100%; height: auto; }
.gb-fig--half .gb-fig__media > img,
.gb-fig--small .gb-fig__media > img { width: 100%; }
.gb-fig figcaption,
.gb-cap { display: flex; gap: var(--sp-2); margin: var(--sp-2) 0 0; font-size: var(--fs-sm); line-height: var(--lh-snug); color: var(--text-muted); }
.gb-fig figcaption svg.lucide,
.gb-cap svg.lucide { flex-shrink: 0; width: 1rem; height: 1rem; margin-top: 0.15rem; color: var(--primary-text); }
.gb-fig--small { max-width: 13rem; margin-inline: auto; }
.gb-fig--half.gb-fig--center { max-width: 30rem; margin-inline: auto; }
@media (min-width: 40rem) {
  .gb-fig--half { width: calc(min(100%, var(--measure)) * 0.46); }
  .gb-fig--small { width: calc(min(100%, var(--measure)) * 0.3); max-width: 12rem; }
  /* floats sit at the edge of the text column, not of the (wider) panel */
  .gb-fig--left { float: left; margin: 0.4rem var(--sp-6) var(--sp-4) max(0px, calc((100% - var(--measure)) / 2)); }
  .gb-fig--right { float: right; margin: 0.4rem max(0px, calc((100% - var(--measure)) / 2)) var(--sp-4) var(--sp-6); }
  .gb-fig--half.gb-fig--center { width: calc(min(100%, var(--measure)) * 0.6); max-width: none; }
}

.gb-callout { clear: both; margin: 0 0 var(--sp-5); }
.gb-callout__p { margin: 0; }
.gb-callout__p + .gb-callout__p,
.gb-callout .gb-ul,
.gb-callout .gb-ol { margin-top: var(--sp-2); margin-bottom: 0; }
.alert--tip { --a-fg: var(--gold-text); --a-bg: var(--gold-soft); }

.gb-gal { clear: both; margin: 0 0 var(--sp-5); }
.gb-gal__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
@media (min-width: 30rem) { .gb-gal__grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.gb-gal__item {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface-2);
  cursor: zoom-in;
}
.gb-gal__item > img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform var(--dur-slow) var(--ease); }
.gb-gal__item:hover > img { transform: scale(1.04); }
.gb-gal__item:focus-visible { outline-offset: 2px; }

.cmp { clear: both; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); margin: 0 0 var(--sp-5); }
.cmp__title { display: flex; align-items: center; gap: var(--sp-2); margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-muted); }
.cmp__title svg.lucide { flex-shrink: 0; width: 1.1rem; height: 1.1rem; color: var(--primary-text); }
.cmp__cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); }
@media (min-width: 40rem) { .cmp__cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cmp__col {
  --c: var(--success-text);
  --cbg: var(--success-soft);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
  padding: var(--sp-4);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-top: 3px solid var(--c);
  border-radius: var(--r-lg);
  background: var(--cbg);
}
.cmp__col--bad { --c: var(--danger-text); --cbg: var(--danger-soft); }
.cmp__label { display: flex; align-items: center; gap: var(--sp-2); margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--c); }
.cmp__label svg.lucide { width: 1.15rem; height: 1.15rem; }
.cmp__quote { margin: 0; padding-inline-start: var(--sp-3); border-inline-start: 2px solid color-mix(in srgb, var(--c) 45%, transparent); font-family: var(--font-serif); line-height: 1.8; color: var(--text); }
.cmp__why { font-size: var(--fs-sm); line-height: var(--lh-snug); color: var(--text-muted); }
.cmp__p { margin: 0; }
.cmp__p + .cmp__p { margin-top: var(--sp-2); }
.cmp .gb-ul,
.cmp .gb-ol { margin: var(--sp-1) 0 0; }

.gb-divider { clear: both; margin: var(--sp-6) 0; }

/* =====================================================================
   Card library (layout B)
   ===================================================================== */
.guide-page { padding-top: var(--sp-6); }
.gl { display: flex; flex-direction: column; min-width: 0; }
.gc-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.gc-toolbar__filters { flex: 1 1 20rem; min-width: 0; }
/* Role chips WRAP (a handful of roles): no hidden horizontal scroller that clips the active chip
   at the edge of the narrow apply.php scroll column. Overrides the scrolling .chips base. */
.gc-roles { flex-wrap: wrap; max-width: 100%; overflow: visible; padding: 0.125rem 0; }
.gc-roles .chip {
  flex: 0 1 auto;
  max-width: 100%;
  min-height: var(--tap);
  white-space: normal;          /* a very long role name wraps inside its chip instead of overflowing */
  text-align: center;
  line-height: var(--lh-snug, 1.3);
  padding-block: 0.375rem;
}
.gc-roles .chip:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.gc-search { flex: 0 1 18rem; min-width: 0; width: 100%; }
@media (min-width: 48rem) { .gc-search { width: auto; } }
.gc-search .input { min-height: var(--tap); }
.gc-count { margin: 0 0 var(--sp-4); font-size: var(--fs-sm); color: var(--text-muted); }
.gc-grid { --min: 17rem; --gap: var(--sp-5); margin: 0; padding: 0; list-style: none; }
.gc-card { position: relative; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.gc-card[hidden] { display: none; }
.gc-card:has(.gc-card__btn:focus-visible) { outline: 2px solid var(--ring); outline-offset: 3px; }
.gc-card__cover { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-bottom: 1px solid var(--hairline); background: var(--surface-2); }
.gc-card__cover > img,
.gc-card__cover > .ph { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 0.6s var(--ease); }
.gc-card__cover > .ph { display: grid; }
.gc-card:hover .gc-card__cover > img,
.gc-card:hover .gc-card__cover > .ph { transform: scale(1.04); }
.gc-card__role { position: absolute; top: var(--sp-3); inset-inline-start: var(--sp-3); display: block; max-width: calc(100% - 1.5rem); overflow: hidden; text-overflow: ellipsis; line-height: 1.5rem; box-shadow: 0 4px 14px -4px rgba(0, 0, 0, 0.6); }
.gc-card__body { display: flex; flex-direction: column; gap: var(--sp-2); flex: 1; padding: var(--sp-4) var(--sp-5) var(--sp-5); }
.gc-card__title { margin: 0; font-size: var(--fs-lg); line-height: var(--lh-snug); }
.gc-card__btn { min-height: var(--tap); padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.gc-card__btn::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.gc-card__btn:focus-visible { outline: none; }
.gc-card__desc { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); line-height: var(--lh-snug); }
.gc-card__meta { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); margin: auto 0 0; padding-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-subtle); }
.gc-card__meta span { display: inline-flex; align-items: center; gap: 0.35rem; }
.gc-card__meta svg.lucide { width: 0.95rem; height: 0.95rem; }
.gc-empty[hidden] { display: none; }
.guide-cta { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); margin-top: var(--sp-10); text-align: center; }
.guide-cta p { margin: 0; color: var(--text-muted); }

/* =====================================================================
   Reading panel: modal (desktop) → bottom sheet (<640px, components.css), pearl paper
   ===================================================================== */
.modal[hidden] { display: none; }
.read__head { flex: 1; min-width: 0; }
/* wide on large screens so full-size images (infographics) get ~1000 px; text keeps --measure (.gb-doc) */
.modal--read .modal__dialog { max-width: 62rem; background: var(--scroll-paper); }
.modal--read .modal__header,
.modal--side .modal__header { align-items: center; border-bottom: 1px solid var(--hairline); padding-bottom: var(--sp-3); }
.modal--read .modal__title,
.modal--side .modal__title { overflow-wrap: anywhere; }
.modal--read .modal__title:focus,
.modal--side .modal__title:focus { outline: none; }
.modal--read .modal__close,
.modal--side .modal__close { margin: 0; }
.modal--read .modal__body { padding-top: 0; }
.modal--read .modal__footer { background: rgba(255, 255, 255, 0.6); justify-content: space-between; }
.read__eyebrow { display: block; margin-bottom: 0.15rem; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--primary-text); }
.read__cover { margin: 0 calc(-1 * var(--sp-5)) var(--sp-4); aspect-ratio: 3 / 1; overflow: hidden; background: var(--surface-2); }
.read__cover > img,
.read__cover > .ph,
.read__zoom > img { display: block; width: 100%; height: 100%; object-fit: cover; }
.read__zoom { width: 100%; height: 100%; border: 0; border-radius: 0; background: none; }
.read__zoom:focus-visible { outline-offset: -3px; }
.read__cover > .ph { display: grid; }
.read__cover > .ph > img { width: 18%; }
.read__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-4); font-size: var(--fs-xs); color: var(--text-muted); }
.read__meta > span:not(.badge) { display: inline-flex; align-items: center; gap: 0.35rem; }
.read__meta > .badge { max-width: 100%; white-space: normal; line-height: 1.3; padding-block: 0.15rem; }
.read__meta svg.lucide { width: 0.95rem; height: 0.95rem; }
.read__nav { min-width: 0; max-width: 48%; }
.read__nav span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.read__nav[hidden] { display: none; }
.read__nav--next { margin-inline-start: auto; }
@media (max-width: 39.99rem) {
  .read__cover { margin-inline: calc(-1 * var(--sp-4)); aspect-ratio: 16 / 7; }
  .modal--read .modal__footer { flex-wrap: nowrap; }
  .modal--read .modal__footer > .btn { flex: 1 1 0; min-width: 0; }
  .read__nav { max-width: none; }
}

/* Lightbox + zoom viewer (assets/js/guide.js §3): near full-screen on desktop, full-screen on phones.
   The image is absolutely positioned; its size and offset are set by script through CSSOM. */
.modal--lightbox .modal__dialog {
  width: 100%;
  max-width: none;
  height: calc(100vh - 2rem);
  height: calc(100dvh - 2rem);
  max-height: none;
  background: #0B0A10;
  transform: none;
}
.modal--lightbox .modal__dialog::after { display: none; }
.lb__head { align-items: center; padding: var(--sp-3) var(--sp-4); }
.lb__head .modal__title { padding-top: 0; font-size: var(--fs-base); }
.lb__head .modal__close { margin: 0; }
.lb__open { min-height: var(--tap); flex-shrink: 0; }
.lb__open[hidden] { display: none; }
.lb__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 var(--sp-4);
  overflow: hidden;
  border-radius: var(--r-lg);
  background: #000;
  touch-action: none;           /* pan / pinch handled by script */
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: contain;
  cursor: default;
}
.lb__stage.can-zoom { cursor: zoom-in; }
.lb__stage.is-zoomed { cursor: grab; }
.lb__stage.is-dragging { cursor: grabbing; }
.lb__stage:focus { outline: none; }
.lb__stage:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.lb__img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  max-width: none;
  max-height: none;
  transform-origin: 0 0;
  -webkit-user-drag: none;
  pointer-events: none;
}
.lb__img[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .lb__stage.is-anim .lb__img { transition: width 0.18s var(--ease), height 0.18s var(--ease), transform 0.18s var(--ease); }
}
.lb__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4) 0; }
.lb__bar .btn[hidden] { display: none; }
.lb__btn.btn { min-width: var(--tap); min-height: var(--tap); }
.lb__btn[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.lb__zoom { display: flex; align-items: center; gap: var(--sp-1); margin-inline: auto; }
.lb__pct { min-width: 3.25rem; text-align: center; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; color: var(--text-muted); }
.lb__actual { padding-inline: var(--sp-3); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.lb__actual[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-text); }
.lb__cap { min-height: 1.5em; margin: 0; padding: var(--sp-2) var(--sp-4) var(--sp-3); text-align: center; color: var(--text-muted); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.lb__cap:empty { padding-bottom: var(--sp-2); }
@media (max-width: 39.99rem) {
  .modal--lightbox .modal__dialog {
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    transform: none;
  }
  .modal--lightbox .modal__dialog::before { display: none; }
  .lb__head { padding: calc(var(--sp-2) + env(safe-area-inset-top)) var(--sp-3) var(--sp-2); }
  .lb__open { width: var(--tap); padding: 0; }
  .lb__open-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .lb__stage { margin: 0; border-radius: 0; }
  .lb__bar { gap: var(--sp-1); padding: var(--sp-2) var(--sp-2) 0; }
  .lb__zoom { gap: 0; }
  .lb__pct { min-width: 2.75rem; }
  .lb__cap { padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom)); }
}

/* Side drawer ("ดูตัวอย่าง" under a question): right panel on desktop, bottom sheet on phones */
.modal--side .modal__dialog { background: var(--scroll-paper); }
@media (min-width: 40rem) {
  .modal--side { justify-content: flex-end; align-items: stretch; padding: 0; }
  .modal--side .modal__dialog {
    max-width: 32rem;
    height: 100%;
    max-height: none;
    border-radius: var(--r-xl) 0 0 var(--r-xl);
    border-right: 0;
    transform: translateX(100%);
  }
  .modal--side.is-open .modal__dialog { transform: none; }
}
.modal--side .modal__body { padding-top: 0; }
.gd-switch { flex-wrap: wrap; margin: var(--sp-3) 0; }
.gd-switch[hidden] { display: none; }

/* =====================================================================
   Entry points (apply.php)
   ===================================================================== */
.apply-tabs .tab { flex: 1 1 0; justify-content: center; font-size: var(--fs-base); min-height: var(--tap); }
.apply-panel:focus-visible { outline-offset: 4px; }
.apply-panel--guide .gc-grid { --min: 15rem; --gap: var(--sp-4); }
.apply-panel--guide .gc-card { background: rgba(255, 255, 255, 0.72); }
.apply-guide-note { margin: 0 0 var(--sp-4); font-size: var(--fs-sm); color: var(--text-muted); }
.ep-help {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  align-self: flex-start;
  min-height: var(--tap);
  margin: -0.5rem 0 -0.25rem -0.5rem;
  padding: 0 0.5rem;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--primary-text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  cursor: pointer;
}
.ep-help:hover { text-decoration-thickness: 2px; background: var(--primary-soft); }
.ep-help svg.lucide { width: 1rem; height: 1rem; flex-shrink: 0; }
fieldset.q-item > .ep-help { margin: -0.25rem 0 var(--sp-1) -0.5rem; }

/* topbar link of the current page (guide.php) */
.topbar .btn[aria-current="page"] { color: var(--primary-text); background: var(--primary-soft); }
