:root {
  --stage: #000;
  --fg: #f2f2f0;
  --muted: #a3a39d;
  --glass: rgba(18, 18, 17, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #8fb0ff;
  --fade: 1200ms;
  /* Obrys tekstu na kolorowym tle: 8 cieni dookoła + miękki cień pod spodem. */
  --outline: -2px -2px 0 #000, 0 -2px 0 #000, 2px -2px 0 #000, 2px 0 0 #000, 2px 2px 0 #000, 0 2px 0 #000,
    -2px 2px 0 #000, -2px 0 0 #000, 0 3px 8px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}
/* Przenikanie zmienia tylko przezroczystość (bez ruchu), więc zostaje także przy
   „ogranicz ruch” w systemie. Wyłączamy jedynie przesuwanie paska sterowania. */
@media (prefers-reduced-motion: reduce) {
  .controls, .toast { transform: none !important; }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--stage);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }

/* ---------- scena ---------- */
#stage { position: fixed; inset: 0; background: var(--stage); touch-action: pan-y; }
/* Przenikanie: nowy obrazek (.front) pojawia się NAD starym, stary znika dopiero po
   animacji – bez przyciemnienia w połowie. Czarne tło warstwy zakrywa też pasy. */
.slide {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; object-position: center;
  background: var(--stage);
  opacity: 0; z-index: 0; transition: opacity var(--fade) ease-in-out;
  user-select: none; -webkit-user-drag: none;
}
.fit-cover .slide { object-fit: cover; }
.slide.on { opacity: 1; z-index: 1; }
.slide.front { z-index: 2; }
.slide.instant { transition: none; }

/* ---------- podpis ---------- */
.caption {
  position: fixed; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0; max-width: min(70ch, calc(100% - 32px));
  padding: 4px 10px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.45); color: rgba(255, 255, 255, 0.85);
  font-size: 13px; text-shadow: 0 1px 2px #000;
  transition: opacity 300ms, transform 300ms;
  pointer-events: none;
}
body.ui .caption { transform: translateY(-64px); }

/* ---------- sterowanie ---------- */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 0 max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity 250ms, transform 250ms;
}
body.ui .controls { opacity: 1; transform: none; pointer-events: auto; }
body.started:not(.ui) { cursor: none; }
body:not(.started) .controls { display: none; }

.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 0 4px 8px; }
.progress span { display: block; height: 100%; width: 100%; background: var(--fg); transform-origin: left; transform: scaleX(0); }
.progress span.run { animation: progress linear forwards; }
body.paused .progress span.run { animation-play-state: paused; }
@keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.bar { display: flex; align-items: center; gap: 4px; }
.bar .spacer { flex: 1; }
.bar button {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer;
}
.bar button:hover, .bar button:focus-visible { background: rgba(255, 255, 255, 0.12); outline: none; }
.bar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bar svg .fill { fill: currentColor; stroke: none; }
.bar .i-play { display: none; }
body.paused .bar .i-play { display: block; }
body.paused .bar .i-pause { display: none; }
.counter { color: var(--muted); font-size: 13px; padding: 0 8px; font-variant-numeric: tabular-nums; }

/* ---------- ekran startowy ---------- */
.start {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px 16px; text-align: center;
  background: #000 url("../bg.png") center / cover no-repeat;
  background-image: image-set(url("../bg.webp") type("image/webp"), url("../bg.png") type("image/png"));
  transition: opacity 400ms;
}
body.started .start { opacity: 0; pointer-events: none; }
.start h1 {
  margin: 0; font-size: clamp(48px, 11vw, 96px); font-weight: 800; letter-spacing: -0.01em; color: #fff;
  -webkit-text-stroke: 0.08em #000; paint-order: stroke fill; /* obrys na zewnątrz liter */
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.7);
}
.start-status, .hint { color: #fff; font-weight: 600; text-shadow: var(--outline); }
.start-status { margin: 0; min-height: 1.45em; font-size: 17px; }
.start-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.hint { margin: 18px 0 0; font-size: 13px; max-width: 46ch; }
.start button:not(.primary) { background: rgba(0, 0, 0, 0.72); border-color: rgba(255, 255, 255, 0.7); font-weight: 600; }
.start button { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55); }
@media (hover: none) { .hint { display: none; } }

button.primary, .start button, .dialog-actions button {
  padding: 10px 20px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); cursor: pointer;
}
button.primary { background: var(--fg); color: #000; border-color: var(--fg); font-weight: 600; }
button:disabled { opacity: 0.45; cursor: default; }
.start button:focus-visible, .dialog-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- ustawienia ---------- */
.settings {
  width: min(420px, calc(100% - 32px)); padding: 20px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--glass); color: var(--fg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.settings::backdrop { background: rgba(0, 0, 0, 0.35); }
.settings h2 { margin: 0 0 14px; font-size: 18px; }
.field { display: block; border: 0; padding: 0; margin: 0 0 16px; }
.field > span:first-child, .field legend { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; padding: 0; }
.field label { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }
.field.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.interval { display: flex; align-items: center; gap: 12px; }
.interval input { flex: 1; accent-color: var(--fg); }
.interval output { min-width: 5ch; text-align: right; font-variant-numeric: tabular-nums; }
input[type=radio], input[type=checkbox] { accent-color: var(--fg); width: 16px; height: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

/* ---------- stan ---------- */
.spinner {
  position: fixed; right: 20px; top: 20px; width: 22px; height: 22px;
  border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; top: 20px; transform: translate(-50%, -8px);
  padding: 8px 14px; border-radius: 10px; background: var(--glass); border: 1px solid var(--line);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 200ms, transform 200ms;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }
