:root {
  /* Harbour: steel and navy blues on cool greys */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #e9eef5;
  --text: #16202e;
  --muted: #5b6677;
  --border: #d6dde7;
  --accent: #1d4f91;
  --accent-text: #f5f7fa;
  --link: #245ea8;
  --danger: #b0302a;
  --ok: #1f6b4a;
  --ok-bg: #e2efe9;
  --warn: #85560f;
  --warn-bg: #f3ece0;
  --radius: 10px;
  --wordmark-palette: --harbour-light;
  --wordmark-scan: 50; /* closed-up scanlines read solid on light grounds */
  --shadow: 0 1px 2px rgb(22 32 46 / 6%), 0 4px 16px rgb(22 32 46 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1520;
    --surface: #151e2c;
    --surface-2: #1f2a3b;
    --text: #e7ecf3;
    --muted: #95a3b7;
    --border: #26344a;
    --accent: #8db6ea;
    --accent-text: #0e1520;
    --link: #9cc2f2;
    --danger: #f08a7e;
    --ok: #7fd1a8;
    --ok-bg: #1c3a33;
    --warn: #e6b45c;
    --warn-bg: #3a3322;
    --wordmark-palette: --harbour-dark;
    --wordmark-scan: 0;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

/* Wordmark font, subset to the letters of "JWeb Files" (SIL OFL, see sixtyfour-OFL.txt). */
@font-face {
  font-family: "Sixtyfour Convergence";
  src: url("sixtyfour-convergence.woff2") format("woff2");
  font-display: block;
}

/* Recolour the wordmark's red CRT layers: 0-1 are the glyph, 2-5 the offset fringes. */
@font-palette-values --harbour-light {
  font-family: "Sixtyfour Convergence";
  override-colors: 0 #245ea8, 1 #245ea8, 2 rgb(0 170 190 / 25%), 3 rgb(0 170 190 / 60%), 4 rgb(200 60 90 / 25%), 5 rgb(200 60 90 / 55%);
}
@font-palette-values --harbour-dark {
  font-family: "Sixtyfour Convergence";
  override-colors: 0 #86b8f2, 1 #86b8f2, 2 rgb(80 230 240 / 13%), 3 rgb(80 230 240 / 45%), 4 rgb(255 110 140 / 13%), 5 rgb(255 110 140 / 40%);
}

* { box-sizing: border-box; }

/* Feel like an app: no rubber-band/pull-to-refresh shift, no double-tap zoom. */
html {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

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

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 0.6rem; font-weight: 650; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }

/* --- header --- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--text); }
.wordmark { font-family: "Sixtyfour Convergence", monospace; font-weight: 400; line-height: 1; white-space: nowrap; color: var(--link); font-palette: var(--wordmark-palette); font-variation-settings: "SCAN" var(--wordmark-scan); }
.brand .wordmark { font-size: 17px; }
.brand:hover { text-decoration: none; }
.top nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.top nav a:hover { background: var(--surface-2); text-decoration: none; }
.top nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }
.logout { margin: 0; }
.disk { color: var(--muted); font-size: 0.85rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.disk.low { color: var(--danger); font-weight: 600; }
button.plain { background: none; border: 0; color: var(--muted); padding: 6px; font: inherit; cursor: pointer; }

@media (max-width: 560px) {
  /* Two rows on phones: wordmark, free space and log out, then the menu full width. */
  .top { flex-wrap: wrap; gap: 4px 6px; padding: 8px 8px 6px; }
  .brand { padding-left: 4px; }
  .brand .wordmark { font-size: 15px; }
  .top nav { order: 3; flex-basis: 100%; }
  .logout, .disk { margin-left: auto; }
  .disk + .logout { margin-left: 0; }
}

/* --- buttons and forms --- */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.6; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); }
.small { padding: 5px 10px; font-size: 0.9rem; }
.big { padding: 12px 22px; font-size: 1.05rem; }
.wide { width: 100%; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label[hidden] { display: none; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.inline { display: flex; gap: 6px; }
.inline select { width: auto; }

.error { color: var(--danger); margin: 0; }
.error[hidden] { display: none; }
.empty { color: var(--muted); padding: 24px 0; }
.note { color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.meta { color: var(--muted); font-size: 0.85rem; }
.mono { font-family: ui-monospace, monospace; font-size: 0.85rem; color: var(--muted); word-break: break-all; }

/* --- page structure --- */

.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.tools { display: flex; gap: 6px; flex-wrap: wrap; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 1.05rem; min-width: 0; }
.crumbs a:last-child { color: var(--text); font-weight: 600; }
.crumbs span { color: var(--muted); }

.center { display: flex; justify-content: center; padding-top: 6vh; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow);
}
.panel.narrow { max-width: 400px; }
.panel h1 { display: flex; align-items: center; gap: 8px; }
.panel h1.logo { justify-content: center; margin-bottom: 4px; }
.panel h1.logo .wordmark { font-size: clamp(18px, 7.5vw, 30px); }
.panel h1.logo + h2 { margin: 0; text-align: center; }
.panel p { margin: 0; }
main > .panel { margin-top: 24px; }

/* --- file lists --- */

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.entries li { display: flex; align-items: center; gap: 8px; padding-right: 10px; border-top: 1px solid var(--border); }
.entries li:first-child { border-top: 0; }
.entry {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  padding: 8px 12px;
  flex: 1;
  min-width: 0;
  color: var(--text);
}
.entries li:hover:not(:has(button:hover, .button:hover)) { background: var(--surface-2); }
.entry:hover { text-decoration: none; }
.entry .thumb { grid-row: 1 / 3; }
.entry .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.entry .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--muted);
}
.thumb .icon { width: 22px; height: 22px; }
.thumb-video { position: relative; overflow: hidden; }
.thumb-video img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-video:has(img)::after { /* play marker over the frame */
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent #fff;
  filter: drop-shadow(0 0 2px rgb(0 0 0 / 70%));
}
.thumb .icon-dir { color: var(--link); }
.shared { color: var(--link); }

