/* Theatre of the mind (theatre.js): the stage over the board and the GM's Director window. */

#theatre {
  position: absolute; inset: 0; z-index: 6; overflow: hidden; isolation: isolate;
  background: #04060a; opacity: 0; transition: opacity .9s var(--ease);
  --bar-top: 7%; --bar-bot: 17%;
}
#theatre.on { opacity: 1; }
#theatre.peek { opacity: .1; pointer-events: none; }
#theatre.peek .th-peek { pointer-events: auto; opacity: 1; }

/* background: two layers cross-fade, each with a slow push (Ken Burns) and soft, blurred edges */
.th-backdrop { position: absolute; inset: -2%; }
.th-bg {
  position: absolute; inset: 0; background: center / cover no-repeat; opacity: 0;
  transition: opacity 1.6s ease; transform-origin: 50% 50%;
  -webkit-mask-image: radial-gradient(ellipse 78% 72% at 50% 46%, #000 52%, transparent 100%);
  mask-image: radial-gradient(ellipse 78% 72% at 50% 46%, #000 52%, transparent 100%);
  filter: saturate(.92) brightness(.86);
}
.th-bg.on { opacity: 1; animation: thKen 46s ease-in-out infinite alternate; }
@keyframes thKen {
  from { transform: scale(1.06) translate(var(--kx0, 0), var(--ky0, 0)); }
  to { transform: scale(1.17) translate(var(--kx1, 0), var(--ky1, 0)); }
}
.th-blank {
  position: absolute; inset: 0; opacity: 0; transition: opacity 1.2s;
  background:
    radial-gradient(ellipse 50% 38% at 50% 58%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 70%),
    radial-gradient(ellipse 90% 60% at 50% 110%, rgba(60, 46, 24, .55), transparent 70%),
    linear-gradient(180deg, #070a12, #04060a 70%);
}
#theatre.no-bg .th-blank { opacity: 1; }
.th-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse 85% 80% at 50% 45%, transparent 55%, rgba(2, 3, 6, .82) 100%); }
.th-floor { position: absolute; left: 0; right: 0; bottom: var(--bar-bot); height: 26%; pointer-events: none; background: linear-gradient(0deg, rgba(3, 4, 8, .85), transparent); }
.th-motes { position: absolute; inset: 0; pointer-events: none; opacity: .7; }

/* letterbox */
.th-bar { position: absolute; left: 0; right: 0; background: #020305; z-index: 80; transition: transform 1.1s var(--ease); }
.th-bar.top { top: 0; height: var(--bar-top); transform: translateY(-100%); }
.th-bar.bot { bottom: 0; height: var(--bar-bot); transform: translateY(100%); display: grid; place-items: center; }
.th-bar.top::after, .th-bar.bot::before { content: ""; position: absolute; left: 8%; right: 8%; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 40%, transparent), transparent); }
.th-bar.top::after { bottom: 0; }
.th-bar.bot::before { top: 0; }
#theatre.on .th-bar { transform: none; }

