/* ==========================================================================
   EDU BUBU — EPISODE ENGINE (Lokalny arkusz bazowego silnika odcinków)
   Korzysta ze zmiennych i klas ogólnych z globals.css (bez ich powielania).
   Układ: czarny pasek moderatora po LEWEJ + lewitujący jasny ekran 66% / 34%.
   ========================================================================== */

.ep-shell {
  --ep-tile-height: clamp(64px, 8.8vh, 80px);
  position: relative;
  display: grid;
  grid-template-columns: clamp(72px, 6vw, 88px) 1fr;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background-color: var(--bubu-obsidian-dark);
}

/* --------------------------------------------------------------------------
   1. BOCZNY PASEK MODERATORA (lewa krawędź, ciemny, stonowany, rozwijany)
   -------------------------------------------------------------------------- */
.ep-modbar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: clamp(72px, 6vw, 88px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.75rem 0.5rem 1rem;
  background-color: var(--bubu-obsidian-dark);
  color: rgba(255, 255, 255, 0.72);
  z-index: 30;
  transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1), padding 0.28s ease, box-shadow 0.28s ease;
}

.ep-modbar::-webkit-scrollbar {
  display: none;
}

.ep-shell.is-menu-open .ep-modbar {
  width: clamp(280px, 34vw, 400px);
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: 16px 0 48px rgba(0, 0, 0, 0.55);
  overflow-y: auto;
  scrollbar-width: none;
  z-index: 40;
}

.ep-mod-top,
.ep-mod-middle,
.ep-mod-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
}

.ep-shell.is-menu-open .ep-mod-top,
.ep-shell.is-menu-open .ep-mod-middle,
.ep-shell.is-menu-open .ep-mod-bottom {
  align-items: stretch;
}

/* Przyciski w pasku moderatora — niskokontrastowe, wtapiające się w czerń */
.ep-mod-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 48px;
  padding: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background-color: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.72);
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  overflow: hidden;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.ep-mod-item:disabled {
  opacity: 0.32;
  cursor: not-allowed;
  pointer-events: none;
}

.ep-shell.is-menu-open .ep-mod-item {
  justify-content: flex-start;
  padding: 0.6rem 0.9rem;
}

.ep-mod-item:active {
  background-color: rgba(255, 255, 255, 0.14);
}

.ep-mod-item.is-active {
  background-color: rgba(232, 168, 37, 0.18);
  border-color: rgba(232, 168, 37, 0.45);
  color: var(--accent-gold-glow);
}

.ep-mod-icon {
  font-size: 1.2rem;
  line-height: 1;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.ep-mod-label {
  display: none;
  opacity: 0;
  white-space: nowrap;
  transition: opacity 0.2s ease 0.08s;
}

.ep-shell.is-menu-open .ep-mod-label {
  display: inline;
  opacity: 1;
}

/* Tytuł i opis odcinka w rozwiniętym MENU */
.ep-menu-info {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background-color: rgba(255, 255, 255, 0.04);
  transition: max-height 0.26s ease, opacity 0.22s ease, padding 0.26s ease, border-color 0.26s ease;
}

.ep-shell.is-menu-open .ep-menu-info {
  max-height: 180px;
  opacity: 1;
  padding: 0.7rem 0.9rem;
  border-color: rgba(255, 255, 255, 0.08);
}

.ep-menu-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  color: #FFFFFF;
  margin-bottom: 0.25rem;
}

.ep-menu-desc {
  font-size: 0.85rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.72);
}

/* Kropki postępu 1..5 ze statusami */
.ep-mod-dots {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.42rem;
  width: 100%;
}

.ep-shell.is-menu-open .ep-mod-dots {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.25rem 0;
}

.ep-mod-dot {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  border: 2px solid rgba(255, 255, 255, 0.18);
  background-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.65);
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.ep-mod-dot.is-done {
  background-color: var(--accent-sage);
  border-color: var(--accent-sage-light);
  color: #FFFFFF;
}