@media (max-width: 560px) {
  .entries li button span, .entries li .button span { display: none; }
}

/* --- previews --- */

.preview { margin: 12px 0; display: flex; justify-content: center; }
.preview img, .preview video {
  max-width: 100%;
  max-height: 72vh;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.preview video {
  /* 16:9 frame, shrunk to fit the viewport height; other ratios letterbox */
  width: min(100%, calc(72vh * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
}
.preview audio { width: 100%; }

/* --- Plyr video and audio players, in Harbour colours --- */

/* The controls always sit on video, so they use the dark palette in both themes. */
.preview .plyr {
  --plyr-color-main: #8db6ea;                 /* steel blue: progress, volume, hovered controls */
  --plyr-video-control-color: #fff;
  --plyr-video-control-color-hover: #0e1520;
  --plyr-video-controls-background: linear-gradient(#0000, rgb(14 21 32 / 80%));
  --plyr-range-thumb-background: #e7ecf3;
  --plyr-focus-visible-color: #9cc2f2;
  --plyr-font-family: inherit;
  --plyr-control-radius: 6px;
  --plyr-menu-background: rgb(21 30 44 / 96%);
  --plyr-menu-color: #e7ecf3;
  --plyr-menu-arrow-color: #8db6ea;
  --plyr-menu-back-border-color: #26344a;
  --plyr-menu-back-border-shadow-color: #0000;
  --plyr-tooltip-background: #151e2c;
  --plyr-tooltip-color: #e7ecf3;
  --plyr-video-background: #000;
  width: min(100%, calc(72vh * 16 / 9));
  border-radius: var(--radius);
}
/* ...but not in fullscreen, where it must fill the screen. Separate rules, as an
   unknown pseudo-class would void the whole list in some browsers. */
.preview .plyr:fullscreen { width: 100%; border-radius: 0; }
.preview .plyr:-webkit-full-screen { width: 100%; border-radius: 0; }
.preview .plyr--fullscreen-fallback { width: 100%; border-radius: 0; }
.preview .plyr video { width: 100%; height: 100%; max-height: none; border-radius: 0; aspect-ratio: auto; } /* undo the no-JS sizing above */
.preview .plyr button { font-weight: inherit; gap: 0; white-space: normal; } /* undo app button styles */

/* Audio controls sit on the page, so they follow the light/dark theme. */
.preview .plyr--audio {
  --plyr-color-main: var(--accent);
  --plyr-audio-controls-background: var(--surface);
  --plyr-audio-control-color: var(--text);
  --plyr-audio-control-color-hover: var(--accent-text);
  --plyr-audio-progress-buffered-background: color-mix(in srgb, var(--muted) 30%, transparent);
  --plyr-audio-range-track-background: color-mix(in srgb, var(--muted) 30%, transparent);
  --plyr-range-thumb-background: var(--surface);
  --plyr-focus-visible-color: var(--link);
  --plyr-tooltip-background: var(--surface-2);
  --plyr-tooltip-color: var(--text);
  width: 100%;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Big play button: translucent with a white ring, blue on hover. */
.preview .plyr__control--overlaid {
  padding: 20px;
  border: 2px solid rgb(255 255 255 / 85%);
  background: rgb(0 0 0 / 55%);
  box-shadow: 0 2px 12px rgb(0 0 0 / 35%);
}
.preview .plyr__control--overlaid svg { width: 32px; height: 32px; }
.preview .plyr__control--overlaid:hover { background: #8db6ea; border-color: #8db6ea; color: #0e1520; }

/* While a playing video loads or buffers, the big button comes back as a spinner. */
.preview .plyr--playing.plyr--loading .plyr__control--overlaid { opacity: 1; visibility: visible; pointer-events: none; }
.preview .plyr--playing.plyr--loading .plyr__control--overlaid svg { visibility: hidden; }
.preview .plyr--playing.plyr--loading .plyr__control--overlaid::after {
  content: "";
  position: absolute;
  inset: 16px;
  border: 3px solid rgb(255 255 255 / 30%);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .preview .plyr--playing.plyr--loading .plyr__control--overlaid::after { animation-duration: 2.4s; }
}
.nopreview {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 48px; color: var(--muted); background: var(--surface); border-radius: var(--radius); width: 100%;
}
.nopreview .icon { width: 48px; height: 48px; }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }

/* --- share and upload link cards --- */

.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.inactive { background: var(--bg); border-style: dashed; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.subject { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; margin: 0; color: var(--text); }
.subject span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cardnote { margin: 0; color: var(--muted); font-style: italic; }
.cardactions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.cardactions form { margin: 0; }

.copyrow { display: flex; gap: 6px; }
.copyrow input { font-family: ui-monospace, monospace; font-size: 0.85rem; }

.facts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 0.85rem; }

.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-active { color: var(--ok); background: var(--ok-bg); }
.badge-missing { color: var(--warn); background: var(--warn-bg); }
.badge-revoked, .badge-expired, .badge-full { color: var(--muted); }

/* --- activity log --- */

.log { list-style: none; padding: 0; margin: 0; }
.log li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.log .action { font-weight: 600; }
.log .action[data-action="bad password"], .log .action[data-action="rejected"] { color: var(--danger); }
.log .detail { word-break: break-all; }
.log .meta { flex-basis: 100%; }

/* --- dialog --- */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.dialog h2 { margin: 0; }
.center .dialog { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 480px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* --- public pages --- */

/* Logo above share, upload and error pages (login and setup show it large instead). */
.public-top { display: flex; justify-content: center; padding: 20px 16px 0; }
.public-top .wordmark { font-size: clamp(16px, 6vw, 24px); }

body.public main { max-width: 760px; }
.sharepage { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding-top: 12px; }
.sharepage > .button.big { align-self: center; }
.sharepage > .meta { text-align: center; margin: 0; }
.sharepage > .filename { display: block; text-align: center; word-break: normal; overflow-wrap: anywhere; }
.sharepage > .filename .icon { margin-right: 6px; }
@media (max-width: 560px) { .sharepage > .filename { font-size: 1.1rem; } }
.filename { display: flex; align-items: center; gap: 8px; word-break: break-word; }
.sharepage .pagehead { margin: 0; }

.drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  position: relative;
}
.drop.over { border-color: var(--link); color: var(--link); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.progress { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.progress:empty { display: none; }
.progress li { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.progress .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress progress { flex-basis: 100%; width: 100%; height: 6px; }
.progress .ok .meta { color: var(--ok); }
.progress .failed .meta { color: var(--danger); }
