:root {
  --bg: #ffffff;
  --fg: #000000;
  --mute: #6b6b6b;
  --line: #d4d4d4;
  --soft: #f3f3f3;
  --wave: #bcbcbc;
  --strip: #dedede;
  --font: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --dock-h: 72px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --fg: #ffffff; --mute: #8c8c8c; --line: #2e2e2e;
    --soft: #101010; --wave: #474747; --strip: #262626; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --fg: #ffffff; --mute: #8c8c8c; --line: #2e2e2e;
  --soft: #101010; --wave: #474747; --strip: #262626; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 400 14px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 18px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; margin: 0; }
h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .14em; color: var(--mute); margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
h3:first-child { margin-top: 4px; }
.mute { color: var(--mute); }
.error { color: var(--fg); border: 1px solid var(--fg); padding: 8px 10px; margin: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* przyciski */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 16px;
  font: 500 13px/1 var(--font); text-transform: uppercase; letter-spacing: .08em; text-align: center;
  color: var(--fg); background: var(--bg); border: 1px solid var(--fg); border-radius: 0;
  cursor: pointer; user-select: none;
}
.btn:active { background: var(--fg); color: var(--bg); }
.btn.solid, .btn.on { background: var(--fg); color: var(--bg); }
.btn.wide { width: 100%; }
.link {
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  font: 500 12px/1 var(--font); text-transform: uppercase; letter-spacing: .08em;
  color: var(--fg); text-decoration: underline; text-underline-offset: 3px;
}

input, select {
  font: 400 15px/1.2 var(--font); color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 0; padding: 11px 12px; min-width: 0; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--fg); }
input[type="range"] { -webkit-appearance: none; appearance: none; border: 0; padding: 0; height: 32px; background: transparent; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--fg); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--fg); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -9px; background: var(--fg); border: 0; border-radius: 0; }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: var(--fg); border: 0; border-radius: 0; }
input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; flex: none;
  width: 22px; height: 22px; padding: 0; margin: 0; border: 1px solid var(--fg); background: var(--bg); cursor: pointer;
}
input[type="checkbox"]:checked { background: var(--fg); box-shadow: inset 0 0 0 4px var(--bg); }

.progress { width: 100%; height: 2px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--fg); transition: width .15s; }

/* ekrany logowania / wgrania */
.screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--mute); }
.field b { color: var(--fg); font-weight: 500; }
.box .field { margin: 0; }

/* odtwarzacz – układ telefonu */
.player { padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); }