.ep-mod-dot.is-current {
  background-color: var(--accent-gold);
  border-color: var(--accent-gold-glow);
  color: var(--ink-dark);
  transform: scale(1.1);
}

/* Strzałki poprzedni / następny pod kropkami */
.ep-mod-arrows {
  display: flex;
  gap: 0.3rem;
  width: 100%;
}

.ep-mod-arrows .ep-mod-item {
  flex: 1 1 0;
  min-height: 48px;
  padding: 0.25rem;
}

/* Suwak głośności widoczny po rozwinięciu MENU */
.ep-volume-box {
  display: none;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-color: rgba(255, 255, 255, 0.04);
}

.ep-shell.is-menu-open .ep-volume-box {
  display: flex;
}

.ep-volume-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 600;
}

.ep-volume-slider {
  width: 100%;
  accent-color: var(--accent-gold);
  cursor: pointer;
}

/* Przycisk „Zamknij / Wróć do menu” widoczny tylko po rozwinięciu MENU */
.ep-mod-exit {
  display: none;
}

.ep-shell.is-menu-open .ep-mod-exit {
  display: inline-flex;
}

/* Duży okrągły przycisk „Zobacz jeszcze raz” wychodzący w 1/3 poza pasek moderacji */
.ep-replay-orb-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  height: var(--ep-tile-height);
  margin-top: 0.15rem;
}

.ep-replay-orb {
  position: relative;
  right: calc(var(--ep-tile-height) * -0.33);
  flex-shrink: 0;
  width: var(--ep-tile-height);
  min-width: var(--ep-tile-height);
  height: var(--ep-tile-height);
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: var(--radius-pill);
  border: var(--border-ink);
  background-color: var(--bg-card);
  color: var(--ink-dark);
  box-shadow: var(--shadow-btn);
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  z-index: 30;
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.ep-replay-orb-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  line-height: 1;
  transform: translateY(-1px);
}

.ep-replay-orb:active {
  transform: translateY(3px);
  box-shadow: var(--shadow-btn-active);
  background-color: var(--accent-gold-glow);
}

.ep-shell.is-menu-open .ep-replay-orb {
  right: 0;
  width: 100%;
  min-width: 0;
  height: 48px;
  aspect-ratio: auto;
  border-radius: var(--radius-sm);
  justify-content: flex-start;
  padding: 0 0.9rem;
  gap: 0.75rem;
  font-size: 0.95rem;
}

.ep-replay-orb-label {
  display: none;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
}

.ep-shell.is-menu-open .ep-replay-orb-label {
  display: inline;
}

/* --------------------------------------------------------------------------
   2. LEWITUJĄCY JASNY EKRAN GRY (66% scena / 34% odpowiedzi)
   -------------------------------------------------------------------------- */
.ep-main {
  grid-column: 2;
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 0.6rem 0.6rem 0.6rem 0;
  border-radius: var(--radius-lg);
  border: var(--border-ink);
  background-color: var(--bg-cream);
  box-shadow: -10px 0 28px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  z-index: 10;
}

/* Strefa sceny (zawsze pełna wysokość ekranu gry) */
.ep-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
  padding: 0;
  background: linear-gradient(180deg, #9AD3EE 0%, #E6F4EC 62%, var(--bg-cream) 100%);
  overflow: hidden;
}

.ep-scene-host {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 0;
}

/* Placeholder scenki Ziemian (do podmiany na docelowe sceny) */
.ep-placeholder-scene {
  width: min(680px, 100%);
  height: min(350px, 92%);
  margin: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  text-align: center;
  background-color: var(--bg-card);
  border: 3px dashed var(--ink-Soft);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.75rem;
}

.ep-placeholder-tag {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ep-placeholder-title {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.2vw, 1.75rem);
  font-weight: 800;
  color: var(--ink-dark);
}

.ep-placeholder-meta {
  font-size: 0.95rem;
  color: var(--ink-muted);
  max-width: 46ch;
}

