/* Wayang Bayang: a carved panggung frame round a lamp-lit kelir, on Rehat's cream paper. */
.page {
  --bb-wood: #5A2E17;
  --bb-wood-2: #8A4B22;
  --bb-brass: #C99A3B;
  --bb-ink: #1E140C;
  --bb-cloth-edge: #B98A50;
}
.game-title, .panel h2, .banner h2 { font-family: var(--font-round); font-weight: 600; }

/* stage */
.board-wrap { display: block; container-type: inline-size; }
.bb-stage { background: linear-gradient(180deg, var(--bb-wood-2), var(--bb-wood)); border-radius: var(--radius-lg); padding: clamp(8px, 2.4cqw, 18px); box-shadow: var(--shadow-card); }
.bb-kelir { display: block; width: 100%; height: auto; aspect-ratio: 5 / 3; border-radius: var(--radius-sm); outline: 2px solid var(--bb-cloth-edge); touch-action: none; user-select: none; -webkit-user-select: none; cursor: default; }
.bb-kelir:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }
.bb-ghost { opacity: .16; }
.bb-ghost path { fill: var(--bb-ink); }
.bb-shadow path { fill: var(--bb-ink); fill-opacity: .9; }
.bb-shadow { cursor: grab; }
.bb-selpath { fill: none; stroke: var(--bb-brass); stroke-width: 2.5; stroke-linejoin: round; pointer-events: none; }
/* M11: the outline fades in whenever the stage inserts it for a newly selected puppet */
.bb-selpath.is-in { animation: bb-sel-in var(--dur-1) var(--ease) both; }
@keyframes bb-sel-in { from { opacity: 0; } to { opacity: 1; } }
.bb-hintpath { fill: none; stroke: var(--bb-brass); stroke-width: 2.5; stroke-dasharray: 8 6; pointer-events: none; }
.bb-stage.is-done .bb-ghost { opacity: 0; transition: opacity var(--dur-3) var(--ease); }
.bb-sweep { pointer-events: none; }
.bb-sweep path { fill: var(--bb-ink); fill-opacity: .9; }

