:root {
  --bg: #ffffff;
  --surface: #f6f6f7;
  --ink: #1b1b1f;
  --muted: #6b6b76;
  --line: #e6e6ea;
  --accent: #e0352b;
  --accent-ink: #ffffff;
  --bar: #1b1b1f;
  --bar-ink: #ffffff;
  --bar-line: #3a3a42;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1e1e23;
    --ink: #f3f3f5;
    --muted: #a0a0ab;
    --line: #2e2e35;
    --accent: #f0574d;
    --accent-ink: #131316;
    --bar: #2a2a31;
    --bar-line: #464650;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.375rem; line-height: 1.3; margin: 0; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { font-size: 1rem; margin: 0; }
p { margin: 0; }

.muted { color: var(--muted); font-size: 0.8125rem; }
.error { color: var(--accent); font-size: 0.875rem; }
.error:empty { display: none; }

button { font: inherit; cursor: pointer; border-radius: 8px; }
input, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary { background: var(--ink); color: var(--bg); border: 0; padding: 0.5rem 1rem; font-weight: 600; white-space: nowrap; }
.ghost { background: transparent; color: inherit; border: 1px solid var(--line); padding: 0.35rem 0.7rem; font-size: 0.8125rem; white-space: nowrap; }
.ghost:hover { background: var(--surface); }
.danger { color: var(--accent); }
.small { padding: 0.1rem 0.45rem; font-size: 0.75rem; }
.check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8125rem; white-space: nowrap; }
.check input { width: auto; }

.dot { width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--accent); flex: none; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* Górny pasek */
.topbar {
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { font-weight: 700; font-size: 1.0625rem; letter-spacing: -0.01em; }
.topbar-actions, .start { display: flex; align-items: center; gap: 0.75rem; }
.record {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  padding: 0.5rem 1rem;
  font-weight: 650;
  white-space: nowrap;
}
.record .dot { background: currentColor; }

/* Logowanie */
.login { max-width: 340px; margin: 14vh auto 0; padding: 0 16px; }
.login form { display: grid; gap: 0.6rem; margin-top: 1.5rem; }
.login label { font-size: 0.875rem; }

/* Biblioteka */
.library { max-width: 1320px; margin: 0 auto; padding: 1.75rem 20px 9rem; display: grid; gap: 1.25rem; }
.videos {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
.video { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; background: var(--bg); }
.video:hover { box-shadow: 0 4px 18px rgb(0 0 0 / 0.08); }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--surface); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / 0.75); color: #fff; font-size: 0.75rem; padding: 0 0.35rem; border-radius: 4px; font-variant-numeric: tabular-nums; }
.info { padding: 0.65rem 0.75rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 0; }
.title-input { border-color: transparent; background: transparent; padding: 0.1rem 0.3rem; margin-left: -0.3rem; font-weight: 600; text-overflow: ellipsis; }
.title-input:hover { border-color: var(--line); }
.actions { display: flex; gap: 0.4rem; margin-top: auto; padding-top: 0.6rem; }

/* Pasek w trakcie nagrywania */
.live-bar {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: min(380px, calc(100vw - 32px));
  background: var(--bar);
  color: var(--bar-ink);
  border-radius: 14px;
  padding: 0.85rem;
  display: grid;
  gap: 0.6rem;
  box-shadow: 0 10px 34px rgb(0 0 0 / 0.3);
  z-index: 10;
}
.live-row { display: flex; align-items: center; gap: 0.6rem; }
.timer { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stop { margin-left: auto; background: var(--accent); color: #fff; border: 0; padding: 0.4rem 0.9rem; font-weight: 650; }
.share { display: flex; gap: 0.4rem; }
.share input { min-width: 0; background: transparent; border-color: var(--bar-line); color: inherit; font-size: 0.8125rem; }
.copy-dark { background: transparent; color: inherit; border: 1px solid var(--bar-line); padding: 0.35rem 0.7rem; font-size: 0.8125rem; white-space: nowrap; }
.live-note { font-size: 0.75rem; opacity: 0.75; }

.countdown {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 160px;
  height: 160px;
  margin: -80px 0 0 -80px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bar);
  color: var(--bar-ink);
  font-size: 4.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  z-index: 20;
}

/* Oglądanie */
.watch-page { height: 100dvh; display: flex; flex-direction: column; }
.watch-page .topbar { flex: none; }
.watch { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; }
.stage { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.player { background: #000; border-radius: 12px; overflow: hidden; flex: none; }
.player video { display: block; width: 100%; max-height: calc(100dvh - 190px); }
.waiting { aspect-ratio: 16 / 9; display: grid; place-items: center; text-align: center; padding: 1.5rem; color: #fff; }

.markers { position: relative; height: 12px; flex: none; }
.markers:empty { display: none; }
.marker { position: absolute; top: 1px; width: 10px; height: 10px; margin-left: -5px; padding: 0; border: 0; border-radius: 50%; background: var(--accent); }
.marker:hover { transform: scale(1.3); }

.comments { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.comments h2 { padding: 1rem 1rem 0.75rem; border-bottom: 1px solid var(--line); }
.comments-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0.75rem 1rem; }
.comments ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.comment-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; font-size: 0.875rem; }
.comment-body { margin: 0.15rem 0 0.3rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-body:last-child { margin-bottom: 0; }
.stamp { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; }
.stamp:hover { text-decoration: underline; }
#comment-form { flex: none; display: grid; gap: 0.45rem; padding: 0.75rem 1rem 1rem; border-top: 1px solid var(--line); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

@media (max-width: 900px) {
  .watch-page { height: auto; display: block; }
  .watch { display: block; }
  .player video { max-height: none; }
  .comments { border-left: 0; border-top: 1px solid var(--line); }
  .comments-scroll { overflow: visible; }
}

@media (max-width: 560px) {
  .topbar { height: auto; padding: 10px 16px; flex-wrap: wrap; }
  .library { padding-inline: 16px; }
  .stage { padding: 12px 16px; }
  .live-bar { left: 16px; bottom: 16px; }
}