/* caption */
.th-cap { max-width: min(880px, 86%); text-align: center; opacity: 0; transform: translateY(8px); transition: opacity .5s, transform .5s var(--ease); }
.th-cap.in { opacity: 1; transform: none; }
.th-cap.empty { opacity: 0; }
.th-cap-kick { font: 700 8.5px var(--mono); letter-spacing: .46em; text-transform: uppercase; color: var(--accent); margin-bottom: 7px; min-height: 1px; }
.th-cap-kick:empty { display: none; }
.th-cap-text {
  font: italic 400 clamp(15px, 1.75vw, 23px)/1.42 var(--serif); color: #f1ead9; letter-spacing: .01em;
  text-shadow: 0 2px 14px #000; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* actors */
.th-cast { position: absolute; inset: 0; z-index: 20; }
.th-actor {
  --s: 1; --ty: 0px; --rot: 0deg; --b: 1; --sat: 1; --con: 1; --glow: rgba(0, 0, 0, 0); --rim: transparent;
  position: absolute; left: var(--x, 50%); bottom: calc(var(--bar-bot) - 1px);
  height: 66%; width: auto; max-width: 31%; aspect-ratio: 3 / 4.15;
  transform: translateX(-50%) translateY(var(--ty)) rotate(var(--rot)) scale(var(--s));
  transform-origin: 50% 100%;
  transition: left .8s var(--ease), transform .7s var(--ease), opacity .7s ease, filter .7s ease;
  filter: brightness(var(--b)) saturate(var(--sat)) contrast(var(--con));
  pointer-events: none;
}
#theatre.has-focus .th-actor:not(.focus) { --b: .5; --sat: .6; --s: .93; }
.th-actor.focus { --s: 1.07; }
.th-actor.enter, .th-actor.leave { opacity: 0; }
.th-actor.enter.from-left, .th-actor.leave.from-left { transform: translateX(calc(-50% - 140px)) translateY(var(--ty)) scale(var(--s)); }
.th-actor.enter.from-right, .th-actor.leave.from-right { transform: translateX(calc(-50% + 140px)) translateY(var(--ty)) scale(var(--s)); }
.th-actor.enter.from-center, .th-actor.leave.from-center { transform: translateX(-50%) translateY(40px) scale(calc(var(--s) * .96)); }

.th-fig { position: absolute; inset: 0; filter: drop-shadow(0 0 22px var(--glow)); transition: filter .7s ease; }
.th-img, .th-initial, .th-tint {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; border-radius: 3px;
  -webkit-mask-image: linear-gradient(0deg, transparent 0, #000 30%), radial-gradient(ellipse 58% 54% at 50% 46%, #000 40%, transparent 96%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(0deg, transparent 0, #000 30%), radial-gradient(ellipse 58% 54% at 50% 46%, #000 40%, transparent 96%);
  mask-composite: intersect;
}
.th-initial { display: grid; place-items: center; font: 400 clamp(60px, 9vw, 120px) var(--serif); color: #eee7d9; background: radial-gradient(circle at 50% 35%, #2a3348, #0b0f18 70%); }
.th-tint { pointer-events: none; opacity: 0; transition: opacity .7s; background: transparent; }
.th-actor.focus .th-fig::after {
  content: ""; position: absolute; left: 18%; right: 18%; bottom: 21%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent); box-shadow: 0 0 18px var(--accent); opacity: .85;
}
.th-plate {
  position: absolute; left: 50%; bottom: 4%; transform: translate(-50%, 0); white-space: nowrap; text-align: center; z-index: 2;
  opacity: .0; transition: opacity .6s, transform .6s var(--ease);
}
.th-actor.focus .th-plate, #theatre:not(.has-focus) .th-plate { opacity: 1; }
.th-plate-kick { display: block; font: 700 7.5px var(--mono); letter-spacing: .4em; text-transform: uppercase; color: var(--accent); margin-bottom: 3px; min-height: 9px; }
.th-plate-name { display: block; font: 400 clamp(14px, 1.5vw, 21px) var(--serif); letter-spacing: .12em; text-transform: uppercase; color: #f1ead9; text-shadow: 0 2px 10px #000, 0 0 3px #000; }
.th-rays { position: absolute; left: 50%; top: 38%; width: 190%; aspect-ratio: 1; transform: translate(-50%, -50%); opacity: 0; pointer-events: none; transition: opacity .8s; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 214, 128, .16) 0 5deg, transparent 5deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 15%, transparent 66%); mask-image: radial-gradient(circle, #000 15%, transparent 66%);
}

/* moods */
.th-actor.mood-calm { --glow: rgba(110, 160, 230, .35); }
.th-actor.mood-calm .th-fig { animation: thBreathe 6s ease-in-out infinite; }
.th-actor.mood-angry { --glow: rgba(235, 60, 40, .62); --con: 1.14; --sat: 1.18; }
.th-actor.mood-angry .th-tint { opacity: .22; background: linear-gradient(0deg, rgba(200, 30, 20, .9), transparent 70%); }
.th-actor.mood-angry .th-fig { animation: thSeethe 2.2s ease-in-out infinite; }
.th-actor.mood-angry.mood-in .th-fig { animation: thJolt .5s ease 1, thSeethe 2.2s ease-in-out .5s infinite; }
.th-actor.mood-afraid { --glow: rgba(140, 190, 200, .3); --sat: .62; --ty: 6px; --s: .97; }
.th-actor.mood-afraid .th-tint { opacity: .3; background: linear-gradient(0deg, rgba(40, 70, 110, .9), transparent 80%); }
.th-actor.mood-afraid .th-fig { animation: thTremble .18s linear infinite; }
.th-actor.mood-wounded { --glow: rgba(150, 20, 20, .45); --sat: .6; --ty: 12px; --rot: -1.6deg; }
.th-actor.mood-wounded .th-tint { opacity: .5; background: linear-gradient(0deg, rgba(110, 10, 10, .85), transparent 60%), radial-gradient(ellipse at 30% 40%, rgba(120, 0, 0, .35), transparent 60%); }
.th-actor.mood-triumphant { --glow: rgba(255, 204, 110, .7); --ty: -14px; --con: 1.06; --sat: 1.1; }
.th-actor.mood-triumphant .th-rays { opacity: 1; animation: thRays 40s linear infinite; }
.th-actor.mood-triumphant .th-tint { opacity: .25; background: linear-gradient(180deg, rgba(255, 220, 140, .55), transparent 60%); }
#theatre.has-focus .th-actor.focus.mood-afraid { --s: 1.03; }
#theatre.has-focus .th-actor.focus.mood-wounded { --s: 1.04; }
#theatre.has-focus .th-actor:not(.focus) .th-rays { opacity: .25; }
.th-actor.mood-in .th-tint { animation: thFlash .9s ease 1; }

@keyframes thBreathe { 50% { transform: translateY(-3px) scale(1.008); } }
@keyframes thSeethe { 50% { transform: scale(1.012); filter: drop-shadow(0 0 34px var(--glow)); } }
@keyframes thJolt { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes thTremble { 0% { transform: translate(0, 0); } 25% { transform: translate(.8px, -.5px); } 50% { transform: translate(-.6px, .4px); } 75% { transform: translate(.5px, .6px); } }
@keyframes thRays { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes thFlash { 0% { opacity: .9; } 100% { opacity: var(--tint-o, .3); } }

/* preview tag, map peek */
.th-preview-tag {
  position: absolute; top: calc(var(--bar-top) + 12px); left: 50%; transform: translateX(-50%); z-index: 90; display: none;
  padding: 4px 12px; border: 1px dashed var(--accent-dim); border-radius: 3px; background: rgba(5, 7, 11, .75);
  font: 700 8px var(--mono); letter-spacing: .3em; text-transform: uppercase; color: var(--accent);
}
#theatre.preview .th-preview-tag { display: block; }
.th-peek {
  position: absolute; top: calc(var(--bar-top) + 10px); right: 12px; z-index: 95; opacity: .55;
  padding: 5px 10px; font: 700 8.5px var(--mono); letter-spacing: .16em; text-transform: uppercase;
  background: rgba(5, 7, 11, .7); transition: opacity .2s;
}
.th-peek:hover { opacity: 1; }

/* reduced motion: fades only, no drift, no shaking */
@media (prefers-reduced-motion: reduce) {
  .th-bg.on, .th-actor .th-fig, .th-actor .th-rays, .th-actor .th-tint, .th-motes i { animation: none !important; }
  .th-actor, .th-actor.enter, .th-actor.leave { transition: opacity .5s ease, filter .5s ease !important; }
  .th-actor.enter.from-left, .th-actor.enter.from-right, .th-actor.enter.from-center, .th-actor.leave.from-left, .th-actor.leave.from-right, .th-actor.leave.from-center { transform: translateX(-50%) translateY(var(--ty)) scale(var(--s)); }
  .th-bar { transition: none; }
}
body.reduce-motion .th-bg.on, body.reduce-motion .th-actor .th-fig, body.reduce-motion .th-actor .th-rays, body.reduce-motion .th-actor .th-tint, body.reduce-motion .th-motes i { animation: none !important; }
body.reduce-motion .th-actor { transition: opacity .5s ease, filter .5s ease !important; }
body.reduce-motion .th-actor.enter.from-left, body.reduce-motion .th-actor.enter.from-right, body.reduce-motion .th-actor.enter.from-center,
body.reduce-motion .th-actor.leave.from-left, body.reduce-motion .th-actor.leave.from-right, body.reduce-motion .th-actor.leave.from-center { transform: translateX(-50%) translateY(var(--ty)) scale(var(--s)); }
body.reduce-motion .th-bar { transition: none; }

@media (max-width: 700px) {
  #theatre { --bar-top: 5%; --bar-bot: 20%; }
  .th-actor { height: 52%; max-width: 36%; }
  .th-cap-text { font-size: 15px; -webkit-line-clamp: 4; }
}

/* ---------- Director window ---------- */

.thd { display: flex; flex-direction: column; gap: 2px; }
.thd h4:first-of-type { margin-top: 12px; }
.thd-status { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 4px; background: rgba(5, 8, 13, .55); }
.thd-status.live { border-color: var(--accent-dim); background: linear-gradient(90deg, rgba(220, 179, 92, .1), rgba(5, 8, 13, .55)); }
.thd-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim-2); flex: none; }
.thd-status.live .thd-dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.thd-state { font: 700 8.5px var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--ink-2); }
.thd-status.live .thd-state { color: var(--accent); }

.thd-bgrow { display: flex; gap: 10px; align-items: stretch; }
.thd-bg {
  width: 172px; aspect-ratio: 16 / 9; flex: none; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--rule-2); border-radius: 4px;
  background: radial-gradient(ellipse at 50% 60%, rgba(220, 179, 92, .08), transparent 70%), #070a11; color: var(--dim-2); font-size: 10.5px; text-align: center; padding: 0;
  transition: border-color .15s, box-shadow .15s;
}
.thd-bg span { padding: 0 10px; }
.thd-bg img { width: 100%; height: 100%; object-fit: cover; }
.thd-bg.drag, .thd-drop.drag, .thd-cast.drag { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim), 0 0 18px color-mix(in srgb, var(--accent) 22%, transparent); }
.thd-bgside { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.thd-art { display: flex; flex-wrap: wrap; gap: 4px; }
.thd-art-pick { width: 46px; height: 32px; padding: 0; overflow: hidden; border-radius: 3px; }
.thd-art-pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thd-art-pick.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.thd-hint { margin: 2px 0; font-size: 10.5px; color: var(--dim-2); }
.thd-hint kbd { font-size: 9px; padding: 1px 5px; }

.thd-cast { display: flex; flex-direction: column; gap: 5px; border-radius: 4px; }
.thd-actor {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 4px;
  background: linear-gradient(150deg, rgba(25, 32, 46, .75), rgba(8, 11, 18, .85)); transition: border-color .15s, box-shadow .15s, transform .15s var(--ease);
}
.thd-actor:hover { border-color: var(--rule-2); }
.thd-actor.focus { border-color: var(--accent-dim); box-shadow: inset 2px 0 var(--accent), 0 0 16px color-mix(in srgb, var(--accent) 10%, transparent); }
.thd-key { width: 22px; height: 22px; padding: 0; flex: none; font: 700 10px var(--mono); }
.thd-actor.focus .thd-key { color: #1b1408; background: var(--accent); border-color: var(--accent); }
.thd-thumb { width: 40px; height: 52px; flex: none; object-fit: cover; object-position: 50% 20%; border-radius: 3px; border: 1px solid var(--rule-2); }
.thd-thumb.blank { display: grid; place-items: center; font: 20px var(--serif); color: var(--ink-2); background: linear-gradient(145deg, #1a2233, #0c111b); }
.thd-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.thd-mid > input { padding: 4px 7px; font: 400 14px var(--serif); letter-spacing: .03em; }
.thd-chips { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.thd-seg { display: inline-flex; }
.thd-seg button { border-radius: 0; padding: 3px 7px; font-size: 10px; }
.thd-seg button:first-child { border-radius: 3px 0 0 3px; }
.thd-seg button:last-child { border-radius: 0 3px 3px 0; }
.thd-seg button + button { margin-left: -1px; }
.thd-moods { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.thd-mood { padding: 2px 6px; font: 700 7.5px var(--mono); letter-spacing: .1em; text-transform: uppercase; border-radius: 10px; background: transparent; color: var(--dim); border-color: var(--rule); }
.thd-mood.on { color: #10131a; border-color: transparent; }
.thd-mood.on[data-mood=none] { background: var(--dim); }
.thd-mood.on[data-mood=calm] { background: #7aa6e6; }
.thd-mood.on[data-mood=angry] { background: #e2584a; }
.thd-mood.on[data-mood=afraid] { background: #8fb9c2; }
.thd-mood.on[data-mood=wounded] { background: #b0423d; color: #fff; }
.thd-mood.on[data-mood=triumphant] { background: var(--accent); }
.thd-acts { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.thd-focus { min-width: 86px; }
.thd-order { display: inline-flex; gap: 3px; }
.thd-order button { padding: 2px 7px; }
.thd-drop {
  display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 12px; border: 1px dashed var(--rule-2); border-radius: 4px;
  color: var(--dim); font-size: 11px; text-align: center; transition: border-color .15s, box-shadow .15s;
}
.thd-pick { max-width: 200px; }
.thd-caprow { display: flex; gap: 6px; align-items: flex-start; }
.thd-caption { font: italic 14px/1.5 var(--serif); color: #eee7d9; }
