/* =========================================================
   Hamlet role-play + study book — lore/hamlet/
   The game is one frame, like a visual novel:
   drawn scenery → big character sprites → text box on top.
   ========================================================= */

.h-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.h-toolbar .is-on, .h-actions .is-on { border-color: var(--accent); background: var(--accent-tint); }
.h-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }

/* ---------- The frame ---------- */
.h-play {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 500px;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0b0b12;
  box-shadow: var(--shadow);
  container-type: size;   /* sprites are sized from the frame (cqw / cqh) */
  isolation: isolate;
}
/* Theatre mode: the frame fills the window. Full screen: the whole screen. */
body.theatre-mode .h-layout { grid-template-columns: minmax(0, 1fr); }
body.theatre-mode .h-play { aspect-ratio: auto; height: calc(100vh - 28px); height: calc(100dvh - 28px); }
.h-play:fullscreen { aspect-ratio: auto; width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; }

/* ---------- Scenery (drawn in hamlet-scenery.js) ---------- */
.h-scenery { position: absolute; inset: 0; }
.h-scenery svg { display: block; width: 100%; height: 100%; }
.sc-twinkle { animation: sc-twinkle 3s ease-in-out infinite; }
.sc-flame { transform-box: fill-box; transform-origin: 50% 100%; animation: sc-flame 0.28s ease-in-out infinite alternate; }
.sc-glow { animation: sc-glow 2.2s ease-in-out infinite; }
.sc-mist { animation: sc-mist 16s ease-in-out infinite alternate; }
.sc-mist--slow { animation-duration: 24s; animation-direction: alternate-reverse; }
.sc-fall { animation: sc-fall 10s linear infinite; }
.sc-sway { transform-box: fill-box; transform-origin: 50% 0; animation: sc-sway 4s ease-in-out infinite alternate; }
.sc-shimmer { animation: sc-twinkle 2.4s ease-in-out infinite; }
@keyframes sc-twinkle { 50% { opacity: 0.25; } }
@keyframes sc-flame { to { transform: scale(0.88, 1.14) rotate(3deg); } }
@keyframes sc-glow { 50% { opacity: 0.28; } }
@keyframes sc-mist { from { transform: translateX(-40px); } to { transform: translateX(60px); } }
@keyframes sc-fall { to { transform: translate(-40px, 480px) rotate(200deg); } }
@keyframes sc-sway { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }

/* Darkens the edges; changes colour with what is happening */
.h-vignette { position: absolute; inset: 0; z-index: 1; pointer-events: none; background: radial-gradient(ellipse at 50% 40%, transparent 45%, rgba(0, 0, 0, 0.55)); transition: background 0.6s; }
.h-play.is-ghostly .h-vignette { background: radial-gradient(ellipse at 50% 40%, rgba(120, 190, 255, 0.12) 20%, rgba(10, 30, 70, 0.75)); }
.h-play.is-narrating .h-vignette { background: radial-gradient(ellipse at 50% 40%, rgba(0, 0, 0, 0.15) 30%, rgba(0, 0, 0, 0.7)); }
.h-play[data-mode="card"] .h-vignette { background: radial-gradient(ellipse at 50% 30%, rgba(0, 0, 0, 0.1) 30%, rgba(0, 0, 0, 0.7)); }