/* the lamp light over the kelir (M1 dim, M8 flare, M12 flicker): opacity-only overlays, never hit-tested */
.bb-screen { position: relative; }
.bb-lamp, .bb-flare, .bb-dim { position: absolute; inset: 0; border-radius: var(--radius-sm); pointer-events: none; opacity: 0; }
/* the flame's hot spot over the cloth, warm brown at the edges; .03 is the rest level (mid of the flicker) */
.bb-lamp { opacity: .03; will-change: opacity; background: radial-gradient(ellipse 62% 72% at 50% 46%, #FFF3D2 0%, rgba(255, 226, 164, .7) 42%, rgba(138, 75, 34, .85) 100%); }
.bb-lamp.is-flicker { animation: bb-flicker 6.4s ease-in-out infinite; }
/* irregular, slow and smooth: eased steps of about half a second, opacity within 0..0.06, no flashes */
@keyframes bb-flicker {
  0% { opacity: .03; }
  8% { opacity: .05; }
  15% { opacity: .02; }
  23% { opacity: .045; }
  31% { opacity: .035; }
  38% { opacity: .06; }
  47% { opacity: .025; }
  55% { opacity: .04; }
  63% { opacity: .012; }
  71% { opacity: .05; }
  80% { opacity: .03; }
  90% { opacity: .055; }
  100% { opacity: .03; }
}
.bb-flare, .bb-dim { will-change: opacity; }
.bb-flare { background: radial-gradient(ellipse 58% 68% at 50% 46%, #FFF6DC 0%, rgba(255, 224, 160, .6) 50%, rgba(255, 210, 140, 0) 100%); }
.bb-dim { background: radial-gradient(ellipse 70% 80% at 50% 46%, #3A2414 0%, #1E140C 100%); }

/* rail */
.bb-rail { display: flex; gap: 8px; justify-content: center; margin-top: 10px; padding: 8px; border-radius: var(--radius-md); background: rgba(0, 0, 0, .18); overflow-x: auto; }
.bb-slot { display: grid; justify-items: center; gap: 2px; min-width: 64px; padding: 6px 8px; border: 1px solid transparent; border-radius: var(--radius-sm); background: rgba(255, 246, 223, .12); color: #F6E7C8; font: 600 12px/1.2 var(--font-body); cursor: pointer;
  transition: opacity var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), background-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease); }
.bb-slot svg { width: auto; height: 44px; }
.bb-slot svg path { fill: #F6E7C8; }
.bb-slot.is-up { opacity: .45; }
.bb-slot.is-sel { border-color: var(--bb-brass); opacity: 1; transform: translateY(-2px); }
.bb-slot:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }
/* M10: hover emphasis on real hover only, the same emphasis on keyboard focus */
@media (hover: hover) {
  .bb-slot:not(:disabled):hover { background: rgba(255, 246, 223, .2); }
  .bb-slot:not(:disabled):not(.is-sel):hover { border-color: rgba(201, 154, 59, .55); }
  .bb-slot.is-up:not(.is-sel):not(:disabled):hover { opacity: .7; }
}
.bb-slot:focus-visible { background: rgba(255, 246, 223, .2); }
.bb-slot:not(.is-sel):focus-visible { border-color: rgba(201, 154, 59, .55); }
.bb-slot.is-up:not(.is-sel):focus-visible { opacity: .7; }
/* while the scene open drives the slots from JS */
.bb-stage.is-opening .bb-slot { transition: none; }

/* D2: the stage view: the lamp, the raised puppets as cards and the cloth, seen from the side. A picture
   (the header is a button with aria-expanded; only the drawing and caption are aria-hidden): a strip under the kelir, or beside it on a wide screen, where the frame
   grows out of the page column by the panel's width so the kelir keeps its size. */
.bb-view { margin-top: 10px; border-radius: var(--radius-md); background: rgba(0, 0, 0, .18); color: #F6E7C8; user-select: none; -webkit-user-select: none; }
.bb-view__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 40px; margin: 0; padding: 6px 12px; border: 0; border-radius: var(--radius-md); background: transparent; color: inherit; font: 600 12px/1.2 var(--font-body); letter-spacing: .02em; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color var(--dur-1) var(--ease); }
.bb-view__bar:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; background: rgba(255, 246, 223, .08); }
.bb-view__chev { width: 7px; height: 7px; margin-right: 2px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; opacity: .8; transform: translateY(-2px) rotate(45deg); transition: transform var(--dur-2) var(--ease); }
.bb-view.is-collapsed .bb-view__chev { transform: rotate(-45deg); }
@media (hover: hover) { .bb-view__bar:hover { background: rgba(255, 246, 223, .08); } }
.bb-view__svg { display: block; width: min(calc(100% - 16px), 200px); height: auto; margin: 0 auto 8px; }
.bb-view__note { display: none; margin: 0 12px 10px; font: 500 12px/1.35 var(--font-body); color: rgba(246, 231, 200, .82); }
.bb-view.is-collapsed .bb-view__svg, .bb-view.is-collapsed .bb-view__note { display: none; }
.bb-view:not(.is-collapsed) .bb-view__svg { animation: bb-view-in var(--dur-2) var(--ease) both; }
@keyframes bb-view-in { from { opacity: 0; } to { opacity: 1; } }
.bb-view__svg .sv-floor { fill: rgba(201, 154, 59, .1); stroke: rgba(201, 154, 59, .32); stroke-width: .8; }
.bb-view__svg .sv-cloth-edge { fill: none; stroke: var(--bb-cloth-edge); stroke-width: 1.4; stroke-linejoin: round; }
.bb-view__svg .sv-shadow { fill: var(--bb-ink); }
.bb-view__svg .sv-beam { fill: #FFE6A6; fill-opacity: .14; }
.bb-view__svg .sv-ray { stroke: #FFE6A6; stroke-width: .9; stroke-opacity: .8; stroke-linecap: round; }
.bb-view__svg .sv-flame { fill: #FFF6DC; }
.bb-view__svg .sv-card { opacity: .6; }
.bb-view__svg .sv-card.is-sel { opacity: 1; }
.bb-view__svg .sv-card rect { fill: #EAD3A2; stroke: rgba(30, 20, 12, .55); stroke-width: .8; }
.bb-view__svg .sv-card.is-sel rect { stroke: var(--bb-brass); stroke-width: 1.6; }
.bb-view__svg .sv-sil { fill: var(--bb-wood); }
@media (min-width: 900px) {
  .board-wrap.bb-view-open { margin-inline: calc(-1 * min(120px, (100vw - 720px) / 2 - 16px)); }
  .board-wrap.bb-view-open .bb-stage { display: grid; grid-template-columns: minmax(0, 1fr) 216px; grid-template-areas: 'screen view' 'rail rail'; column-gap: 12px; align-items: start; }
  .board-wrap.bb-view-open .bb-screen { grid-area: screen; }
  .board-wrap.bb-view-open .bb-view { grid-area: view; margin-top: 0; }
  .board-wrap.bb-view-open .bb-rail { grid-area: rail; }
  .board-wrap.bb-view-open .bb-view__svg { width: calc(100% - 16px); }
  .bb-view__note { display: block; }
}

/* tools */
.bb-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-top: var(--space-3); }
.bb-depth { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; max-width: 420px; font: 600 13px var(--font-body); color: var(--color-text-muted); }
.bb-depth input { flex: 1; accent-color: var(--bb-brass); min-height: 44px; }
.bb-tool { min-width: 44px; min-height: 44px; font-size: 20px; }
@media (max-width: 560px) {
  .bb-depth { flex-basis: 100%; max-width: none; }
}

/* setup list */
.bb-scenes { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bb-scene { width: 100%; display: grid; grid-template-columns: 2em 1fr auto; grid-template-areas: 'n title best' 'n teach best'; align-items: center; gap: 0 10px; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); color: var(--color-text); text-align: left; cursor: pointer; }
.bb-scene:hover { box-shadow: var(--shadow-card-hover); }
.bb-scene.is-last { border-color: var(--color-accent); }
/* M9: the scene just performed: its ✓ pops once (the ✓ itself is the persistent cue) */
.bb-scene.is-new .bb-scene__best { animation: rh-pop var(--dur-2) var(--ease) both; }
.bb-scene__n { grid-area: n; font: 600 18px var(--font-round); color: var(--color-text-muted); }
.bb-scene__title { grid-area: title; font-weight: 700; }
.bb-scene__teach { grid-area: teach; font-size: 13px; color: var(--color-text-muted); }
.bb-scene__best { grid-area: best; font-variant-numeric: tabular-nums; color: var(--color-good); white-space: nowrap; }

/* story card */
.bb-story { text-align: left; max-width: 60ch; margin: var(--space-2) auto var(--space-3); }
.bb-story__text { margin: 0 0 var(--space-2); }
.bb-story__note { margin: 0; padding: var(--space-2) var(--space-3); border-left: 3px solid var(--bb-brass); background: var(--color-surface-2); border-radius: var(--radius-sm); font-size: 14px; }
.bb-sound { min-width: 44px; }
.bb-lamp-btn[aria-pressed="false"] .bb-glyph { filter: grayscale(1); opacity: .5; }

/* M7: the committed match is close to solved: a persistent warm tint, one pop on entering */
.chip.is-close { border-color: var(--bb-brass); background: #F6E6C2; }
.chip.is-close strong { color: #6B4A12; }
.chip.is-pop { animation: rh-pop var(--dur-2) var(--ease); }

@media (prefers-reduced-motion: reduce) {
  .bb-stage.is-done .bb-ghost { transition: none; }
  .bb-selpath.is-in { animation: none; }
  .bb-slot { transition: none; }
  .bb-view__bar, .bb-view__chev { transition: none; }
  .bb-view:not(.is-collapsed) .bb-view__svg { animation: none; } /* D2: a static diagram */
  .chip.is-pop, .bb-scene.is-new .bb-scene__best { animation: none; }
  /* the flicker starts off here; a player who switches it on deliberately gets it despite Rehat's global switch */
  .bb-lamp.is-flicker { animation-duration: 6.4s !important; animation-iteration-count: infinite !important; }
}
