:root {
  color-scheme: dark;
  --background: #101116;
  --surface: #1a1c24;
  --surface-hover: #242631;
  --border: #343641;
  --text: #f3f2f7;
  --text-muted: #a7a7b5;
  --accent: #8a72ed;
  --accent-hover: #9b86f4;
  --danger: #e17b88;
  --radius: 10px;
  --content-width: 1380px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--text);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }
:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .45; }

.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;
}
.skip-link {
  position: fixed;
  top: -5rem;
  left: 1rem;
  z-index: 100;
  padding: .65rem 1rem;
  background: var(--accent);
  border-radius: 6px;
}
.skip-link:focus { top: 1rem; }

.app-header {
  border-bottom: 1px solid #2d2e37;
  background: #171920;
}
.app-header-inner {
  max-width: var(--content-width);
  min-height: 66px;
  margin: auto;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 2.25rem;
}
.primary-nav { display: flex; align-items: stretch; gap: .2rem; align-self: stretch; }
.primary-nav a {
  display: inline-flex;
  align-items: center;
  padding: 0 .9rem;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: .91rem;
  font-weight: 600;
  transition: color .16s, border-color .16s;
}
.primary-nav a:hover, .primary-nav a[aria-current="page"] { color: var(--text); }
.primary-nav a[aria-current="page"] { border-color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: .55rem; margin-left: auto; }
.header-actions form { margin: 0; }

