:root {
  --page-padding: clamp(12px, 3vw, 36px);
  color-scheme: light;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #cfd2d4;
  color: #1d2a32;
  scrollbar-gutter: stable both-edges;
}

* { box-sizing: border-box; }

/* Karta dopasowuje się do szerokości i treści. Długie pytania przewijamy
   razem ze stroną playera, bez drugiego paska wewnątrz slajdu. */
.stage img[hidden], .question-screen[hidden], .question-check[hidden] { display: none; }
.stage.is-question { display: grid; height: auto; max-height: none; background: #edf3f8; }
.question-screen {
  display: grid;
  width: 100%;
  min-height: clamp(300px, calc(100cqw / var(--question-aspect-ratio, 1.7777778)), 640px);
  padding: clamp(10px, 2cqw, 28px);
  background-position: center top;
  background-repeat: no-repeat;
  background-size: contain;
  overflow-wrap: anywhere;
}
.question-card {
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 0;
  margin: 0;
  padding: clamp(12px, 2cqw, 26px);
  border: 1px solid #d5e2eb;
  border-radius: 14px;
  background: rgb(255 255 255 / 96%);
  box-shadow: 0 6px 24px rgb(22 54 79 / 10%);
  color: #213747;
  line-height: 1.45;
  font-size: clamp(1rem, 1.7cqw, 1.375rem);
}
.question-body { min-width: 0; overflow: visible; }
.question-card fieldset { padding: 0; margin: 0; border: 0; min-width: 0; }
.question-prompt { font-weight: 650; font-size: 1.3em; line-height: 1.3; white-space: pre-wrap; }
.question-eyebrow { color: #326581; font-size: .8em; text-transform: uppercase; letter-spacing: .06em; margin: 0 0 .8em; }
.question-instruction { color: #506578; font-size: .9em; margin: .75em 0; }
.question-option {
  display: flex; align-items: flex-start; gap: clamp(8px, 1cqw, 12px);
  min-height: 44px; padding: clamp(8px, 1cqw, 12px);
  margin: 8px 0; border: 1px solid #cad9e5; border-radius: 9px;
  background: #f8fbfd; cursor: pointer; white-space: pre-wrap;
}
.question-option > span { min-width: 0; }
.question-option:has(input:checked) { background: #e3effc; border-color: #508cce; }
.question-option:focus-within { outline: 3px solid #245ccb; outline-offset: 2px; }
.question-option input { flex: 0 0 auto; width: 20px; height: 20px; margin: 2px 0 0; accent-color: #245ccb; }
.question-message { color: #8b3a16; }
.question-message:empty, .question-audio-message:empty { display: none; }
.question-feedback-title { font-size: 1.3em; line-height: 1.3; margin: 0 0 .75em; }
.question-context { font-size: .9em; color: #506578; white-space: pre-wrap; }
.question-summary { white-space: pre-wrap; border-left: 4px solid #508cce; border-radius: 8px; padding: clamp(12px, 2cqw, 20px); background: #e8f1fc; }
.question-explanation { padding: clamp(10px, 1.5cqw, 16px); margin: 12px 0; border-radius: 8px; border-left: 4px solid; }
.question-explanation p { margin: 7px 0 0; white-space: pre-wrap; }
.question-explanation .question-answer-status { margin: 0 0 10px; font-size: .8em; }
.question-explanation strong { white-space: pre-wrap; }
.question-explanation.is-correct { background: #e8f5ee; border-color: #469477; }
.question-explanation.is-incorrect { background: #fff3df; border-color: #c08b40; }
.question-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #d5e2eb; }
.question-continue { margin-left: auto; }
.question-card button { min-height: 44px; height: auto; max-width: 100%; white-space: normal; font-size: .95em; }
.question-retry, .question-back { background: #edf2f7; color: #29405b; }
@container (max-width: 600px) {
  .question-screen { min-height: 0; padding: 8px; }
  .question-card { padding: 12px; border-radius: 10px; }
  .question-card button { padding: 8px 10px; }
  .question-check { width: 100%; }
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: var(--page-padding);
}

#player {
  --sidebar-external-width: clamp(154px, 15.4vw, 196px);
  --player-main-limit: min(
    1400px,
    calc(100vw - var(--page-padding) - var(--page-padding) - var(--sidebar-external-width))
  );
  --player-main-width: var(--fitted-player-main-width, var(--player-main-limit));
  display: flex;
  width: 100%;
  min-width: 0;
  justify-content: center;
}

.shell {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.player-composite {
  position: relative;
  width: var(--player-main-width);
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
  transition: width 180ms ease;
}

.shell.sidebar-open .player-composite {
  width: calc(var(--player-main-width) + var(--sidebar-external-width));
}

.player-content {
  width: var(--player-main-width);
  min-width: 0;
  padding: clamp(12px, 1.6vw, 24px);
  background: #fff;
}

.viewer-layout {
  position: relative;
  width: 100%;
}

.viewer-main { min-width: 0; container-type: inline-size; }

.shell:fullscreen {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  align-items: safe center;
  overflow-y: auto;
  padding: 24px 32px;
  border-radius: 0;
  background: #cfd2d4;
  box-shadow: none;
}

.shell:fullscreen .player-composite {
  width: min(100%, var(--fullscreen-player-width, 100%));
  box-shadow: none;
}

.shell:fullscreen.sidebar-open .player-composite {
  width: calc(var(--fullscreen-player-width, 100%) + var(--sidebar-external-width));
}

.shell:fullscreen .player-content {
  width: min(100%, var(--fullscreen-player-width, 100%));
}

.shell:fullscreen .stage {
  min-height: 0;
  background: transparent;
}

.shell:fullscreen .stage img {
  width: 100%;
  max-height: none;
}

.player-header {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 2px 14px;
}

.player-header > * { min-width: 0; }

.header-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-left: auto;
}

.presentation-name {
  max-width: min(520px, 44vw);
  overflow: hidden;
  color: #344c5d;
  font-size: 1.02rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-toggle { flex: 0 0 auto; }
.sidebar-toggle.is-active { background: #174f9c; }

.sidebar-icon {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand-logo {
  display: block;
  width: auto;
  max-width: min(300px, 42vw);
  height: 48px;
  object-fit: contain;
  object-position: left center;
}

.brand-logo[hidden] { display: none; }

.stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  background: #111b23;
}

.stage img {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
  backface-visibility: hidden;
}

.stage img.slide-transition {
  animation-duration: var(--slide-transition-duration, 420ms);
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(.22, 1, .36, 1);
}

.stage img.slide-transition-fade { animation-name: slide-fade-in; }

.stage img.slide-transition-slide {
  --slide-enter-offset: 6%;
  animation-name: slide-move-in;
}

.stage img.slide-transition-slide.is-backward { --slide-enter-offset: -6%; }
.stage img.slide-transition-zoom { animation-name: slide-zoom-in; }

.stage img.slide-transition-wipe {
  --slide-wipe-start: inset(0 100% 0 0);
  animation-name: slide-wipe-in;
  animation-duration: var(--slide-transition-duration, 500ms);
}

.stage img.slide-transition-wipe.is-backward {
  --slide-wipe-start: inset(0 0 0 100%);
}

@keyframes slide-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-move-in {
  from { opacity: .25; transform: translateX(var(--slide-enter-offset)); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slide-zoom-in {
  from { opacity: 0; transform: scale(.965); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slide-wipe-in {
  from { clip-path: var(--slide-wipe-start); }
  to { clip-path: inset(0 0 0 0); }
}

.slide-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  width: var(--sidebar-external-width);
  min-width: 0;
  max-height: none;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid #d8e0e7;
  border-radius: 0 12px 12px 0;
  background: #f5f8fa;
  box-shadow: -3px 0 10px rgb(0 0 0 / 7%);
}

.slide-sidebar[hidden] { display: none; }

.slide-sidebar-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 6px 4px 10px;
  color: #315b7c;
  background: #eef3f6;
  font-size: .76rem;
  font-weight: 700;
}

.sidebar-close {
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  color: #315b7c;
  background: transparent;
}

.sidebar-close:hover { background: #dfeaf2; }
.sidebar-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.slide-sidebar-tabs {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 5px;
  border-bottom: 1px solid #d8e0e7;
  background: #eef3f6;
}

.sidebar-view-button {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 5px;
  border-radius: 5px;
  color: #315b7c;
  background: transparent;
  font-size: .76rem;
  font-weight: 700;
}

.sidebar-view-button:hover { color: #174f9c; background: #dfeaf2; }
.sidebar-view-button.is-active { color: #fff; background: #4b88df; }
.sidebar-view-button.is-active:hover { background: #3174d3; }

.sidebar-search-icon {
  display: block;
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.slide-sidebar-view {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
}

.slide-sidebar-view[hidden] { display: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.slide-search-form {
  display: grid;
  flex: 0 0 auto;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid #d8e0e7;
  background: #f5f8fa;
}

.slide-search-input {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #afbdc8;
  border-radius: 5px;
  color: #1d2a32;
  background: #fff;
  font: inherit;
  font-size: .76rem;
}

.slide-search-submit {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  font-size: .76rem;
}

.slide-search-status {
  flex: 0 0 auto;
  padding: 7px 8px 2px;
  color: #526b7c;
  font-size: .72rem;
  line-height: 1.3;
}

.slide-thumbnail-list,
.slide-search-results {
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
}

.slide-thumbnail {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 6px;
  border: 2px solid transparent;
  color: #233746;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
  text-align: left;
}

.slide-thumbnail:hover {
  border-color: #8bb8e8;
  color: #164e71;
  background: #f7fbff;
}

.slide-thumbnail.is-current {
  border-color: #4b88df;
  color: #123d61;
  background: #dceffc;
}

.slide-thumbnail-title {
  display: -webkit-box;
  margin-bottom: 5px;
  overflow: hidden;
  font-size: .78rem;
  font-weight: 650;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.slide-thumbnail img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--slide-aspect-ratio, 16 / 9);
  object-fit: contain;
  border: 1px solid #cdd7df;
  background: #111b23;
}

/* Własne tło zostaje pod grafiką; symbol rozpoznajemy także bez tła. */
.question-thumbnail {
  position: relative;
  display: flex;
  width: 100%;
  aspect-ratio: var(--slide-aspect-ratio, 16 / 9);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  border: 1px solid #bdcedd;
  border-radius: 5px;
  background: linear-gradient(140deg, #e8f5fc, #dce9fa);
}
.question-thumbnail img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .3; border: 0; }
.question-thumbnail svg { position: relative; width: 46%; max-height: 60%; color: #245b86; }
.question-thumbnail-label {
  position: relative; max-width: 96%; padding: 3px 6px; border-radius: 4px;
  color: #174b70; background: rgb(255 255 255 / 92%); font-size: 10px; font-weight: 700;
  line-height: 1.2; text-align: center;
}

.slide-thumbnail-number {
  display: block;
  margin-top: 4px;
  color: #607281;
  font-size: .7rem;
  font-weight: 600;
}

.caption-panel {
  max-height: 180px;
  margin-top: 12px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  border: 1px solid #d8e0e7;
  border-radius: 6px;
  background: #f8fafc;
}

.caption-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 12px;
  border-bottom: 1px solid #d8e0e7;
  color: #315b7c;
  background: #f8fafc;
  font-size: .9em;
  font-weight: 700;
}

.caption-list {
  padding: 12px 14px 14px;
  color: #1d2a32;
  font-size: 1.03rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.caption-empty {
  margin: 0;
  padding: 10px 12px;
  color: #57636e;
  font-style: italic;
}

.caption-text { margin: 0; white-space: normal; }

.caption-cue {
  display: inline;
  padding: 1px 2px;
  border: 0;
  color: inherit;
  background: transparent;
  border-radius: 3px;
  font: inherit;
  font-weight: inherit;
  line-height: inherit;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}

.caption-cue:hover { background: #edf4fb; color: #164e71; }
.caption-cue.is-current { background: #dceffc; color: #164e71; }
.caption-cue:focus-visible { outline: 3px solid #174f9c; outline-offset: 2px; }

.controls {
  --control-size: 44px;
  display: grid;
  grid-template-columns: var(--control-size) minmax(0, 1fr) auto;
  grid-template-areas: "play playback playback" "tools tools navigation";
  gap: 6px;
  align-items: center;
  margin-top: 10px;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  color: white;
  background: #4b88df;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: #3174d3; }
button:focus-visible, input:focus-visible { outline: 3px solid #174f9c; outline-offset: 2px; }
button[disabled] { cursor: not-allowed; opacity: .55; }

.square-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.controls .square-button { width: var(--control-size); height: var(--control-size); }
.play { grid-area: play; font-size: 18px; }

.playback-panel {
  grid-area: playback;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 6px;
  align-items: center;
  min-width: 0;
  font-size: .82rem;
}

.progress { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; height: 24px; margin: 0; accent-color: #4b88df; }
.time { grid-column: 2; grid-row: 1; }
.time, .counter { font-variant-numeric: tabular-nums; white-space: nowrap; }
.utility-controls { grid-area: tools; display: flex; gap: 4px; }
.utility-button { color: white; }
.utility-button.is-active { background: #174f9c; }
.utility-button.is-active:hover { background: #123d78; }
.utility-button.placeholder { font-size: 17px; }
.navigation-spacer { grid-area: spacer; display: none; min-width: 148px; }
.navigation { grid-area: navigation; display: flex; gap: 4px; justify-content: flex-end; }
.navigation button {
  display: inline-flex;
  width: var(--control-size);
  min-width: 0;
  height: var(--control-size);
  padding: 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}
.nav-label { display: none; }
.nav-arrow { font-size: 26px; line-height: 1; }

/* Progi odnoszą się do treści playera, także w ramce Moodle.
   Tylko wąski układ telefonu potrzebuje dwóch wierszy przycisków.
   560 px jest też minimalną szerokością dopasowania slajdu w player.js. */
@container (min-width: 560px) {
  .controls {
    grid-template-columns: var(--control-size) minmax(0, 1fr) auto auto;
    grid-template-areas: "play playback tools navigation";
  }
  /* Na mniejszym tablecie licznik i czas obok suwaka zwalniają miejsce
     dla podpisów nawigacji, bez zmniejszania pól dotykowych. */
  .playback-panel { grid-template-columns: auto minmax(20px, 1fr); gap: 2px 4px; font-size: .75rem; }
  .counter { grid-column: 1; grid-row: 1; }
  .time { grid-column: 1; grid-row: 2; }
  .progress { grid-column: 2; grid-row: 1 / 3; height: var(--control-size); }
  .navigation button { width: auto; min-width: 44px; padding: 0 6px; gap: 4px; font-size: .8rem; }
  .nav-label { display: inline; }
  .nav-arrow { font-size: 1.45em; }
}

@container (min-width: 720px) {
  .controls { gap: 8px; margin-top: 14px; }
  .playback-panel { grid-template-columns: minmax(0, 1fr) auto; gap: 2px 6px; font-size: .82rem; }
  .time { grid-column: 2; grid-row: 1; }
  .progress { grid-column: 1 / -1; grid-row: 2; height: 24px; }
  .utility-controls { gap: 8px; }
  .navigation { gap: 8px; }
  .navigation button { min-width: 112px; padding: 0 10px; gap: 7px; font-size: .9rem; }
}

@container (min-width: 1040px) {
  .controls {
    grid-template-columns: var(--control-size) minmax(220px, 360px) auto minmax(148px, 1fr) auto;
    grid-template-areas: "play playback tools spacer navigation";
    gap: 12px;
  }
  .navigation { gap: 10px; }
  .navigation button { min-width: 148px; padding: 0 14px; font-size: 1rem; }
  .navigation-spacer { display: block; }
}

@media (max-width: 820px) {
  :root { scrollbar-gutter: auto; }
  body { place-items: start center; }
  #player {
    --player-main-limit: 100%;
    --player-main-width: var(--fitted-player-main-width, var(--player-main-limit));
  }
  .shell { width: 100%; min-height: 0; }
  .shell.sidebar-open .player-composite { width: 100%; }
  .slide-sidebar {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    height: 380px;
    max-height: min(60dvh, 420px);
    min-height: 280px;
    border-left: 0;
    border-top: 1px solid #d8e0e7;
    border-radius: 0 0 12px 12px;
    box-shadow: none;
  }
  .sidebar-close { width: 44px; height: 44px; }
  .sidebar-view-button, .slide-search-submit { min-height: 44px; }
  .slide-search-input { min-height: 44px; font-size: 16px; }
  .slide-search-form { grid-template-columns: minmax(0, 1fr) auto; }
  .slide-search-status { overflow-wrap: anywhere; }
  .slide-thumbnail-list, .slide-search-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(130px, 100%), 1fr));
    gap: 8px;
    align-content: start;
  }
  .slide-thumbnail { margin: 0; }
  .shell:fullscreen { padding: 8px; overflow-y: auto; place-items: start center; }
  .shell:fullscreen .player-composite,
  .shell:fullscreen.sidebar-open .player-composite,
  .shell:fullscreen .player-content { width: 100%; }
}

@media (max-width: 680px) {
  body { padding: 0; }
  .player-content { padding: 8px; }
  .player-header { min-height: 52px; gap: 8px; padding-bottom: 8px; }
  .brand-logo { height: 36px; max-width: 36%; }
  .sidebar-toggle { width: 44px; height: 44px; }
  .header-actions { gap: 8px; }
  .presentation-name { max-width: 100%; font-size: .88rem; }
  .caption-panel { max-height: 160px; }
  .caption-list { padding: 10px; font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  .stage img.slide-transition { animation: none; }
}

/* Film zachowuje proporcje także w ramce i na telefonie. */
.video-screen[hidden] { display: none; }
.stage.is-video { display: block; height: auto; max-height: none; background: #edf3f8; }
.video-screen { width: 100%; min-width: 0; padding: clamp(8px, 2cqw, 28px); background: center top / contain no-repeat; overflow-wrap: anywhere; }
.video-card { min-width: 0; padding: clamp(10px, 1.6cqw, 22px); border: 1px solid #d5e2eb; border-radius: 14px; background: rgb(255 255 255 / 96%); color: #213747; font-size: clamp(1rem, 1.6cqw, 1.2rem); line-height: 1.45; }
.video-title { margin: 0 0 .65em; font-size: 1.35em; line-height: 1.3; white-space: pre-wrap; }
.video-media { display: block; width: 100%; max-width: 100%; height: auto; max-height: 65dvh; aspect-ratio: var(--video-aspect, 16 / 9); object-fit: contain; background: #10202b; border-radius: 8px; }
.video-message:empty { display: none; }
.video-message { margin: .7em 0; color: #8b3a16; }
.video-thumbnail { background: #e6f1fa; }
@container (max-width: 600px) { .video-card { border-radius: 10px; } }
/* Shown only when the browser requires a click before audio playback. */
.playback-notice { margin: 6px 0; color: #245b86; font-size: 0.9rem; }
.playback-notice[hidden] { display: none; }
