/* ==========================================================================
   REAL Shahnameh — Chapter page
   Builds on style.css + home.css. Long-form, cinematic, with locked/unlocked
   states for collectibles. Persian RTL friendly.
   ========================================================================== */

/* Ensure hidden attribute is respected even when display is set by a class rule */
[hidden] { display: none !important; }

/* ── Global mobile-safety reset for chapter page ──────────────────────────
   Prevents horizontal overflow / side-slipping seen on narrow viewports.   */
.chapter-app,
.chapter-app * {
  box-sizing: border-box;
}
.chapter-app {
  overflow-x: hidden;
  max-width: 100vw;
}
/* Scene text must not push past viewport */
.scene-text,
.scene-modal-body p,
.bt-msg,
.copy,
.intro {
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}
/* Battle and quiz cards must stay within the column */
.battle-card,
.quiz-card,
.req-list,
.quiz-tier-tabs {
  overflow: hidden;
  max-width: 100%;
}
/* Scene modal body must not bleed outside the card */
.scene-modal-body {
  overflow-x: hidden;
  max-width: 100%;
}
/* Prevent any image from overflowing its container */
.scene-modal-image img,
.scene-card .scene-info {
  max-width: 100%;
}

/* Battle teaser overlay — shown when player taps the CTA with all reqs met */
.battle-teaser-overlay {
  position: fixed; inset: 0; z-index: 910;
  background: rgba(4, 5, 11, .9);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  padding: 32px 24px;
  opacity: 0; transition: opacity .25s ease;
}
.battle-teaser-overlay.open { opacity: 1; }
.bt-inner {
  max-width: 320px; width: 100%;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.bt-glyph {
  font-size: 56px; line-height: 1;
  filter: drop-shadow(0 0 28px rgba(255, 82, 103, .75));
  animation: bt-pulse 1.8s ease-in-out infinite;
}
@keyframes bt-pulse {
  0%, 100% { transform: scale(1);    filter: drop-shadow(0 0 20px rgba(255,82,103,.6)); }
  50%       { transform: scale(1.1); filter: drop-shadow(0 0 36px rgba(255,82,103,.9)); }
}
.bt-title {
  font-size: 20px; font-weight: 900; margin: 0;
  color: #ff6b7a;
  text-shadow: 0 0 22px rgba(255, 82, 103, .55);
  letter-spacing: .5px;
}
.bt-msg {
  font-size: 14px; line-height: 1.65; color: #d8d2c0; margin: 0;
}
.bt-dismiss { width: 100%; }

/* Chapter gate overlay */
.chapter-gate {
  position: fixed; inset: 0; z-index: 500;
  background: #04050b;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 24px;
}
.cg-inner {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; max-width: 340px; gap: 12px;
}
.cg-lock { font-size: 56px; line-height: 1; }
.cg-title {
  font-size: 22px; font-weight: 900; margin: 0;
  background: linear-gradient(118deg,#fff 0%,#ffe8c0 55%,var(--gold,#f4c56b) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.cg-msg { font-size: 14px; color: var(--muted,#6c7287); margin: 0; line-height: 1.5; }
.cg-btn { width: 100%; margin-top: 4px; }

.chapter-body { background: #04050b; color: #e9e3d0; }

.chapter-app {
  padding: 0 0 calc(110px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(244, 197, 107, .08), transparent 65%),
    linear-gradient(180deg, #06070f 0%, #04050b 100%);
}

/* ----- breadcrumbs / replay intro ----- */
.ch-crumbs {
  position: relative; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: env(safe-area-inset-top) 14px 0;
  margin-top: 12px;
}
.ch-crumb {
  font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--gold, #f4c56b); text-decoration: none;
  background: rgba(244, 197, 107, .08);
  border: 1px solid rgba(244, 197, 107, .25);
  padding: 6px 12px; border-radius: 999px;
}
.ch-replay {
  background: transparent;
  border: 1px solid rgba(140, 109, 255, .35);
  color: #cdbcff;
  font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase;
  padding: 6px 12px; border-radius: 999px;
  cursor: pointer;
}
.ch-replay:hover { background: rgba(140, 109, 255, .12); }

/* ----- hero ----- */
.ch-hero {
  position: relative;
  margin: 14px 14px 18px;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(244, 197, 107, .35);
  min-height: 280px;
  background: linear-gradient(160deg, #2a1a3d 0%, #1a0c2a 50%, #0b0814 100%);
  isolation: isolate;
}
.ch-hero-cover {
  position: absolute; inset: 0;
  background-color: #0b0814;
  background-position: center right;
  background-size: cover;
  background-repeat: no-repeat;
  filter: saturate(1.05);
  transition: opacity .4s ease;
}
.ch-hero-fade {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(4, 5, 11, .35) 0%, rgba(4, 5, 11, .85) 70%, rgba(4, 5, 11, .98) 100%),
    linear-gradient(90deg, rgba(4, 5, 11, .85) 0%, rgba(4, 5, 11, .25) 60%, transparent 100%);
}
.ch-hero-body {
  position: relative;
  padding: 80px 18px 22px;
  z-index: 1;
}
.ch-hero-kicker {
  display: inline-block;
  font-size: 10px; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--gold, #f4c56b);
  background: rgba(244, 197, 107, .12);
  border: 1px solid rgba(244, 197, 107, .35);
  border-radius: 999px;
  padding: 4px 10px; margin-bottom: 10px;
}
.ch-hero-title {
  margin: 0;
  font-size: clamp(24px, 6vw, 30px);
  font-weight: 900;
  line-height: 1.1;
  background: linear-gradient(180deg, #fff, var(--gold, #f4c56b));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 32px rgba(244, 197, 107, .2);
}
.ch-hero-fa {
  margin: 6px 0 14px;
  font-size: 16px; color: var(--gold, #f4c56b); opacity: .9;
}
.ch-hero-rewards {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.ch-hero-rewards .reward-pill {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  background: rgba(74, 216, 166, .12);
  color: var(--jade, #4ad8a6);
  border: 1px solid rgba(74, 216, 166, .35);
  letter-spacing: .5px;
  display: inline-flex; align-items: center; gap: 4px;
}
.ch-hero-rewards .reward-pill.gold {
  background: rgba(244, 197, 107, .12);
  color: var(--gold, #f4c56b);
  border-color: rgba(244, 197, 107, .35);
}

/* ----- lore summary ----- */
.ch-lore {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: start;
  margin: 0 14px 16px;
  padding: 14px;
}
.ch-lore-mark {
  width: 56px; height: 56px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: rgba(244, 197, 107, .12);
  border: 1px solid rgba(244, 197, 107, .3);
  color: var(--gold, #f4c56b);
  font-size: 24px;
}
.ch-lore-body .kicker {
  display: block;
  font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--muted, #6c7287);
  margin-bottom: 4px;
}
.ch-lore-body .copy { margin: 0; font-size: 13px; line-height: 1.65; color: #d8d2c0; }

/* ----- chapter section heads ----- */
.chapter-app .section-head {
  display: flex; align-items: end; justify-content: space-between;
  margin: 14px 16px 10px;
}
.chapter-app .section-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.chapter-app .section-head .more {
  font-size: 11px; color: var(--muted, #6c7287);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 1px;
}

/* ----- timeline strip ----- */
/* ----- scene list ----- */
.scene-list { display: grid; gap: 12px; padding: 0 14px; }
.scene-card {
  position: relative;
  background: var(--bg-card, #0e1019);
  border: 1px solid var(--border, #1f2336);
  border-radius: 18px;
  padding: 16px 14px 14px;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.scene-card:hover { border-color: rgba(244, 197, 107, .4); transform: translateY(-1px); }
.scene-card.read {
  border-color: rgba(74, 216, 166, .35);
  background: linear-gradient(180deg, rgba(74, 216, 166, .04), rgba(74, 216, 166, 0));
}
.scene-card .scene-num {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(244, 197, 107, .12);
  border: 1px solid rgba(244, 197, 107, .35);
  color: var(--gold, #f4c56b);
  font-weight: 800; font-size: 16px;
}
.scene-card.read .scene-num {
  background: rgba(74, 216, 166, .14);
  border-color: rgba(74, 216, 166, .4);
  color: var(--jade, #4ad8a6);
}
.scene-card .scene-info { min-width: 0; }
.scene-card .scene-info .era {
  font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase;
  color: rgba(244, 197, 107, 0.75);
  font-weight: 600;
}
.scene-card .scene-info h4 { margin: 4px 0 4px; font-size: 14px; font-weight: 700; line-height: 1.3; }
.scene-card .scene-info p  { margin: 0; font-size: 12px; color: #aab1c2; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.scene-card .scene-arrow {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(244, 197, 107, .14);
  border: 1px solid rgba(244, 197, 107, .35);
  color: var(--gold, #f4c56b);
  display: grid; place-items: center;
  font-size: 14px;
}

/* atmosphere accents per scene */
.scene-card[data-atmos="dark"]   { box-shadow: inset 0 0 60px rgba(140, 109, 255, .08); }
.scene-card[data-atmos="dawn"]   { box-shadow: inset 0 0 60px rgba(244, 197, 107, .08); }
.scene-card[data-atmos="fated"]  { box-shadow: inset 0 0 60px rgba(255, 108, 108, .08); }
.scene-card[data-atmos="warm"]   { box-shadow: inset 0 0 60px rgba(255, 138, 61, .08); }
.scene-card[data-atmos="wild"]   { box-shadow: inset 0 0 60px rgba(74, 216, 166, .08); }
.scene-card[data-atmos="court"]  { box-shadow: inset 0 0 60px rgba(94, 162, 255, .08); }

/* When a scene has a backdrop image, render it as a soft right-aligned wash
   behind the text so each scene card hints at its location/character. */
.scene-card.has-backdrop {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.scene-card.has-backdrop::before {
  content: "";
  position: absolute; inset: 0;
  background-image: var(--scene-backdrop, none);
  background-size: cover;
  background-position: center right;
  background-repeat: no-repeat;
  opacity: .35;
  z-index: -1;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, .9) 70%, #000 100%);
          mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, .9) 70%, #000 100%);
}
.scene-card.has-backdrop::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(14, 16, 25, .92) 0%, rgba(14, 16, 25, .75) 50%, rgba(14, 16, 25, .35) 100%);
  z-index: -1;
}
.scene-card.has-backdrop[data-atmos="dark"]::after  { background: linear-gradient(90deg, rgba(10, 7, 25, .92) 0%, rgba(10, 7, 25, .75) 50%, rgba(40, 22, 80, .35) 100%); }
.scene-card.has-backdrop[data-atmos="fated"]::after { background: linear-gradient(90deg, rgba(20, 5, 10, .92) 0%, rgba(20, 5, 10, .75) 50%, rgba(80, 22, 30, .35) 100%); }

/* ----- battle requirements ----- */
.battle-card {
  margin: 0 14px;
  border: 1px solid rgba(255, 108, 108, .3);
  background:
    radial-gradient(140% 100% at 100% 0%, rgba(255, 108, 108, .12), transparent 70%),
    var(--bg-card, #0e1019);
  padding: 16px;
}
.battle-card .b-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.battle-card .b-glyph {
  position: relative;
  width: 64px; height: 64px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: rgba(255, 108, 108, .14);
  border: 1px solid rgba(255, 108, 108, .35);
  color: #ff8a8a;
  font-size: 22px;
  overflow: hidden;
  flex-shrink: 0;
}
.battle-card .b-glyph img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.battle-card .b-glyph img.img-fail { display: none; }
.battle-card .b-glyph::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 100%, rgba(255, 108, 108, .35) 0%, transparent 60%);
  pointer-events: none;
}
.battle-card .b-master {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(140, 109, 255, .07);
  border: 1px solid rgba(140, 109, 255, .25);
  border-radius: 12px;
}
.battle-card .b-master-portrait {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle, #2a1647, #0d0623);
  border: 1px solid rgba(140, 109, 255, .35);
}
.battle-card .b-master-portrait img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.battle-card .b-master-portrait img.img-fail { display: none; }
.battle-card .b-master-label {
  font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase;
  color: #cdbcff;
}
.battle-card .b-master-name { font-size: 13px; font-weight: 800; color: #fff; margin-top: 2px; }
.battle-card .b-head h4 { margin: 0; font-size: 15px; font-weight: 800; }
.battle-card .b-head .b-sub { margin: 2px 0 0; font-size: 11px; color: var(--muted, #6c7287); }
.battle-card p.intro {
  margin: 0 0 14px; font-size: 12px; line-height: 1.55; color: #d8d2c0;
}
.req-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.req-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .02);
  border: 1px solid var(--border, #1f2336);
  border-radius: 12px;
}
.req-row.done {
  background: rgba(74, 216, 166, .07);
  border-color: rgba(74, 216, 166, .35);
}
.req-mark {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border, #1f2336);
  display: grid; place-items: center;
  font-size: 14px;
  color: var(--muted, #6c7287);
}
.req-row.done .req-mark {
  background: rgba(74, 216, 166, .15);
  border-color: rgba(74, 216, 166, .4);
  color: var(--jade, #4ad8a6);
}
.req-label { font-size: 13px; color: #e9e3d0; }
.req-row.done .req-label { color: var(--jade, #4ad8a6); }
.req-pill {
  font-size: 10px; letter-spacing: 1px;
  background: rgba(244, 197, 107, .12); color: var(--gold, #f4c56b);
  border: 1px solid rgba(244, 197, 107, .3);
  padding: 2px 8px; border-radius: 999px;
}
.req-row.done .req-pill {
  background: rgba(74, 216, 166, .14);
  color: var(--jade, #4ad8a6);
  border-color: rgba(74, 216, 166, .35);
}

/* Hint system */
.req-row.has-hint { cursor: pointer; user-select: none; }
.req-row.has-hint:active { background: rgba(255,255,255,.05); }
.req-row.has-hint .req-mark::after {
  content: " ›";
  font-size: 10px;
  color: var(--muted, #6c7287);
  transition: transform .2s;
}
.req-row.has-hint.hint-open .req-mark::after { content: " ›"; transform: rotate(90deg); display: inline-block; }
.req-hint-body {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted, #6c7287);
  background: rgba(244,197,107,.06);
  border: 1px solid rgba(244,197,107,.2);
  border-radius: 8px;
  padding: 8px 10px;
  display: none;
}
.req-row.hint-open .req-hint-body { display: block; }

.battle-cta {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 108, 108, .35);
  background: rgba(255, 108, 108, .08);
  color: #ff8a8a;
  font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  cursor: not-allowed;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.battle-cta.ready {
  padding: 15px 12px;
  border-color: rgba(255, 82, 103, .8);
  background: linear-gradient(160deg, #c83042 0%, #8b0023 50%, #ff3355 100%);
  background-size: 200% 200%;
  color: #fff;
  cursor: pointer;
  letter-spacing: 1.5px;
  font-size: 12px;
  text-shadow: 0 1px 6px rgba(0,0,0,.45);
  animation: pulse-red 2s ease-in-out infinite, bg-shift 4s ease infinite;
}
.battle-cta.ready:active { transform: scale(.97); }
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 82, 103, .4), 0 4px 24px rgba(200,48,66,.5); }
  50%      { box-shadow: 0 0 0 10px rgba(255, 82, 103, 0), 0 4px 24px rgba(200,48,66,.2); }
}
@keyframes bg-shift {
  0%, 100% { background-position: 0% 50%; }
  50%       { background-position: 100% 50%; }
}

/* ----- quiz tier tabs ----- */
.quiz-tier-tabs {
  display: flex; gap: 6px; margin-bottom: 14px;
}
.quiz-tier-tab {
  flex: 1; padding: 8px 6px; border-radius: 10px;
  font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  border: 1px solid var(--border, #1f2336);
  background: rgba(255,255,255,.03); color: var(--muted, #6c7287);
  cursor: pointer; transition: background .15s, border-color .15s;
}
.quiz-tier-tab.active {
  background: rgba(244,197,107,.12);
  border-color: rgba(244,197,107,.4);
  color: var(--gold, #f4c56b);
}
.quiz-tier-tab.done {
  background: rgba(74,216,166,.1);
  border-color: rgba(74,216,166,.35);
  color: var(--jade, #4ad8a6);
}
.quiz-tier-tab.locked { opacity: .4; cursor: not-allowed; }

/* ----- quiz card ----- */
.quiz-card {
  margin: 0 14px;
  padding: 16px;
}
.quiz-card .quiz-q {
  font-size: 14px; font-weight: 700;
  margin: 0 0 12px;
  color: #fff;
  line-height: 1.4;
}
.quiz-card .quiz-options {
  display: grid; gap: 8px;
}
.quiz-opt {
  text-align: left;
  padding: 12px 14px;
  background: rgba(244, 197, 107, .04);
  border: 1px solid rgba(244, 197, 107, .2);
  color: #e9e3d0;
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.quiz-opt:hover { border-color: rgba(244, 197, 107, .5); }
.quiz-opt.correct {
  border-color: rgba(74, 216, 166, .55);
  background: rgba(74, 216, 166, .08);
  color: var(--jade, #4ad8a6);
}
.quiz-opt.wrong {
  border-color: rgba(255, 82, 103, .5);
  background: rgba(255, 82, 103, .07);
  color: #ff8a9a;
  animation: shake .35s ease-in-out;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-4px); }
  40%      { transform: translateX(4px); }
  60%      { transform: translateX(-2px); }
  80%      { transform: translateX(2px); }
}
.quiz-explain {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(74, 216, 166, .06);
  border: 1px solid rgba(74, 216, 166, .25);
  border-radius: 12px;
  color: #d8d2c0;
  font-size: 12px;
  line-height: 1.55;
  display: flex; gap: 8px;
}
.quiz-explain .qx-mark { color: var(--jade, #4ad8a6); flex-shrink: 0; font-weight: 800; }
.quiz-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px;
  font-size: 11px; color: var(--muted, #6c7287);
  letter-spacing: 1px;
}
.quiz-rewards {
  margin-top: 12px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.quiz-rewards .reward-pill {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  background: rgba(244, 197, 107, .12);
  color: var(--gold, #f4c56b);
  border: 1px solid rgba(244, 197, 107, .3);
}
.quiz-complete {
  text-align: center;
  padding: 18px 14px;
}
.quiz-complete .badge {
  display: inline-block;
  font-size: 32px; line-height: 1;
  margin-bottom: 6px;
  filter: drop-shadow(0 0 20px rgba(244, 197, 107, .55));
}
.quiz-complete h3 {
  margin: 0 0 6px;
  font-size: 18px; font-weight: 800;
  background: linear-gradient(180deg, #fff, var(--gold, #f4c56b));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.quiz-complete p {
  margin: 0 0 12px; font-size: 13px; color: #d8d2c0;
}

/* Quiz score ring */
.quiz-score-ring {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 10px;
}
.qsr-num {
  font-size: 48px;
  font-weight: 900;
  line-height: 1;
  color: var(--gold, #f4c56b);
}
.qsr-sep {
  font-size: 28px;
  color: #888;
  line-height: 1;
}
.qsr-total {
  font-size: 28px;
  font-weight: 700;
  color: #d8d2c0;
  line-height: 1;
}

/* Quiz verdict badge */
.quiz-verdict {
  display: inline-block;
  padding: 5px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.qv-pass {
  background: rgba(72, 200, 120, .18);
  color: #48c878;
  border: 1px solid rgba(72, 200, 120, .35);
}
.qv-fail {
  background: rgba(255, 100, 80, .18);
  color: #ff7060;
  border: 1px solid rgba(255, 100, 80, .35);
}
.quiz-result-pass .qsr-num { color: #48c878; }
.quiz-result-fail .qsr-num { color: #ff7060; }

/* ----- scene reader modal ----- */
.scene-modal {
  position: fixed; inset: 0;
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.scene-modal[aria-hidden="false"] { display: flex; }
.scene-modal-bg {
  position: absolute; inset: 0;
  background: rgba(4, 5, 11, .8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in .25s ease-out;
}
.scene-modal-card {
  position: relative;
  width: 100%; max-width: 540px;
  max-height: 92vh;
  margin: 0 auto;
  background: linear-gradient(180deg, #0d1020 0%, #04050b 100%);
  border-top: 1px solid rgba(244, 197, 107, .35);
  border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: slide-up .35s cubic-bezier(.2, .9, .2, 1);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up {
  from { transform: translateY(40%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.scene-modal-glow {
  position: absolute;
  top: -40%; left: -20%; right: -20%; height: 60%;
  background: radial-gradient(closest-side, rgba(244, 197, 107, .35), transparent 70%);
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
}
.scene-close {
  position: absolute; top: 10px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border, #1f2336);
  color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  z-index: 3;
}
.scene-close:hover { background: rgba(255, 255, 255, .12); }
.scene-modal-image {
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 16 / 9;
  display: grid; place-items: center;
  background:
    radial-gradient(140% 100% at 50% 0%, rgba(244, 197, 107, .15), transparent 70%),
    linear-gradient(180deg, #1a1330, #0d1020);
  border-bottom: 1px solid rgba(244, 197, 107, .2);
  overflow: hidden;
}
.scene-modal-image .scene-emoji { display: none; }
.scene-modal-image img,
.scene-modal-image video {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(1.05);
}
.scene-modal-image video {
  filter: none; /* no saturation boost on video */
}
.scene-modal-image iframe {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  border: none;
  display: block;
}
.scene-modal-image img.img-fail { display: none; }
/* Gradient overlay sits above video/iframe but passes pointer events through */
.scene-modal-image::after { z-index: 2; }

/* Dark/gold "image coming soon" placeholder — for missing scene art. */
.scene-modal-image .scene-placeholder {
  position: absolute; inset: 0;
  z-index: 0;
  display: grid; place-items: center;
  text-align: center;
  background:
    radial-gradient(120% 120% at 50% 30%, rgba(244, 197, 107, .12), transparent 65%),
    linear-gradient(180deg, #14101e 0%, #0a0814 100%);
  border-top: 1px solid rgba(244, 197, 107, .14);
  border-bottom: 1px solid rgba(244, 197, 107, .14);
  color: var(--gold, #f4c56b);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; letter-spacing: 2.4px; text-transform: uppercase;
}
.scene-modal-image .scene-placeholder::before {
  content: "✦";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -130%);
  font-size: 24px;
  color: rgba(244, 197, 107, .55);
  filter: drop-shadow(0 0 12px rgba(244, 197, 107, .35));
}
.scene-modal-image:has(img:not(.img-fail)) .scene-placeholder { display: none; }
.scene-modal-image::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 50%, rgba(13, 16, 32, .85) 100%);
  pointer-events: none;
}
.scene-modal-image.atmos-dark::after  { background: linear-gradient(180deg, rgba(10, 7, 25, .35) 0%, rgba(10, 7, 25, .9) 100%); }
.scene-modal-image.atmos-fated::after { background: linear-gradient(180deg, rgba(20, 5, 10, .3) 0%, rgba(20, 5, 10, .9) 100%); }

.scene-modal-body {
  position: relative;
  z-index: 2;
  padding: 18px 18px calc(max(20px, env(safe-area-inset-bottom, 0px) + 12px));
  overflow-y: auto;
  flex: 1;
}
.scene-modal-body .kicker {
  font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--gold, #f4c56b);
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}
.scene-modal-body h2 {
  margin: 6px 0 4px;
  font-size: 22px; font-weight: 800;
  background: linear-gradient(180deg, #fff, var(--gold, #f4c56b));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.scene-fa {
  margin: 0 0 14px;
  font-size: 14px; color: var(--gold, #f4c56b); opacity: .9;
}
.scene-text {
  font-size: 14px; line-height: 1.7;
  color: #d8d2c0;
  margin-bottom: 16px;
}
.scene-reward {
  display: flex; align-items: center; gap: 10px;
  padding: 12px;
  background: rgba(74, 216, 166, .07);
  border: 1px solid rgba(74, 216, 166, .25);
  border-radius: 12px;
  margin-bottom: 14px;
  animation: reward-in .4s ease-out;
}
@keyframes reward-in {
  from { opacity: 0; transform: scale(.95); }
  to   { opacity: 1; transform: scale(1); }
}
.reward-burst {
  font-size: 14px; font-weight: 800; color: var(--jade, #4ad8a6);
  text-shadow: 0 0 16px rgba(74, 216, 166, .35);
}
.reward-meta {
  font-size: 11px; color: var(--muted, #6c7287);
  letter-spacing: 1px;
}
.scene-actions {
  display: flex; gap: 10px;
  margin-top: 4px;
}
.scene-actions .ghost-btn { flex: 1; }
.scene-actions .primary-btn { flex: 2; }

/* ----- mobile compactness ----- */
@media (min-width: 420px) {
  .ch-grid, .codex-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 340px) {
  .ch-grid, .codex-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════════
   FERDOWSI'S DESK — card, modal, parchment, palette variants
   ═══════════════════════════════════════════════════════════════ */

/* Desk card (inline) */
.desk-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  border: 1px solid rgba(244,197,107,.18);
  transition: border-color .2s, transform .1s;
  user-select: none;
}
.desk-card:active { transform: scale(.98); }
.desk-card-done { border-color: rgba(244,197,107,.45); }
.desk-card-icon {
  font-size: 28px;
  flex-shrink: 0;
  line-height: 1;
}
.desk-card-body { flex: 1; min-width: 0; }
.desk-card-kicker {
  font-size: 9px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--gold, #f4c56b);
  opacity: .7;
  margin-bottom: 2px;
}
.desk-card-title {
  font-size: 14px;
  font-weight: 700;
  color: #f0ead8;
  margin-bottom: 4px;
}
.desk-card-meta {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--muted, #6c7287);
  margin-bottom: 5px;
}
.desk-card-preview {
  font-size: 12px;
  color: #9e98a8;
  line-height: 1.45;
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.desk-card-arrow {
  font-size: 18px;
  color: var(--muted, #6c7287);
  flex-shrink: 0;
}

/* Modal overlay */
.desk-modal {
  position: fixed; inset: 0; z-index: 320;
  display: flex; align-items: flex-end; justify-content: center;
  transition: opacity .25s;
}
.desk-modal[aria-hidden="true"] {
  opacity: 0;
  pointer-events: none;
}
.desk-modal[aria-hidden="false"] { opacity: 1; }
.desk-modal-bg {
  position: absolute; inset: 0;
  background: rgba(2,3,8,.82);
  backdrop-filter: blur(4px);
}
.desk-modal-card {
  position: relative;
  width: 100%; max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.25,.8,.25,1);
  -webkit-overflow-scrolling: touch;
}
.desk-modal[aria-hidden="false"] .desk-modal-card {
  transform: translateY(0);
}

/* Parchment core */
.desk-parchment {
  padding: 28px 22px calc(max(32px, env(safe-area-inset-bottom, 0px) + 20px));
  background: #0e0c18;
  border-top: 2px solid rgba(244,197,107,.30);
}

/* Palette variants */
[data-desk-palette="normal"]    .desk-parchment { background: #0e0c18; }
[data-desk-palette="melancholic"] .desk-parchment {
  background: linear-gradient(180deg, #0b1018 0%, #0e0c18 100%);
  border-top-color: rgba(100,160,200,.35);
}
[data-desk-palette="tragic"] .desk-parchment {
  background: linear-gradient(180deg, #080c14 0%, #0d0c16 100%);
  border-top-color: rgba(140,110,200,.35);
}
[data-desk-palette="melancholic"] .desk-title,
[data-desk-palette="melancholic"] .desk-section-label { color: #7bc2e0; }
[data-desk-palette="tragic"] .desk-title,
[data-desk-palette="tragic"] .desk-section-label { color: #a890c8; }

/* Parchment elements */
.desk-quill-icon { font-size: 32px; text-align: center; margin-bottom: 6px; opacity: .85; }
.desk-meta {
  display: flex; justify-content: center; gap: 14px;
  font-size: 11px; color: var(--muted, #6c7287);
  margin-bottom: 10px;
}
.desk-title {
  font-size: 17px; font-weight: 800;
  color: var(--gold, #f4c56b);
  text-align: center;
  margin: 0 0 20px;
  letter-spacing: .4px;
}
.desk-section { margin-bottom: 18px; }
.desk-section-label {
  font-size: 9px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--gold, #f4c56b);
  opacity: .75;
  margin-bottom: 6px;
}
.desk-section-body {
  font-size: 13.5px;
  line-height: 1.65;
  color: #ccc5b6;
  margin: 0;
}
.desk-read-btn { width: 100%; margin-top: 8px; }

/* Close button */
.desk-close {
  position: absolute; top: 14px; right: 16px;
  background: rgba(255,255,255,.08);
  border: none; border-radius: 50%;
  width: 30px; height: 30px;
  font-size: 18px; color: #ccc; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}

/* ----- RTL friendliness ----- */
html[dir="rtl"] .ch-hero-fade {
  background:
    linear-gradient(180deg, rgba(4, 5, 11, .35) 0%, rgba(4, 5, 11, .85) 70%, rgba(4, 5, 11, .98) 100%),
    linear-gradient(270deg, rgba(4, 5, 11, .85) 0%, rgba(4, 5, 11, .25) 60%, transparent 100%);
}
html[dir="rtl"] .scene-card { grid-template-columns: auto 1fr 56px; }