.container { max-width: var(--content-width); margin: auto; padding: 1.75rem 2rem 5rem; }
.eyebrow {
  color: #b8a8fb;
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: .38rem;
}
.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.45rem;
}
.page-heading h1 { font-size: clamp(1.75rem, 3vw, 2.3rem); line-height: 1.15; letter-spacing: -.045em; margin: 0; }
.page-heading-compact { margin-bottom: 1.2rem; }
.page-subtitle { color: var(--text-muted); margin: .4rem 0 0; }
.collection-count, .section-count { color: var(--text-muted); font-size: .85rem; }
.collection-count { padding-bottom: .2rem; white-space: nowrap; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .65rem 1rem;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color .16s, border-color .16s, color .16s, transform .16s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-secondary { background: #282a34; border-color: #42434d; color: var(--text); }
.button-secondary:hover:not(:disabled) { background: #333540; border-color: #565762; }
.button-ghost { background: transparent; color: var(--text-muted); }
.button-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.button-danger { background: #6d303c; color: #fff; }
.button-danger:hover:not(:disabled) { background: #863a48; }
.button-small { min-height: 36px; padding: .5rem .78rem; font-size: .83rem; }
.button-block { width: 100%; }
.back-link { display: inline-flex; align-items: center; color: var(--text-muted); font-size: .87rem; font-weight: 600; margin-bottom: 1.1rem; }
.back-link:hover, .section-link:hover { color: var(--text); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.field { display: grid; gap: .38rem; min-width: 0; }
.field label { color: #d7d6e0; font-size: .86rem; font-weight: 650; }
.field input, .field select, .field textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 43px;
  padding: .68rem .8rem;
  background: #12141c;
  border: 1px solid #41434f;
  border-radius: 7px;
  color: var(--text);
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.field textarea { min-height: 115px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #858594; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #656575; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #8a72ed33; }
.field-help { color: var(--text-muted); font-size: .82rem; margin: 0; }
.form-stack { display: grid; gap: 1.1rem; }
.form-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }
.alert { padding: .8rem 1rem; margin-bottom: 1.2rem; border: 1px solid #a95768; border-radius: 7px; background: #38222b; color: #ffe5ea; }
.alert-success { border-color: #398867; background: #1a3329; color: #d6f5e5; }
.alert-info { border-color: #6261a1; background: #27263c; color: #e9e5ff; }

.auth-body { background: var(--background); }
.auth-body .container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card { flex: 0 1 420px; width: 100%; min-width: 0; padding: 2.2rem; box-shadow: 0 16px 44px #0003; }
.auth-card h1 { font-size: 1.95rem; letter-spacing: -.04em; line-height: 1.15; margin: .25rem 0 .55rem; }
.auth-intro { color: var(--text-muted); margin-bottom: 1.55rem; }
.auth-card .form-stack { gap: 1.1rem; }
.auth-card .button-block { margin-top: .25rem; }

.library-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(170px, 230px) auto auto;
  align-items: end;
  gap: .7rem;
  margin-bottom: 1.7rem;
}
.library-toolbar .field label { font-size: .77rem; color: var(--text-muted); }
.library-toolbar .field input, .library-toolbar .field select { min-height: 42px; }
.toolbar-submit, .toolbar-clear { align-self: end; }
.toolbar-search input { appearance: none; }

.media-section { margin: 0 0 2.2rem; }
.section-heading { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .9rem; }
.section-heading h2 { font-size: 1.22rem; letter-spacing: -.025em; line-height: 1.25; margin: 0; }
.section-link { color: #b8a8fb; font-size: .83rem; font-weight: 600; margin-left: auto; }
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 1.25rem 1rem; }
.media-row { display: flex; gap: 1rem; overflow-x: auto; padding: 0 .1rem .75rem; margin: 0 -.1rem; scroll-snap-type: x proximity; scrollbar-color: #555665 transparent; }
.media-row .video-card { flex: 0 0 clamp(230px, 23vw, 290px); scroll-snap-align: start; }
.video-card { position: relative; min-width: 0; border-radius: 8px; transition: transform .16s; }
.video-card-link { display: block; }
.video-card:hover { transform: translateY(-3px); }
.video-card-image { display: block; position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; border: 1px solid #383948; border-radius: 8px; background: #1c2030; }
.video-card-image::after { content: ""; position: absolute; inset: 0; background: #08091200; transition: background-color .16s; }
.video-card:hover .video-card-image, .video-card:focus-within .video-card-image { border-color: #7969bd; }
.video-card:hover .video-card-image::after, .video-card:focus-within .video-card-image::after { background: #08091244; }
.video-card-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.video-card-image > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .16s; }
.video-card.is-previewing .video-card-image > video { opacity: 1; }
.card-play {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 42px;
  height: 42px;
  border: 1px solid #ffffff88;
  border-radius: 50%;
  background: #181824bb;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity .16s;
}
.card-play::after { content: ""; position: absolute; left: 17px; top: 12px; border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-left: 11px solid #fff; }
.video-card:hover .card-play, .video-card:focus-within .card-play { opacity: 1; }
.video-card.is-previewing .card-play { opacity: 0; }
.video-preview-button { position: absolute; z-index: 4; top: .5rem; right: .5rem; min-width: 3.2rem; padding: .35rem .45rem; border: 1px solid #ffffff88; border-radius: 5px; background: #181824dd; color: #fff; font-size: .7rem; font-weight: 650; }
.video-preview-button[hidden] { display: none; }
.video-preview-button:hover, .video-preview-button:focus-visible, .video-card.is-previewing .video-preview-button { background: #413866; }
.duration-badge { position: absolute; z-index: 2; right: .55rem; bottom: .55rem; padding: .15rem .42rem; border-radius: 4px; background: #101116d9; color: #fff; font-size: .72rem; font-variant-numeric: tabular-nums; }
.progressbar { position: absolute; z-index: 3; display: block; inset: auto 0 0; height: 3px; background: #c2bfd466; }
.progressbar > span { display: block; height: 100%; width: 0; background: var(--accent); }
.video-card-copy { display: grid; gap: .2rem; padding: .55rem .05rem 0; }
.video-card-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .91rem; line-height: 1.3; font-weight: 650; }
.video-card-meta { display: flex; gap: .35rem; color: var(--text-muted); font-size: .78rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.video-card-meta > span { color: #666778; }
.category-shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: .7rem; }
.category-shortcut { position: relative; min-width: 0; min-height: 135px; overflow: hidden; border: 1px solid var(--border); border-left: 3px solid #7866c6; border-radius: 7px; background: var(--surface); transition: border-color .16s; }
.category-shortcut:hover, .category-shortcut:focus-within { border-color: #9b86f4; }
.category-shortcut > img, .category-shortcut > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.category-shortcut > video { opacity: 0; transition: opacity .16s; }
.category-shortcut.is-previewing > video { opacity: 1; }
.category-shortcut-link { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: end; gap: .1rem; padding: .8rem .9rem; padding-right: 4.2rem; background: linear-gradient(180deg, #10111622 10%, #101116d9 100%); color: #fff; }
.category-shortcut-link span { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-shortcut-link small { color: #e1dfea; font-size: .77rem; }
.category-preview-button { position: absolute; z-index: 1; right: .5rem; bottom: .55rem; min-width: 3.2rem; padding: .35rem .45rem; border: 1px solid #ffffff88; border-radius: 5px; background: #181824dd; color: #fff; font-size: .7rem; font-weight: 650; }
.category-preview-button[hidden] { display: none; }
.category-preview-button:hover, .category-preview-button:focus-visible { background: #413866; }
.category-shortcut.is-previewing .category-preview-button { background: #413866; }

.empty-state { text-align: center; padding: 2.6rem 1.5rem; border: 1px dashed #454655; border-radius: var(--radius); background: #171920; }
.empty-state-large { margin-top: 1.2rem; padding: 4rem 1.5rem; }
.empty-state h2, .empty-state h3 { font-size: 1.3rem; margin: .8rem 0 .3rem; letter-spacing: -.025em; }
.empty-state p { color: var(--text-muted); max-width: 30rem; margin: 0 auto 1.2rem; }
.empty-symbol { width: 54px; height: 40px; margin: 0 auto; border: 2px solid #8271ce; border-radius: 6px; position: relative; }
.empty-symbol::before { content: ""; position: absolute; left: 12px; top: 10px; border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-left: 12px solid #8271ce; }
.empty-symbol-folder { height: 42px; border-radius: 4px; }
.empty-symbol-folder::before { left: 5px; top: -8px; width: 23px; height: 6px; border: 2px solid #8271ce; border-bottom: 0; border-radius: 4px 4px 0 0; }

.player-shell { overflow: hidden; border: 1px solid #30313d; border-radius: 9px; background: #000; }
.player-shell video { display: block; width: 100%; max-height: 75vh; aspect-ratio: 16 / 9; background: #000; }
.video-information { margin: 1.35rem 0 2.4rem; }
.video-heading { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.video-heading h1 { font-size: clamp(1.4rem, 2.7vw, 2rem); line-height: 1.2; letter-spacing: -.035em; margin: 0 0 .45rem; }
.video-metadata { display: flex; flex-wrap: wrap; gap: .4rem; color: var(--text-muted); font-size: .85rem; margin: 0; }
.video-metadata span[aria-hidden] { color: #676877; }
.video-actions { display: flex; gap: .45rem; align-items: start; flex: 0 0 auto; }
.video-description { max-width: 58rem; margin-top: 1.45rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }
.video-description h2 { font-size: .94rem; margin-bottom: .4rem; }
.video-description p { color: #cbcbd5; margin: 0; line-height: 1.65; }
.related-section { margin-top: 2.3rem; }
.action-menu { position: relative; }
.action-menu > summary { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 7px; background: #282a34; color: var(--text); font-size: 1.35rem; line-height: 1; cursor: pointer; list-style: none; }
.action-menu > summary::-webkit-details-marker, .category-edit > summary::-webkit-details-marker { display: none; }
.action-menu > summary:hover, .action-menu[open] > summary { background: var(--surface-hover); }
.action-menu-panel { position: absolute; z-index: 10; right: 0; top: calc(100% + .35rem); min-width: 165px; padding: .3rem; border: 1px solid var(--border); border-radius: 7px; background: #262831; box-shadow: 0 10px 24px #0005; }
.action-menu-panel form { margin: 0; }
.menu-danger { width: 100%; padding: .55rem .65rem; border: 0; border-radius: 5px; background: transparent; color: #ffb5bf; text-align: left; font-size: .86rem; }
.menu-danger:hover:not(:disabled) { background: #703540; color: white; }

.form-panel { max-width: 740px; padding: clamp(1.3rem, 3vw, 2rem); }
.upload-zone { display: grid; place-items: center; gap: .3rem; padding: 1.65rem 1rem 1.2rem; border: 1px dashed #66617d; border-radius: 8px; background: #1d1e29; text-align: center; color: var(--text-muted); transition: border-color .16s, background-color .16s; }
.upload-zone strong { color: var(--text); font-size: .96rem; }
.upload-zone.is-dragover { border-color: var(--accent); background: #292537; }
.upload-symbol { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #3a3356; color: #d4c8ff; font-size: 1.35rem; font-weight: 700; margin-bottom: .35rem; }
.upload-zone input[type="file"] { width: min(100%, 380px); padding: .35rem; margin-top: .45rem; background: #151720; border: 1px solid #51505f; color: transparent; }
.upload-zone input[type="file"]::file-selector-button { margin-right: .75rem; padding: .45rem .65rem; border: 0; border-radius: 5px; background: #413866; color: #fff; cursor: pointer; }
.selected-file { min-height: 1.2em; margin: .2rem 0 0; color: #d1c5ff; font-size: .82rem; overflow-wrap: anywhere; }

.category-create { display: grid; grid-template-columns: minmax(180px, .65fr) minmax(320px, 1.35fr); align-items: end; gap: 1rem; padding: 1.3rem 1.5rem; margin-bottom: 2rem; }
.category-create h2 { font-size: 1.1rem; margin: 0 0 .2rem; }
.category-create p { color: var(--text-muted); font-size: .83rem; margin: 0; }
.category-create form { display: flex; align-items: end; gap: .65rem; }
.category-create form .field { flex: 1; }
.category-list { display: grid; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.category-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: .6rem; min-height: 74px; padding: .85rem 1rem; position: relative; }
.category-item + .category-item { border-top: 1px solid var(--border); }
.category-item-main h3 { font-size: .94rem; margin: 0 .5rem .1rem 0; overflow-wrap: anywhere; }
.category-item-main p { font-size: .79rem; color: var(--text-muted); margin: 0; }
.category-edit > summary { list-style: none; cursor: pointer; }
.category-edit-form { position: absolute; z-index: 9; right: 3.6rem; top: calc(100% - .35rem); display: grid; gap: .65rem; width: min(330px, calc(100vw - 3rem)); padding: 1rem; box-shadow: 0 12px 30px #0006; }
.category-edit-form .button { justify-self: start; }

@media (max-width: 900px) {
  .app-header-inner { gap: 1rem; padding: 0 1.25rem; }
  .container { padding: 1.5rem 1.25rem 4rem; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); }
}

@media (max-width: 700px) {
  .app-header-inner { min-height: 0; flex-wrap: wrap; justify-content: space-between; padding: .5rem 1rem; gap: .4rem .8rem; }
  .primary-nav { order: 1; width: auto; gap: .2rem; }
  .header-actions { order: 2; }
  .header-actions .button { min-height: 32px; padding: .4rem .55rem; font-size: .77rem; }
  .primary-nav a { min-height: 40px; padding: .5rem .8rem; }
  .container { padding: 1.2rem 1rem 3rem; }
  .library-toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .toolbar-search { grid-column: 1 / -1; }
  .toolbar-category { grid-column: 1; }
  .toolbar-clear { grid-column: 1 / -1; justify-self: start; }
  .video-heading { flex-wrap: wrap; }
  .category-create { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .header-actions { gap: .1rem; }
  .header-actions .button { padding: .38rem .45rem; }
  .video-grid { grid-template-columns: 1fr; }
  .media-row .video-card { flex-basis: min(76vw, 280px); }
  .library-toolbar { grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
  .toolbar-submit { padding: .55rem .7rem; }
  .category-create form { align-items: stretch; flex-direction: column; }
  .category-create form .button { width: 100%; }
  .category-item { padding: .8rem; }
  .category-edit-form { right: .7rem; }
  .auth-card { padding: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