.stage { position: relative; background: #000; display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 9; max-height: 42vh; width: 100%; overflow: hidden; }
.stage #yt { display: block; border: 0; }
.shield { position: absolute; inset: 0; z-index: 1; cursor: pointer; }
.stage.mirror iframe { transform: scaleX(-1); }
.stage:fullscreen { aspect-ratio: auto; max-height: none; height: 100vh; }
.stage-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; color: #fff; text-align: center; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.stage-msg { background: #000; z-index: 3; }
.stage-msg .progress { width: 60%; background: #333; }
.stage-msg .progress > div { background: #fff; }
/* nakładki na odtwarzaczu: czas, menu, pełny ekran */
.hud { position: absolute; z-index: 3; color: #fff; }
.hud-tl {
  top: 8px; left: 8px; padding: 6px 8px; background: rgba(0, 0, 0, .55);
  font: 500 12px/1 var(--font); font-variant-numeric: tabular-nums; pointer-events: none;
}
.hud-tl span { color: rgba(255, 255, 255, .75); }
.hud-btn {
  width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer;
  background: rgba(0, 0, 0, .55); border: 1px solid rgba(255, 255, 255, .5);
}
.hud-btn:active { background: #fff; color: #000; }
.hud-tr { top: 8px; right: 8px; }
.hud-br { bottom: 8px; right: 8px; }

.overlay { position: absolute; inset: 0; z-index: 2; pointer-events: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(0, 0, 0, .6); color: #fff; }
.overlay-big { font-size: clamp(56px, 22vw, 180px); font-weight: 700; line-height: 1; text-align: center; padding: 0 16px; }
.overlay-small { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .1em; text-align: center; padding: 0 16px; }

.timeline { padding: 8px 16px; border-bottom: 1px solid var(--line); }
#wave { display: block; width: 100%; height: 56px; touch-action: none; cursor: pointer; background: var(--soft); }
/* lista fragmentów pod filmem */
.frags { padding: 12px 16px 16px; }
.frags > .btn { min-height: 44px; }
.frags .list { margin-top: 12px; }
.hint { font-size: 12px; color: var(--mute); margin: 8px 0 0; }
.hint .link { margin-left: 6px; }

/* lista fragmentów */
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); -webkit-user-select: none; user-select: none; }
.list input { -webkit-user-select: text; user-select: text; }
.item { border-bottom: 1px solid var(--line); }
.item-head { display: flex; align-items: center; gap: 12px; padding: 12px 0; cursor: pointer; min-height: 60px; }
.num { flex: none; min-width: 34px; height: 34px; padding: 0 4px; display: grid; place-items: center; border: 1px solid var(--fg); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.item.active .num { background: var(--fg); color: var(--bg); }
.meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.meta b { font-weight: 700; text-transform: uppercase; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta small { font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; }
.play-sm { flex: none; width: 44px; height: 44px; border: 1px solid var(--fg); background: var(--bg); cursor: pointer; font-size: 14px; }
.play-sm:active, .item.active .play-sm { background: var(--fg); color: var(--bg); }
.del {
  flex: none; height: 44px; padding: 0 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--mute);
  font: 500 11px/1 var(--font); text-transform: uppercase; letter-spacing: .06em;
}
.del:active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.handle { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.item.dragging { position: relative; z-index: 5; background: var(--bg); box-shadow: 0 0 0 1px var(--fg), 0 8px 24px rgba(0, 0, 0, .25); }
.item.dragging .handle { cursor: grabbing; background: var(--fg); color: var(--bg); }
.video-title { font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 12px; }
.item-edit { padding: 2px 0 16px 46px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 6px; }
.row-label { flex: 1; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--mute); }
.val { min-width: 64px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; background: none; border: 0; padding: 0 4px; cursor: pointer; }
.sq { flex: none; min-width: 40px; height: 40px; padding: 0 8px; border: 1px solid var(--fg); background: var(--bg); cursor: pointer; font: 500 13px/1 var(--font); text-transform: uppercase; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.sq:active, .sq.on { background: var(--fg); color: var(--bg); }
/* ustawienia (modal) */
.sheet {
  border: 1px solid var(--fg); padding: 0; margin: auto auto 0; width: 100%; max-width: 520px;
  max-height: 88vh; max-height: 88dvh; background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column;
}
.sheet:not([open]) { display: none; }
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--fg); }
.sheet-head h2 { margin: 0; font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.sheet-body { overflow: auto; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-body h3:first-child { margin-top: 16px; }
@media (min-width: 640px) { .sheet { margin: auto; } }

.settings .check { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; }
.settings .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings .btn { margin-top: 6px; }

/* dolny panel sterowania */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--bg); border-top: 1px solid var(--fg);
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px;
}
.dock-info { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.player:has(.dock-info:not([hidden])) { --dock-h: 92px; }
.dock-info #range-info { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock-info #rep-info { color: var(--mute); white-space: nowrap; }
.tempo { display: flex; align-items: center; gap: 8px; }
.tempo .sq { min-width: 40px; height: 40px; }
.tempo input { flex: 1; }
.tempo b { min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; font-size: 15px; }
.rate-chips { display: flex; gap: 6px; margin: 10px 0 4px; }
.rate-chips .sq { flex: 1; }
.transport { display: grid; grid-template-columns: 1fr 1fr 1.3fr 1fr 1fr; gap: 6px; }
.tbtn {
  height: 44px; border: 1px solid var(--fg); background: var(--bg); cursor: pointer; padding: 0 2px;
  font: 500 11px/1.1 var(--font); text-transform: uppercase; letter-spacing: .06em;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
.tbtn:active, .tbtn.on { background: var(--fg); color: var(--bg); }
.tbtn.play { background: var(--fg); color: var(--bg); font-size: 18px; letter-spacing: 0; }
.tbtn.play:active { opacity: .8; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--dock-h) + 12px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--fg); color: var(--bg); padding: 12px 14px; font-size: 13px; text-align: center;
}

/* telefon poziomo – wideo nie może zajmować całego ekranu */
@media (max-height: 520px) and (orientation: landscape) {
  .top { position: static; }
  .stage { max-height: 80vh; }
}

/* komputer: wideo po lewej, fragmenty po prawej */
@media (min-width: 1000px) {
  .player { display: grid; grid-template-columns: minmax(0, 1fr) 440px; align-items: start; }
  .top { height: calc(100vh - var(--dock-h)); display: flex; flex-direction: column; border-right: 1px solid var(--line); }
  .stage { flex: 1; max-height: none; aspect-ratio: auto; }
  .dock { flex-direction: row; align-items: center; gap: 24px; padding: 12px 24px; }
  .dock-info { flex-direction: column; width: 260px; }
  .player:has(.dock-info:not([hidden])) { --dock-h: 72px; }
  .transport { flex: 1; max-width: 520px; margin-left: auto; }
  .toast { left: 50%; right: auto; transform: translateX(-50%); }
}