/* ---------- Characters: the most important thing on screen ---------- */
.h-cast { position: absolute; left: 0; right: 0; bottom: 96px; z-index: 2; display: flex; justify-content: center; align-items: flex-end; padding: 0 2%; pointer-events: none; }
.h-actor {
  position: relative; flex: 0 1 auto; min-width: 0;
  width: min(36cqw, 68cqh);
  margin: 0 -2%;
  transform: scale(0.9); transform-origin: bottom center;
  filter: brightness(0.82) saturate(0.85);
  transition: transform 0.35s cubic-bezier(0.3, 0.7, 0.4, 1.4), filter 0.3s;
}
.h-actor.is-speaking { transform: scale(1.1); filter: drop-shadow(0 0 18px rgba(255, 255, 255, 0.25)); z-index: 2; }
.h-play.is-narrating .h-actor { filter: brightness(0.55) saturate(0.6); }
.h-play[data-mode="choice"] .h-actor, .h-play[data-mode="card"] .h-actor { filter: brightness(0.9); }
.h-sprite { transform-origin: bottom center; }
.h-actor.is-entering .h-sprite { animation: h-enter 0.55s cubic-bezier(0.2, 0.8, 0.3, 1.2) 1; }
.h-actor.is-hopping .h-sprite { animation: h-hop 0.38s ease-out 1; }
.h-actor.is-ghost .h-sprite { animation: h-float 3.2s ease-in-out infinite; filter: drop-shadow(0 0 16px rgba(140, 200, 255, 0.8)); }
.h-avatar { width: 100%; height: auto; display: block; }
.h-avatar .aura { animation: h-pulse 2.6s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
.h-avatar.emo-angry { animation: h-shake 0.45s ease-in-out 2; }
.h-avatar.emo-mad .swirl { animation: h-spin 1.6s linear infinite; transform-origin: center; transform-box: fill-box; }
.h-avatar.emo-scared { animation: h-tremble 0.18s linear 6; }
.h-avatar.emo-happy { animation: h-bounce 0.6s ease-out 1; }
.h-avatar.emo-sad .tear { animation: h-drip 1.6s ease-in infinite; }
/* Emotion mark that pops up next to the head */
.h-pop { position: absolute; top: 0; right: 4%; font-size: clamp(1.5rem, 5cqw, 3.2rem); line-height: 1; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5)); animation: h-pop 1.6s cubic-bezier(0.3, 0.7, 0.4, 1.6) forwards; }

@keyframes h-enter { from { opacity: 0; transform: translateY(40px) scale(0.92); } }
@keyframes h-hop { 40% { transform: translateY(-5%); } 70% { transform: translateY(1%); } }
@keyframes h-pop { 0% { opacity: 0; transform: scale(0) rotate(-30deg); } 18% { opacity: 1; transform: scale(1.25) rotate(8deg); } 30% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
@keyframes h-float { 50% { transform: translateY(-3%); } }
@keyframes h-pulse { 50% { opacity: 0.45; transform: scale(1.04); } }
@keyframes h-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes h-tremble { 50% { transform: translate(1px, -1px); } }
@keyframes h-bounce { 40% { transform: translateY(-6px); } }
@keyframes h-spin { to { transform: rotate(360deg); } }
@keyframes h-drip { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(14px); opacity: 0; } }