/* Bubu-obserwator jako stały element sceny */
.ep-bubu-dock {
  position: absolute;
  left: clamp(0.6rem, 1.5vw, 1.35rem);
  bottom: clamp(130px, 20vh, 176px);
  width: clamp(140px, 17vw, 210px);
  height: clamp(168px, 23vh, 245px);
  pointer-events: none;
  z-index: 3;
  transform: translateX(0);
  opacity: 1;
  transition: transform 1.2s linear, opacity 0.25s ease;
}

.ep-bubu-dock.is-offscreen-left {
  transform: translateX(-150%);
  opacity: 0;
}

.ep-bubu-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.ep-bubu-bubble {
  position: absolute;
  left: clamp(135px, 16.5vw, 210px);
  bottom: clamp(238px, 35vh, 330px);
  max-width: min(340px, 44vw);
  background-color: var(--bg-card);
  border: var(--border-ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-btn);
  padding: 0.7rem 1rem;
  font-family: var(--font-body);
  font-size: clamp(0.95rem, 1.35vw, 1.12rem);
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink-dark);
  text-align: left;
  cursor: pointer;
  z-index: 4;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.ep-bubu-bubble::before {
  content: "";
  position: absolute;
  left: -12px;
  bottom: 14px;
  width: 14px;
  height: 14px;
  background-color: var(--bg-card);
  border-left: var(--border-ink);
  border-bottom: var(--border-ink);
  transform: rotate(45deg);
}

.ep-bubu-bubble.is-hidden {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}

/* Strefa odpowiedzi (nakładka wjeżdżająca od dołu bez przesuwania sceny) */
.ep-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.7rem clamp(1.25rem, 2.5vw, 2.5rem) 0.8rem;
  padding-left: clamp(2.75rem, 4.5vw, 4rem);
  background-color: var(--bg-parchment);
  border-top: var(--border-ink);
  min-height: 0;
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}

.ep-main[data-phase="WAITING_START"] .ep-controls,
.ep-main[data-phase="INTRO"] .ep-controls {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}

.ep-question {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 1.9vw, 1.45rem);
  font-weight: 800;
  text-align: center;
  color: var(--ink-dark);
  line-height: 1.2;
}

.ep-main[data-phase="READY_NEXT"] .ep-question {
  color: var(--accent-sage-dark);
}

.ep-options-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: clamp(0.75rem, 1.6vw, 1.35rem);
  width: min(980px, 100%);
}

.ep-option-tile {
  flex: 1 1 0;
  min-width: 140px;
  min-height: var(--ep-tile-height);
  height: var(--ep-tile-height);
  padding: 0.5rem 1rem;
  flex-direction: row;
  justify-content: center;
  text-align: left;
  font-size: clamp(0.98rem, 1.4vw, 1.18rem);
  line-height: 1.2;
}

.ep-option-icon {
  font-size: clamp(1.6rem, 2.4vw, 2.1rem);
  line-height: 1;
  flex-shrink: 0;
}

.ep-option-tile.is-tried {
  opacity: 0.36;
  box-shadow: none;
  transform: translateY(2px);
  pointer-events: none;
}

.ep-next-btn {
  flex: 0 1 clamp(240px, 36vw, 420px);
  min-height: var(--ep-tile-height);
  height: var(--ep-tile-height);
  padding: 0.5rem 1.75rem;
  font-size: clamp(1.15rem, 1.8vw, 1.45rem);
  letter-spacing: 0.02em;
}

.ep-summary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  width: min(760px, 100%);
}

.ep-summary-actions .btn-touch {
  flex: 1 1 220px;
  min-height: 72px;
  font-size: 1.15rem;
}

/* --------------------------------------------------------------------------
   3. NAKŁADKI NA ŚRODKU EKRANU GRY (START / DALEJ oraz PAUZA)
   -------------------------------------------------------------------------- */
.ep-center-gate {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  background-color: rgba(250, 246, 238, 0.42);
  backdrop-filter: blur(2px);
  z-index: 12;
}

.ep-center-gate.is-hidden {
  display: none;
}

