/* Approved October discovery artwork. Web keeps its original card geometry;
   only native SELECT opts into the portrait library. */
body.select-phase .btn-game-pick.shathaat::before { background-image: url('/assets/game-discovery/answers.webp'); }
body.select-phase .btn-game-pick.faker::before { background-image: url('/assets/game-discovery/faker.webp'); }
body.select-phase .btn-game-pick.khedaa::before { background-image: url('/assets/game-discovery/khedaa.webp'); }
body.select-phase .btn-game-pick.khallat::before { background-image: url('/assets/game-discovery/khallat.webp'); }
body.select-phase .btn-game-pick.mahkama::before { background-image: url('/assets/game-discovery/mahkama.webp'); }
body.select-phase .btn-game-pick.nesba::before { background-image: url('/assets/game-discovery/percent.webp'); }
html:not(.native) body.select-phase .btn-game-pick::before { border-radius: 16px; }
html:not(.native) body.select-phase .btn-game-pick:focus-visible { outline: 3px solid #ffdb49; outline-offset: 4px; }

html.native[data-mj-surface="host"]:has(.native-library) body.select-phase {
  height: 100dvh; min-height: 0; padding: 0; overflow: hidden;
  color: #fff7e8;
  background: #0567ac url('/assets/game-discovery/library-background.webp') center top / 100% auto repeat-y;
}
html.native:has(.native-library) body.select-phase::before,
html.native:has(.native-library) body.select-phase::after { display: none !important; }
html.native:has(.native-library) body.select-phase :is(.page-header, #top-left-bar, #rotate-overlay, #host-player-switch) { display: none !important; }
html.native:has(.native-library) body.select-phase #app {
  display: block; width: 100%; max-width: none; height: 100%; min-height: 0;
  flex: 1 1 auto; margin: 0; padding: 0; overflow-x: hidden; overflow-y: auto;
  zoom: 1; transform: none; scrollbar-width: thin; scrollbar-color: #54b4df transparent;
  -webkit-overflow-scrolling: touch;
}
/* Settings still covers the library without a second active scroll surface. */
html.native.mobile-shell[data-shell-screen]:not([data-shell-screen="library"]):not([data-shell-screen="play"]) body.select-phase #app { display: none; }
.native-library {
  --discovery-ink: #fff7e8; --discovery-dark: #00243e;
  width: min(100%, 700px); margin: 0 auto; box-sizing: border-box;
  padding: max(14px, var(--safe-top, env(safe-area-inset-top))) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  color: var(--discovery-ink); font-family: 'Cairo', sans-serif;
}
.discovery-nav { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; align-items: center; gap: 12px; }
.discovery-logo { display: block; width: 100%; max-width: 230px; height: 84px; object-fit: contain; justify-self: center; }
html.native body.select-phase #app .discovery-icon-button {
  display: grid; place-items: center; width: 48px; height: 48px; min-height: 48px;
  min-width: 48px; max-width: 48px; margin: 0; padding: 10px; border: 2px solid #052637; border-radius: 15px;
  background: #03476b; color: #fff7e8; box-shadow: 0 4px 8px #00233766; cursor: pointer;
  box-sizing: border-box;
}
.native-library svg, .discovery-detail svg { width: 25px; height: 25px; flex-shrink: 0; }
.discovery-intro { padding: 8px 0 23px; text-align: center; }
.native-library .discovery-intro h1 {
  margin: 0; font-size: clamp(30px, 8.5vw, 54px); font-weight: 900; line-height: 1.45;
  color: #fff7e8; text-shadow: 0 3px 1px #002238, 0 5px 7px #00223880;
}
.discovery-intro p { margin: 3px 0 0; font-size: clamp(15px, 4vw, 21px); line-height: 1.7; color: #fff7e8; }
.discovery-games { display: flex; flex-direction: column; gap: 12px; }
html.native body.select-phase #app .discovery-card {
  position: relative; display: block; width: 100%; height: auto; min-height: 0; max-width: none;
  aspect-ratio: 656 / 244; margin: 0; padding: 0; border: 0; border-radius: 18px;
  overflow: hidden; isolation: isolate; background: #063b52 !important;
  box-shadow: 0 4px 9px #00223866; color: #fff7e8; font: inherit;
  line-height: 1.4; transform: none; animation: none; will-change: auto;
  transition: transform 150ms ease-out;
}
html.native body.select-phase #app .discovery-card::before { display: none; }
html.native body.select-phase #app .discovery-card > * { display: block !important; }
.discovery-card-art {
  position: absolute; inset: 0; pointer-events: none;
  background: url('/assets/game-discovery/library-art.webp') 51.85% var(--art-y, 17.96%) / 104.116% var(--art-size, 839.344%) no-repeat;
}
.shathaat { --art-y: 17.96%; }
.faker { --art-y: 32.206%; }
.khedaa { --art-y: 46.306%; --art-size: 875.214%; }
.khallat { --art-y: 60.366%; }
.mahkama { --art-y: 74.723%; }
.nesba { --art-y: 90.366%; --art-size: 750.183%; }
.discovery-card-soon {
  position: absolute; top: 8px; left: 9px; padding: 3px 10px; background: #002137;
  color: #fff7e8; border-radius: 12px; font-size: 12px; font-weight: 800;
}
html.native body.select-phase #app .discovery-card:active { transform: scale(.985); }
.native-library :is(button, a):focus-visible, .discovery-detail button:focus-visible {
  outline: 3px solid #ffe342; outline-offset: 3px;
}
.discovery-join {
  position: sticky; bottom: 0; z-index: 4; padding: 15px 10px max(15px, env(safe-area-inset-bottom));
  margin-top: 9px; background: linear-gradient(transparent, #014372 28%);
}
.discovery-join button {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 54px;
  margin: 0; padding: 10px 18px; border: 2px solid #3ebde9; border-radius: 30px;
  box-shadow: 0 3px 8px #00233780; background: #002b49; color: #fff7e8; cursor: pointer;
  font: 800 clamp(16px, 4vw, 23px) / 1.5 'Cairo', sans-serif;
}
.discovery-join svg { color: #89dcff; }
.native-library #game-start-status { position: relative; width: 100%; margin: 0 0 14px; }

/* Full-height briefs retain the library beneath them and restore its focus
   and scroll position on Back. Only the explicit CTA creates a room. */
.discovery-detail {
  --detail-paper: #fff6e5; --detail-ink: #073c4d; --detail-accent: #ffd83e;
  position: fixed; inset: 0; width: 100%; max-width: 760px; height: 100dvh; max-height: 100dvh;
  margin: 0 auto; padding: 0; border: 0; border-radius: 0;
  background: var(--detail-paper); color: var(--detail-ink); font-family: 'Cairo', sans-serif;
  overflow: hidden; direction: rtl;
}
.discovery-detail[open] { display: flex; flex-direction: column; }
.discovery-detail::backdrop { background: #002339ed; }
.discovery-detail-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-color: var(--detail-ink) var(--detail-paper); }
.discovery-detail-nav { padding: max(12px, env(safe-area-inset-top)) 20px 10px; background: var(--detail-ink); }
.discovery-detail-back {
  display: flex; align-items: center; gap: 8px; min-height: 44px; border: 0; padding: 4px 0;
  background: transparent; color: var(--detail-paper); font: 800 18px 'Cairo', sans-serif; cursor: pointer;
}
.discovery-detail-art { position: relative; width: 100%; aspect-ratio: 656 / 244; overflow: hidden; }
.discovery-detail-intro, .discovery-video-section, .discovery-how, .discovery-gallery { padding: 24px 24px 8px; }
.discovery-detail h1 { margin: 0 0 5px; color: var(--detail-ink); font-size: clamp(30px, 7vw, 44px); font-weight: 900; line-height: 1.4; }
.discovery-detail h2 { margin: 0 0 16px; color: var(--detail-ink); font-size: clamp(24px, 5.5vw, 32px); font-weight: 900; line-height: 1.5; }
.discovery-detail p { margin: 0; font-size: 17px; line-height: 1.85; color: var(--detail-ink); }
.discovery-detail .discovery-hook { font-weight: 800; font-size: 21px; margin-bottom: 10px; }
.discovery-video { overflow: hidden; border-radius: 14px; background: #071523; }
.discovery-video video { display: block; width: 100%; aspect-ratio: 16 / 9; }
.discovery-how ol { list-style: none; margin: 0; padding: 0; }
.discovery-how li { display: flex; align-items: flex-start; gap: 15px; margin-bottom: 23px; }
.discovery-step-number { flex: 0 0 46px; display: grid; place-items: center; height: 46px; border-radius: 50%; background: var(--detail-accent); color: var(--detail-ink); font-size: 26px; font-weight: 900; }
.discovery-how h3 { margin: 0 0 4px; font-size: 21px; line-height: 1.6; color: var(--detail-ink); }
.discovery-gallery { padding-bottom: 28px; }
.discovery-gallery-scroll { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-color: var(--detail-ink) var(--detail-paper); padding-bottom: 10px; }
.discovery-gallery img { flex: 0 0 85%; width: 85%; max-width: none; height: auto; aspect-ratio: 16 / 9; object-fit: contain; border-radius: 12px; scroll-snap-align: center; background: var(--detail-ink); }
.discovery-detail-footer { flex: 0 0 auto; padding: 14px 24px max(14px, env(safe-area-inset-bottom)); background: var(--detail-ink); color: var(--detail-paper); }
.discovery-detail-footer button { display: flex; justify-content: center; align-items: center; gap: 24px; width: 100%; min-height: 54px; border: 0; border-radius: 12px; padding: 9px 14px; background: var(--detail-accent); color: var(--detail-ink); font: 900 24px 'Cairo', sans-serif; cursor: pointer; }
.discovery-detail-footer p { text-align: center; color: var(--detail-paper); font-size: 13px; margin-top: 7px; }
.discovery-detail-footer .discovery-unavailable { font-size: 24px; font-weight: 900; margin: 0; }
.discovery-faker { --detail-ink: #392016; --detail-accent: #ffab8f; }
.discovery-mahkama { --detail-paper: #f5e8ca; --detail-ink: #073f30; --detail-accent: #a8e3ba; }
.discovery-percent { --detail-paper: #ffedc6; --detail-ink: #682016; --detail-accent: #ffd06d; }
@media (min-width: 600px) {
  .native-library { padding-top: max(18px, env(safe-area-inset-top)); padding-inline: 24px; }
  .discovery-games { gap: 18px; }
  .discovery-intro { padding-bottom: 28px; }
  .discovery-card-soon { font-size: 16px; top: 12px; left: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  html.native body.select-phase #app .discovery-card { transition: none; }
}

/* Illustrated rule pages follow the approved posters. Art is kept in atlas
   windows; live copy reflows independently, including on 320px phones. */
.illustrated-brief {
  --brief-ink: #072c3b; --brief-accent: #ffe000; --brief-world: #004b66;
  position: fixed; inset: 0; width: 100%; max-width: 760px; height: 100dvh; max-height: 100dvh;
  margin: 0 auto; padding: 0; border: 0; border-radius: 0; overflow: hidden;
  background: var(--brief-world); color: var(--brief-ink); direction: rtl; text-align: center;
  font-family: 'Cairo', sans-serif;
}
.illustrated-brief[open] { display: flex; flex-direction: column; }
.illustrated-brief::backdrop { background: #071a25ed; }
.illustrated-brief .brief-scroll { flex: 1; min-height: 0; overflow: auto; padding-top: env(safe-area-inset-top); scrollbar-width: thin; scrollbar-color: var(--brief-accent) var(--brief-world); }
.brief-faker { --brief-ink: #10100e; --brief-accent: #ff604e; --brief-world: #fff7e6; }
.brief-khedaa { --brief-ink: #101c1f; --brief-world: #003544; }
.brief-khallat { --brief-ink: #111; --brief-world: #1d052f; }
.brief-mahkama { --brief-ink: #073e30; --brief-accent: #b8dec2; --brief-world: #07372b; }
.brief-sr { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip-path: inset(50%); white-space: nowrap; }
.brief-art { display: block; width: 100%; background-repeat: no-repeat; flex-shrink: 0; }
.brief-hero { position: relative; }
.illustrated-brief .brief-back {
  position: absolute; inset: 1% 1% auto auto; width: 22%; min-width: 70px; min-height: 44px;
  height: 16%; margin: 0; padding: 0; border: 0; border-radius: 4px; background: transparent;
  box-shadow: none; cursor: pointer;
}
.illustrated-brief .brief-share { position: absolute; top: 0; left: 0; width: 12%; min-width: 44px; height: 16%; min-height: 44px; margin: 0; padding: 0; border: 0; background: transparent; box-shadow: none; cursor: pointer; }
.brief-share-status { position: absolute; top: 48px; left: 12px; padding: 8px 12px; background: #fff7e8; color: #073e30; font-size: 14px; }
.illustrated-brief .brief-player-count { position: absolute; right: 4%; bottom: 3%; display: grid; place-items: center; width: 34%; height: 11%; margin: 0; padding: 0; color: #fff9e9; background: #7800cb; font-size: clamp(10px, 2.7vw, 19px); font-weight: 800; line-height: 1.1; }
.brief-paper { position: relative; margin-top: -10px; padding: 12px 5% 24px; background: url('/assets/game-briefs/paper.webp') center / 100% 100% no-repeat; }
.illustrated-brief .brief-heading { color: var(--brief-ink); font-size: clamp(25px, 6.4vw, 44px); font-weight: 900; line-height: 1.45; margin: 0 0 12px; text-wrap: balance; }
.brief-heading::before, .brief-heading::after { content: ''; display: inline-block; width: .7em; height: .8em; margin: 0 .2em; vertical-align: middle; background: var(--brief-accent); clip-path: polygon(0 0, 100% 85%, 28% 42%, 0 56%, 96% 100%, 4% 100%); }
.brief-heading::after { transform: scaleX(-1); }
.illustrated-brief .brief-watch { display: block; width: 100%; max-width: none; height: auto; min-height: 0; padding: 0; margin: 0; border: 0; border-radius: 8px; background: transparent; overflow: hidden; cursor: pointer; }
.illustrated-brief .brief-watch[hidden], .illustrated-brief .brief-media video[hidden] { display: none; }
.illustrated-brief .brief-media video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #071523; border-radius: 8px; }
.illustrated-brief p.brief-media-caption { margin: 4px 0 0; font-size: clamp(13px, 3.5vw, 18px); font-weight: 900; line-height: 1.6; color: var(--brief-ink); }
.illustrated-brief .brief-how { padding: 22px 0 0; }
.illustrated-brief .brief-summary { margin: -4px 0 8px; font-size: 15px; font-weight: 700; line-height: 1.7; color: var(--brief-ink); }
.illustrated-brief .brief-steps { display: flex; flex-direction: column; gap: 0; margin: 0; padding: 0; list-style: none; }
.illustrated-brief .brief-steps > :is(li, article) { display: grid; grid-template-columns: 36px minmax(0, 1fr) 32%; gap: 8px; align-items: center; position: relative; padding: 12px 0; margin: 0; min-width: 0; background: transparent; border: 0; border-bottom: 1px solid #75684929; border-radius: 0; box-shadow: none; }
.illustrated-brief .brief-steps > :last-child { border-bottom: 0; }
.brief-step-art { grid-column: 3; grid-row: 1; mix-blend-mode: darken; }
.brief-step-copy { grid-column: 2; grid-row: 1; text-align: right; min-width: 0; }
.illustrated-brief .brief-step-copy h3 { margin: 0 0 4px; color: var(--brief-ink); font-size: clamp(17px, 4.4vw, 25px); font-weight: 900; line-height: 1.6; }
.illustrated-brief .brief-step-copy p { margin: 0; color: var(--brief-ink); font-size: clamp(14px, 3.7vw, 19px); line-height: 1.65; }
.brief-step-number { grid-column: 1; grid-row: 1; display: grid; place-items: center; width: 34px; height: 38px; border: 2px solid var(--brief-ink); border-radius: 50%; background: var(--brief-accent); color: var(--brief-ink); font-size: 25px; font-weight: 900; transform: rotate(-7deg); }
.illustrated-brief .brief-gallery { padding: 18px 0 0; }
.illustrated-brief .brief-gallery .brief-heading { font-size: clamp(23px, 5.5vw, 34px); margin-bottom: 8px; }
.brief-gallery > .brief-art { border-radius: 8px; overflow: hidden; }
.illustrated-brief .brief-footer { position: static; flex: 0 0 auto; padding: 8px 5% max(9px, env(safe-area-inset-bottom)); margin: 0; background: var(--brief-world); color: #fff7e8; }
.illustrated-brief .brief-footer button { position: relative; display: flex; justify-content: center; align-items: center; width: 100%; max-width: none; min-height: 48px; margin: 0; padding: 5px 40px; border: 2px solid #101c1f; border-radius: 12px; background: var(--brief-accent); color: #111; font: 900 clamp(22px, 6vw, 30px) / 1.6 'Cairo', sans-serif; box-shadow: none; text-shadow: none; cursor: pointer; }
.illustrated-brief .brief-footer button svg { position: absolute; left: 16px; width: 24px; height: 24px; }
.illustrated-brief .brief-footer p { margin: 5px 0 0; font-size: 12px; line-height: 1.5; color: #fff7e8; }
.brief-faker .brief-footer p { color: #151510; }
.illustrated-brief .brief-footer .discovery-unavailable { color: var(--brief-ink); background: url('/assets/game-briefs/paper.webp') center / 100% 100%; padding: 6px 20px; margin: 0 auto; width: fit-content; min-width: 65%; font-size: 24px; font-weight: 900; }
.brief-mahkama .brief-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; direction: ltr; }
.illustrated-brief.brief-mahkama .brief-steps > li { display: flex; flex-direction: column; gap: 6px; padding: 0; border: 0; direction: rtl; }
.brief-mahkama .brief-step-art { width: 100%; aspect-ratio: 1.5 !important; }
.brief-mahkama .brief-step-copy { text-align: center; }
.illustrated-brief.brief-mahkama .brief-step-copy h3 { font-size: clamp(14px, 3.8vw, 23px); line-height: 1.5; }
.illustrated-brief.brief-mahkama .brief-step-copy p { font-size: clamp(13px, 3.4vw, 18px); line-height: 1.65; }
.illustrated-brief .brief-ghost-note { margin: 18px 6% 0; padding: 9px 12px; color: #073e30; background: #b8dec2; font-size: clamp(16px, 4vw, 23px); font-weight: 900; line-height: 1.6; }
.illustrated-brief button:focus-visible, .brief-demo button:focus-visible { outline: 3px solid var(--brief-accent, #ffe000); outline-offset: 4px; }
.brief-demo { width: min(460px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 24px; border: 0; background: #fff7e8 url('/assets/game-briefs/paper.webp') center / 100% 100%; color: #073e30; font-family: 'Cairo', sans-serif; text-align: center; }
.brief-demo::backdrop { background: #001c17c9; }
.brief-demo .brief-art { width: 65%; margin: 10px auto; mix-blend-mode: multiply; }
.brief-demo button { min-height: 44px; padding: 8px 18px; border: 2px solid #073e30; background: #073e30; color: #fff7e8; font: 800 18px 'Cairo', sans-serif; }
.brief-demo-close { display: block; margin-right: auto; }
.brief-demo h2 { font-size: 26px; }.brief-demo p { font-size: 18px; line-height: 1.8; }
@media (min-width: 600px) {
  .illustrated-brief .brief-steps > :is(li, article) { grid-template-columns: 48px minmax(0, 1fr) 32%; gap: 16px; padding-block: 18px; }
  .brief-step-number { width: 44px; height: 48px; font-size: 32px; }
  .brief-paper { padding-top: 20px; }.illustrated-brief .brief-how { padding-top: 28px; }
}
