* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: #0b1220;
  color: #e8ecf4;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

#stage {
  position: fixed;
  inset: 0;
  background: #000;
}

/* Ramka kadru: dokładnie te proporcje, w jakich powstaje film.
   To, co widać wewnątrz, jest 1:1 z zapisaną klatką i finalnym filmem. */
#frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: #000;
}
#frame::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255,255,255,0.18);
  pointer-events: none;
}

#camera, #onion {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#onion { pointer-events: none; }
#camera.mirrored, #onion.mirrored { transform: scaleX(-1); }

#flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}
#flash.on { opacity: 0.7; transition: none; }

/* Pasek górny */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: linear-gradient(rgba(0,0,0,0.55), rgba(0,0,0,0));
}

.badge {
  background: rgba(0,0,0,0.55);
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 14px;
}

.iconbtn {
  background: rgba(0,0,0,0.55);
  color: #e8ecf4;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 15px;
  cursor: pointer;
}

/* Pasek dolny */
#bottombar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.6));
}

#thumbs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 10px;
  min-height: 12px;
  -webkit-overflow-scrolling: touch;
}
#thumbs img {
  height: 52px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.35);
  flex: 0 0 auto;
  cursor: pointer;
}
#thumbs img:last-child { border-color: #ffb020; border-width: 2px; }

#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 34px;
  padding: 8px 0 4px;
}

#btnCapture {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
#btnCapture span {
  display: block;
  width: 56px;
  height: 56px;
  margin: 3px auto;
  border-radius: 50%;
  background: #e63946;
  transition: transform 0.1s;
}
#btnCapture:active span { transform: scale(0.85); }

.ctrlbtn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}

/* Komunikaty i modale */
.overlay-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(11,18,32,0.92);
  padding: 24px;
  text-align: center;
  z-index: 5;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
  padding: 16px;
}

.modal-box {
  background: #141d31;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h2 { font-size: 18px; margin-bottom: 16px; }

.setting {
  display: block;
  margin-bottom: 18px;
  font-size: 14px;
}
.setting span { display: block; margin-bottom: 6px; color: #b9c3d6; }
.setting b { color: #fff; }
.setting input[type="range"] { width: 100%; }
.setting select {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  background: #0b1220;
  color: #e8ecf4;
  border: 1px solid rgba(255,255,255,0.2);
  font-size: 15px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  background: #26324d;
  color: #e8ecf4;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: #2e6bff; border-color: #2e6bff; color: #fff; }
.btn.danger { background: #7a1f2b; border-color: #a33; color: #fff; }

/* Odtwarzacz / podgląd klatki */
.player-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 720px;
}
#playerCanvas, #viewerImg {
  max-width: 100%;
  max-height: 75vh;
  border-radius: 10px;
  background: #000;
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Eksport */
.progress {
  height: 10px;
  border-radius: 5px;
  background: #0b1220;
  overflow: hidden;
  margin: 10px 0 14px;
}
#exportProgress {
  height: 100%;
  width: 0%;
  background: #2e6bff;
  transition: width 0.15s linear;
}
#exportVideo { width: 100%; border-radius: 10px; margin-bottom: 10px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 130px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}