.ep-gate-title {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.3vw, 1.9rem);
  font-weight: 800;
  color: var(--ink-dark);
  text-align: center;
  max-width: min(680px, 88%);
  padding: 0.45rem 1.25rem;
  border-radius: 999px;
  background-color: rgba(255, 253, 246, 0.92);
  border: var(--border-ink);
  box-shadow: var(--shadow-btn);
}

.ep-gate-btn {
  min-width: clamp(220px, 28vw, 320px);
  min-height: clamp(80px, 12vh, 104px);
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  letter-spacing: 0.02em;
}

.ep-pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background-color: rgba(20, 24, 29, 0.56);
  backdrop-filter: blur(6px);
  cursor: pointer;
  z-index: 15;
}

.ep-pause-overlay.is-hidden {
  display: none;
}

.ep-pause-title {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.6vw, 2.1rem);
  font-weight: 800;
  color: #ffffff;
  text-align: center;
  max-width: min(680px, 88%);
  padding: 0 1rem;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.45);
}

.ep-pause-btn {
  min-width: clamp(220px, 28vw, 320px);
  min-height: clamp(82px, 12vh, 108px);
  font-size: clamp(1.5rem, 2.5vw, 2.1rem);
  letter-spacing: 0.04em;
}

.ep-pause-hint {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

/* --------------------------------------------------------------------------
   NAKŁADKA ORIENTACJI POZIOMEJ (telefony / tablety w pionie)
   -------------------------------------------------------------------------- */
.ep-rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background-color: rgba(23, 26, 31, 0.94);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.ep-rotate-card {
  max-width: 360px;
  width: 100%;
  background-color: var(--bg-card);
  border: var(--border-ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-btn);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
}

.ep-rotate-icon {
  font-size: 2.6rem;
  line-height: 1;
}

.ep-rotate-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink-dark);
}

.ep-rotate-desc {
  font-size: 0.98rem;
  color: var(--ink-muted);
  line-height: 1.35;
}

.ep-rotate-dismiss {
  margin-top: 0.25rem;
  min-height: 48px;
  padding: 0.55rem 1.15rem;
  font-size: 0.95rem;
  background-color: var(--bg-parchment);
  color: var(--ink-dark);
}

@media (orientation: portrait) and (max-width: 900px) {
  .ep-shell:not(.is-portrait-dismissed) .ep-rotate-overlay {
    display: flex;
  }
}

/* --------------------------------------------------------------------------
   RESPONSYWNOŚĆ
   -------------------------------------------------------------------------- */
@media (max-width: 768px) and (orientation: portrait) {
  .ep-shell {
    grid-template-columns: 72px 1fr;
  }

  .ep-main {
    margin: 0.35rem 0.35rem 0.35rem 0;
  }

  .ep-scene-host {
    padding-left: 0;
  }

  .ep-bubu-dock {
    bottom: 185px;
    width: 115px;
    height: 140px;
  }

  .ep-bubu-bubble {
    left: 114px;
    bottom: 265px;
    max-width: 55vw;
    font-size: 0.9rem;
  }

  .ep-controls {
    padding-left: 2.35rem;
  }

  .ep-options-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .ep-option-tile {
    min-height: 64px;
    justify-content: flex-start;
  }
}

/* Telefony i małe ekrany w układzie poziomym — proporcjonalne skalowanie całego viewportu */
@media (max-height: 580px) and (orientation: landscape) {
  .ep-shell {
    zoom: 0.72;
    width: calc(100vw / 0.72);
    height: calc(100dvh / 0.72);
  }
}

@media (max-height: 440px) and (orientation: landscape) {
  .ep-shell {
    zoom: 0.56;
    width: calc(100vw / 0.56);
    height: calc(100dvh / 0.56);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ep-modbar,
  .ep-bubu-bubble,
  .ep-mod-dot,
  .ep-replay-orb,
  .btn-touch {
    transition: none;
  }
}

/* Tooltip po przytrzymaniu palca (long-press) */
.ep-tooltip {
  position: fixed;
  z-index: 100;
  max-width: min(260px, 80vw);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.2);
  background-color: var(--ink-dark);
  color: #FFFFFF;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.ep-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}