/* ---------- Screen effects (playFx in hamlet.js) ---------- */
.h-play::after { content: ""; position: absolute; inset: 0; z-index: 5; pointer-events: none; opacity: 0; }
.h-play.fx-fade::after  { background: #000; animation: h-fx-out 0.9s ease-out 1; }
.h-play.fx-flash::after { background: #fff; animation: h-fx-out 0.5s ease-out 1; }
.h-play.fx-doom::after  { background: radial-gradient(ellipse at center, transparent 30%, rgba(170, 0, 20, 0.75)); animation: h-fx-pulse 1.1s ease-out 1; }
.h-play.fx-glow::after  { background: radial-gradient(ellipse at center, rgba(255, 220, 130, 0.35), transparent 70%); animation: h-fx-pulse 1s ease-out 1; }
.h-play.fx-shake { animation: h-fx-shake 0.42s linear 1; }
.h-play.fx-jolt .h-scenery, .h-play.fx-jolt .h-cast { animation: h-fx-jolt 0.32s ease-out 1; }
@keyframes h-fx-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes h-fx-pulse { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }
@keyframes h-fx-shake { 10%, 50%, 90% { transform: translate(-6px, 2px); } 30%, 70% { transform: translate(6px, -2px); } }
@keyframes h-fx-jolt { 30% { transform: scale(1.05); } }

/* ---------- Small buttons on the stage ---------- */
.h-hud { position: absolute; top: 10px; right: 10px; z-index: 6; display: flex; gap: 6px; opacity: 0.6; transition: opacity 0.2s; }
.h-play:hover .h-hud { opacity: 1; }
.h-hud button { width: 36px; height: 36px; padding: 0; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 50%; background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 1rem; cursor: pointer; filter: grayscale(1); transition: transform 0.15s, filter 0.15s; }
.h-hud button:hover { transform: scale(1.12); }
.h-hud button.is-on, .h-hud button[data-fullscreen] { filter: none; }

/* ---------- Text box / menu / panel ---------- */
.h-dialogue { position: absolute; z-index: 4; left: 3%; right: 3%; bottom: 14px; color: var(--text); }
/* 1. Text box while someone speaks: click anywhere to go on */
.h-play[data-mode="line"] { cursor: pointer; }
.h-play[data-mode="line"] .h-dialogue {
  min-height: 116px; padding: 24px 20px 38px;
  border: 2px solid var(--primary); border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.h-play[data-mode="line"] .h-speaker { position: absolute; top: -17px; left: 16px; margin: 0; align-items: center; }
.h-play[data-mode="line"] .h-name { padding: 4px 16px; border-radius: 10px; background: var(--primary); color: var(--on-primary); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3); }
.h-play[data-mode="line"] .h-role { padding: 2px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.h-play[data-mode="line"] .h-actions { position: absolute; right: 12px; bottom: 6px; margin: 0; }
.h-more { color: var(--primary-text); animation: h-more 0.9s ease-in-out infinite; }
@keyframes h-more { 50% { transform: translateY(4px); opacity: 0.4; } }
/* 2. Choice menu: buttons pop in one after another */
.h-play[data-mode="choice"] .h-dialogue { left: 50%; right: auto; width: min(620px, 92%); transform: translateX(-50%); }
.h-play[data-mode="choice"] .h-prompt { display: table; margin: 0 auto 10px; padding: 6px 18px; border-radius: 999px; background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
.h-play[data-mode="choice"] .h-choice { animation: h-choice-in 0.4s cubic-bezier(0.3, 0.7, 0.4, 1.5) backwards; }
.h-play[data-mode="choice"] .h-choice:nth-child(2) { animation-delay: 0.1s; }
.h-play[data-mode="choice"] .h-choice:nth-child(3) { animation-delay: 0.2s; }
@keyframes h-choice-in { from { opacity: 0; transform: translateY(18px) scale(0.92); } }
/* 3. Panel: start screen, scene titles, notes, endings */
.h-play[data-mode="card"] .h-dialogue {
  left: 50%; right: auto; width: min(640px, 94%); max-height: 66%; overflow-y: auto; transform: translateX(-50%);
  padding: 18px 22px; border-radius: 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(8px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45); animation: h-card-in 0.4s cubic-bezier(0.3, 0.7, 0.4, 1.3) 1;
}
@keyframes h-card-in { from { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.96); } }

.h-speaker { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.h-name { font: 700 1.05rem var(--font-ui); color: var(--primary-text); }
.h-role { color: var(--muted); font-size: 0.8rem; }
.h-line { margin: 0 0 4px; font-family: var(--font); font-size: clamp(1.05rem, 2.4cqw, 1.5rem); font-weight: 600; line-height: 1.45; min-height: 2.6em; }
html[lang="en"] .h-line:not(.is-narration) { font-family: "Cormorant", Georgia, serif; font-size: clamp(1.3rem, 3cqw, 1.9rem); }
.h-line.is-narration { font-size: clamp(0.98rem, 2cqw, 1.25rem); font-weight: 400; font-style: italic; }
.h-sub { margin: 0; color: var(--muted); font-family: "Cormorant", Georgia, serif; font-style: italic; font-size: 1.05rem; }
.h-sub small { font-family: var(--font-ui); font-style: normal; font-size: max(12px, 0.72rem); }
.h-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.h-title { margin: 4px 0 8px; font-family: "Cormorant", Georgia, serif; font-size: 2rem; }
.h-act { margin: 0; color: var(--accent-strong); font: 700 0.78rem var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; }
.h-prompt { font-weight: 700; }
.h-choices { display: flex; flex-direction: column; gap: 8px; }
.h-choice {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px; border: 2px solid var(--border); border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent); color: var(--text); font: 600 0.98rem var(--font-ui); text-align: left; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.h-choice:hover { transform: scale(1.03); border-color: var(--primary); background: var(--surface); }
.h-choice b { display: grid; place-items: center; flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-size: 0.8rem; }
.h-verdict { display: inline-block; margin: 0 0 6px; padding: 3px 12px; border-radius: 999px; font: 700 0.85rem var(--font-ui); }
.h-verdict.is-canon { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.h-verdict.is-alt { background: var(--accent-tint); color: var(--accent-strong); }
.h-end-stats { margin: 12px 0; }

@media (max-width: 700px) {
  .h-play { aspect-ratio: auto; height: 78vh; min-height: 520px; }
  .h-actor { width: min(44cqw, 50cqh); margin: 0 -5%; }
  .h-cast { bottom: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  .h-play, .h-play *, .h-play::after { animation: none !important; }
}

/* ---------- Side panel ---------- */
.h-side { display: flex; flex-direction: column; gap: 14px; }
.h-stat { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-bottom: 10px; font-size: 0.9rem; }
.h-bar { grid-column: 1 / -1; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.h-bar i { display: block; height: 100%; background: var(--gradient, var(--primary)); background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width 0.5s; }
.h-chapters { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.h-chapter { width: 100%; padding: 7px 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); font: 600 0.86rem var(--font-ui); text-align: left; cursor: pointer; }
.h-chapter small { display: inline-block; min-width: 46px; color: var(--muted); }
.h-chapter:hover:not(:disabled) { background: var(--surface-2); }
.h-chapter.is-active { background: var(--primary-tint); color: var(--primary-text); }
.h-chapter:disabled { opacity: 0.45; cursor: default; }
.h-credit { margin-top: 18px; }

/* ---------- Wardrobe ---------- */
.h-wardrobe { max-width: 760px; }
.h-skin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.h-skin { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px; text-align: center; }
.h-skin.is-equipped { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-tint); }
.h-skin h4 { margin: 0; font-size: 0.9rem; }
.h-skin-art { width: 110px; border-radius: 50%; background: radial-gradient(circle, var(--surface-2), transparent 70%); }

/* ---------- Study book ---------- */
.book-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.book-toc { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 2px; }
.book-toc a { padding: 7px 12px; border-radius: var(--radius-sm); color: var(--text) !important; font: 600 0.9rem var(--font-ui); }
.book-toc a:hover { background: var(--surface); text-decoration: none; }
.book-section { margin-bottom: 28px; scroll-margin-top: 84px; }
.book-section > h2 { font-family: "Cormorant", Georgia, serif; font-size: 2rem; margin-bottom: 10px; }
.book-section p { line-height: 1.7; }
.book-chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.book-char { display: grid; grid-template-columns: 70px 1fr; gap: 10px; align-items: center; }
.book-char h4 { margin: 0 0 2px; }
.book-char p { margin: 0; font-size: 0.88rem; color: var(--muted); line-height: 1.45; }
.book-quote { margin: 0 0 12px; padding: 12px 16px; border-left: 4px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface); }
.book-quote q { display: block; font-family: "Cormorant", Georgia, serif; font-size: 1.3rem; font-weight: 600; }
.book-quote small { color: var(--muted); }
.book-act { border-left: 4px solid var(--primary); }
.book-act h3 { margin-top: 0; }
.book-theme h3 { margin: 0 0 6px; }
.book-q li { margin-bottom: 8px; }

@media (max-width: 900px) {
  .h-layout, .book-layout { grid-template-columns: minmax(0, 1fr); }
  .book-toc { position: static; flex-direction: row; flex-wrap: wrap; }
}
