:root {
  color-scheme: dark;
  --bg: #0a0a09;
  --panel: #131311;
  --panel-2: #1b1a17;
  --ink: #f5f0e6;
  --muted: #9b978e;
  --line: #302e29;
  --accent: #ff4f43;
  --focus: #7cc7ff;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: var(--bg);
  color: var(--ink);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(32px, calc(var(--safe-top) + 24px)) 22px max(28px, calc(var(--safe-bottom) + 20px));
  display: grid;
  align-content: center;
  gap: 28px;
  max-width: 460px;
  margin: 0 auto;
}

.login-mark {
  width: 72px;
  height: 72px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
}

.login-mark img, .brand img { width: 100%; height: 100%; object-fit: cover; }
.login-copy { display: grid; gap: 8px; }
.login-copy h1, .library-head h1 { margin: 0; letter-spacing: -0.055em; line-height: .96; }
.login-copy h1 { font-size: clamp(42px, 13vw, 62px); }
.login-copy p:not(.eyebrow) { margin: 0; color: var(--muted); line-height: 1.55; max-width: 40ch; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; }
.login-form input, .search-box, .sort-control select {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
}
.login-form input { min-height: 52px; padding: 0 14px; font-size: 16px; }
.primary-button {
  min-height: 54px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  cursor: pointer;
}
.primary-button:active { transform: translateY(1px); }
.form-error { min-height: 18px; margin: -4px 0 0; color: #ff8c84; font-size: 12px; }

.app-shell { min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: calc(64px + var(--safe-top));
  padding: var(--safe-top) 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: -.03em; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
}
.icon-button svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main { width: min(1180px, 100%); margin: 0 auto; padding: 38px 18px calc(48px + var(--safe-bottom)); }
.library-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.library-head > div { display: grid; gap: 10px; }
.library-head h1 { font-size: clamp(35px, 8vw, 70px); max-width: 13ch; }
.count { color: var(--muted); margin: 0 0 5px; font-size: 12px; white-space: nowrap; }

.controls { margin-top: 32px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; }
.search-box svg { width: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; }
.search-box input::placeholder { color: #716d65; }
.sort-control select { min-height: 48px; padding: 0 38px 0 13px; }

.folder-list { display: flex; gap: 8px; overflow-x: auto; padding: 16px 0 4px; scrollbar-width: none; }
.folder-list::-webkit-scrollbar { display: none; }
.folder-chip { flex: none; min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; }
.folder-chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.video-grid { margin-top: 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 12px; }
.video-card { display: grid; gap: 11px; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.poster { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.poster > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-fallback { position: absolute; inset: 0; display: grid; place-items: center; background: #11110f; }
.poster-fallback img { width: 38%; height: 38%; object-fit: cover; border-radius: 18%; opacity: .7; }
.video-card.has-poster .poster-fallback { display: none; }
.play-mark { position: absolute; left: 10px; bottom: 10px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: var(--bg); }
.play-mark svg { width: 17px; fill: currentColor; }
.progress-track { position: absolute; inset: auto 0 0; height: 3px; background: rgba(255,255,255,.14); }
.progress-track span { display: block; height: 100%; width: 0; background: var(--accent); }
.card-copy { display: grid; gap: 5px; min-width: 0; }
.card-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; letter-spacing: -.025em; }
.card-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }

.status-panel { margin-top: 24px; min-height: 180px; padding: 28px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); line-height: 1.55; display: grid; place-items: center; text-align: center; }

.player-view { position: fixed; z-index: 30; inset: 0; min-height: 100dvh; background: var(--bg); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.player-bar { min-height: calc(72px + var(--safe-top)); padding: var(--safe-top) 12px 0; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 5px; border-bottom: 1px solid var(--line); }
.player-title-wrap { min-width: 0; }
.player-title-wrap p, .player-title-wrap h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-title-wrap p { color: var(--muted); font-size: 10px; }
.player-title-wrap h2 { margin-top: 3px; font-size: 14px; }
.video-stage { min-height: 0; display: grid; place-items: center; background: #000; }
.video-stage video { display: block; width: 100%; max-height: 100%; background: #000; }
.player-meta { min-height: calc(58px + var(--safe-bottom)); padding: 0 18px var(--safe-bottom); display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line); }
.player-meta p { margin: 0; color: var(--muted); font-size: 11px; }
.text-button { min-height: 44px; border: 0; background: transparent; color: var(--ink); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

@media (min-width: 720px) {
  .video-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 30px 18px; }
  main { padding-inline: 28px; }
  .topbar { padding-inline: 28px; }
}

@media (min-width: 1040px) {
  .video-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .controls { grid-template-columns: 1fr; }
  .sort-control select { width: 100%; }
  .library-head { align-items: start; flex-direction: column; gap: 10px; }
  .count { margin: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .video-card .poster { transition: border-color 150ms ease, transform 150ms ease; }
  .video-card:active .poster { transform: scale(.985); }
}
