:root {
  color-scheme: light dark;
  font: 16px/1.5 system-ui, sans-serif;
  --surface: light-dark(#fff, #1b2538);
  --background: light-dark(#f3f6fa, #101827);
  --text: light-dark(#172237, #eef3fc);
  --muted: light-dark(#485c76, #b3c1d8);
  --line: light-dark(#d8e1ee, #36445b);
  --accent: light-dark(#174b99, #9ec4ff);
  --selected: light-dark(#e4eefc, #243a5b);
  --nav-height: 0px;
  --player-height: 0px;
}
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--text); overflow-wrap: anywhere; }
main { width: min(73rem, calc(100% - 2rem)); margin: 0 auto; padding-bottom: calc(var(--player-height) + var(--nav-height) + 1.25rem); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1rem; overflow-wrap: anywhere; }
nav { display: flex; flex-wrap: wrap; gap: .5rem; }
button { font: inherit; text-align: left; padding: .5rem .75rem; min-height: 44px; cursor: pointer; overflow-wrap: anywhere; }
button[aria-current] { font-weight: 700; }
button { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: .55rem; }
button:hover { background: var(--selected); }
button:disabled { opacity: .55; cursor: default; }
:where(button, summary, input, select, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
ul { padding: 0; list-style: none; }
li button { width: 100%; border: 0; border-bottom: 1px solid color-mix(in srgb, CanvasText 22%, Canvas); color: inherit; background: transparent; }
li button:hover { background: color-mix(in srgb, CanvasText 8%, Canvas); }
video { width: 100%; max-height: 50vh; background: black; }
audio { width: 100%; }
form { display: grid; gap: .6rem; justify-items: start; margin: .75rem 0 1.25rem; }
form[hidden] { display: none; }
form h2 { margin: 0; }
label { max-width: 100%; }
input:not([type=checkbox]), select { display: block; box-sizing: border-box; max-width: 100%; margin-top: .2rem; padding: .5rem; font: inherit; }
details { margin: .75rem 0; }
summary { cursor: pointer; padding: .4rem 0; font-weight: 600; }
#users > details { border-top: 1px solid color-mix(in srgb, CanvasText 22%, Canvas); }
.account-bar, .rules li { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.account-bar[hidden] { display: none; }
.rules li button { width: auto; border: 0; }
#search-form { display: flex; flex-wrap: wrap; align-items: end; }
#entries small { display: block; padding: .15rem .75rem .35rem; overflow-wrap: anywhere; }
#index-errors li { margin-top: .35rem; overflow-wrap: anywhere; }
.queue-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
#entries .queue-actions button { width: auto; border: 1px solid ButtonBorder; }
.queue-file-actions { margin: 0 .75rem .4rem; }
.queue-file-actions summary { padding: .2rem 0; font-size: .85rem; }
#queue-items { padding-left: 1.75rem; }
#queue-items li { margin-bottom: .6rem; }
#queue-items small { display: block; overflow-wrap: anywhere; }
#queue-message:empty { display: none; }
#queue-saved li, #recent-list li, #history-list li { margin-bottom: .6rem; }
#queue-saved p { margin: .35rem 0; }
#recent-list small, #history-list small { display: block; overflow-wrap: anywhere; }
#history-message:empty { display: none; }
dialog { max-width: min(28rem, calc(100% - 3rem)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.media-preview { display: block; width: min(9rem, 100%); height: auto; aspect-ratio: 16/9; object-fit: contain; background: black; margin: .5rem .75rem 0; }
.media-preview[hidden] { display: none; }
#diagnostics-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: .4rem 1rem; }
#diagnostics-metrics dt { font-weight: 600; }
#diagnostics-metrics dd { margin: 0 0 .4rem; }
#diagnostics-events li { margin-bottom: .5rem; }

.app-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 0; }
.app-header h1 { margin: 0; font-size: clamp(1.3rem, 3vw, 1.8rem); letter-spacing: -.03em; }
#app-menu { margin: 0; flex: 0 0 auto; }
#app-menu > summary { list-style: none; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--surface); }
#app-menu > summary::-webkit-details-marker { display: none; }
.menu-popup { position: absolute; z-index: 20; right: 0; top: calc(100% - .4rem); width: min(23rem, 100%); box-sizing: border-box; padding: .7rem; border-radius: .8rem; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 8px 24px #0003; }
.app-header { position: relative; z-index: 15; }
#app-nav { display: grid; gap: .25rem; }
#app-nav button { text-align: left; border-color: transparent; background: transparent; }
#app-nav button[aria-current] { background: var(--selected); color: var(--accent); }
#nav-queue-count { font-size: .78rem; margin-left: .15rem; }
#workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
body[data-view="library"] main { display: flex; flex-direction: column; box-sizing: border-box; height: 100dvh; }
body[data-view="library"] #workspace { flex: 1 1 auto; min-height: 0; align-items: stretch; }
body[data-view="library"] #queue-view { overflow-y: auto; min-height: 0; }
#library { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#directory-list { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
#directory-list:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#selection-tools { flex: 0 0 auto; margin-block: .3rem; }
#selection-tools button { min-height: 40px; }
#selection-count { color: var(--muted); }
#selection-message { margin: .2rem 0; }
#selection-message:empty { display: none; }
#library-tools { flex: 0 0 auto; max-height: min(27dvh, 14rem); overflow-y: auto; }
#library, #queue-view, #account, #signin, #history-view { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: .9rem; padding: clamp(.75rem, 2vw, 1.4rem); }
#signin, #account, #history-view { width: min(100%, 48rem); box-sizing: border-box; }
body.app-ready:not([data-view="account"]) #account,
body[data-view="account"] #workspace,
body[data-view="recent"] #workspace, body[data-view="recent"] #history-panel,
body[data-view="history"] #workspace, body[data-view="history"] #recent-media,
body[data-view="queue"] #library { display: none; }
#account-message:empty, #playback-error:empty, #sleep-message:empty, #status:empty, #player-position:empty { display: none; }
#account-message { overflow-wrap: anywhere; }
#search-form { display: flex; flex-wrap: nowrap; gap: .55rem; margin-top: 0; }
#search-form label { flex: 1; min-width: 0; font-weight: 600; }
#search-form input { width: 100%; min-width: 0; }
#search-form > button { flex: 0 0 auto; background: var(--selected); color: var(--accent); font-weight: 650; }
#path { flex: 0 0 auto; display: flex; flex-wrap: nowrap; align-items: center; gap: .5rem; min-height: 44px; min-width: 0; margin: 0; padding-bottom: .35rem; }
#path button { flex: 0 0 auto; background: var(--selected); color: var(--accent); }
#path span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
#folder-view { display: flex; align-items: center; gap: .55rem; margin-top: .6rem; color: var(--muted); }
#folder-view select { margin: 0; }
#entries { margin: .55rem 0 0; }
#entries > li { display: grid; grid-template-columns: minmax(0, 1fr); align-items: center; border-top: 1px solid var(--line); padding: .25rem 0; }
#entries > li:has(.media-preview:not([hidden])) { grid-template-columns: minmax(4.35rem, 8rem) minmax(0, 1fr); column-gap: .65rem; }
#entries > li > .media-preview { grid-row: span 3; margin: 0; width: 100%; border-radius: .5rem; }
#entries > li > button { border: 0; font-weight: 630; }
#entries .select-file { grid-column: -2 / -1; width: fit-content; padding: .45rem .55rem; cursor: pointer; }
#entries .select-file input { vertical-align: middle; margin: 0; width: 1.3rem; height: 1.3rem; }
#entries small, #queue-items small, #recent-list small, #history-list small { color: var(--muted); }
#entries .queue-file-actions { margin: 0 .55rem .2rem; }
#entries .queue-file-actions summary { color: var(--accent); font-size: 1.15rem; min-height: 34px; box-sizing: border-box; width: fit-content; padding: .1rem .35rem; }
.icon-action { min-width: 44px; text-align: center; font-weight: 700; font-size: 1.12rem; }
#queue-view { grid-row: 1; }
#queue-panel { margin: 0; }
#queue-items > li { border-bottom: 1px solid var(--line); padding-bottom: .65rem; }
#queue-items > li > button { border: 0; font-weight: 620; padding-left: 0; }
#queue-items .queue-actions button, #queue-saved .queue-actions button { width: auto; border: 1px solid var(--line); }
#queue-items .queue-empty { list-style: none; color: var(--muted); margin-left: -1.5rem; border: 0; }
#queue-message { position: fixed; z-index: 12; bottom: calc(var(--player-height) + var(--nav-height) + .6rem); inset-inline: 1rem; width: fit-content; max-width: calc(100% - 2rem); margin: 0 auto; padding: .4rem .75rem; border: 1px solid var(--line); border-radius: .65rem; background: var(--surface); box-shadow: 0 4px 18px #0002; pointer-events: none; }
#player { position: fixed; z-index: 10; inset-inline: 0; bottom: var(--nav-height); max-width: 73rem; box-sizing: border-box; margin-inline: auto; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: .9rem .9rem 0 0; background: var(--surface); box-shadow: 0 -5px 24px #0002; }
.player-bar { display: flex; align-items: center; gap: .5rem; }
#queue-transport { display: flex; width: fit-content; align-items: center; gap: .25rem; margin: -.15rem .75rem .12rem auto; color: var(--muted); }
#queue-transport button { padding: 0 .4rem; min-width: 44px; min-height: 36px; text-align: center; }
#queue-position { min-width: 2.5rem; text-align: center; font-size: .82rem; font-variant-numeric: tabular-nums; }
#player-toggle { min-width: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: center; border: 0; background: transparent; }
#player-toggle::after { content: '⌃'; grid-column: 2; grid-row: 1 / span 2; color: var(--accent); font-size: 1.15rem; }
#player-toggle[aria-expanded="true"]::after { content: '⌄'; }
#playing { min-width: 0; white-space: normal; overflow-wrap: anywhere; font-weight: 700; }
#player-position { grid-column: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
#player-playpause { flex: 0 0 auto; font-weight: 650; color: var(--accent); background: var(--selected); }
#player-expanded { overflow: auto; max-height: min(34dvh, 26rem); border-top: 1px solid var(--line); padding: .55rem 0 .15rem; }
#player-expanded video { display: block; width: 100%; max-height: min(23dvh, 18rem); border-radius: .5rem; }
#player-pip { flex: 0 0 auto; }
#player-pip[aria-pressed="true"] { color: var(--accent); background: var(--selected); }
#player.player-inline #media { max-width: min(11rem, 55%); margin-left: auto; }
#player.player-inline video { max-height: 16dvh; }
#player.player-inline :is(#player-controls, #video-options, #sleep-panel) { display: none; }
#player-controls, #video-options { margin-top: .5rem; }
#playback-error { margin: .25rem .5rem; }

@media (min-width: 56rem) {
  body[data-view="library"] #workspace { grid-template-columns: minmax(0, 1fr) minmax(17rem, 24rem); }
  body[data-view="library"] #queue-view { grid-column: 2; }
  body[data-view="library"] #library { grid-row: 1; grid-column: 1; }
  body[data-view="queue"] #queue-view { max-width: 50rem; width: 100%; box-sizing: border-box; }
}

@media (max-width: 55.999rem) {
  body.app-ready { --nav-height: env(safe-area-inset-bottom, 0px); }
  body[data-view="library"] #queue-view { display: none; }
  main { width: calc(100% - 1.1rem); }
  .app-header { padding: .65rem .25rem; }
}
