:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #66665f;
  --line: #deded8;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1f1f1d;
    --text: #f1f1ec;
    --muted: #a8a89f;
    --line: #34342f;
    --accent: #7fb0f5;
    --accent-text: #10203a;
  }
}

* { box-sizing: border-box; }

/* Keeps anything scrolled into view clear of the sticky toolbar. */
html { scroll-padding-top: 136px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }

button, select, input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

button { cursor: pointer; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

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

.page { max-width: 1400px; margin: 0 auto; padding: 16px; }

.device-panel {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.device-panel summary {
  min-height: 44px;
  box-sizing: border-box;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.device-panel summary .icon {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  vertical-align: -2px;
}

.device-info {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0 16px 12px;
}

.device-info > div {
  display: grid;
  grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
  column-gap: 16px;
}

.device-info dt { grid-row: span 9; color: var(--muted); }
.device-info dd { grid-column: 2; margin: 0; min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 479px) {
  .device-info > div { grid-template-columns: minmax(0, 1fr); }
  .device-info dt { grid-row: auto; }
  .device-info dd { grid-column: 1; }
}

.signin {
  display: grid;
  gap: 12px;
  max-width: 340px;
  margin: 18vh auto 0;
  padding: 0 16px;
}

.signin h1 { margin: 0; font-size: 24px; }
.signin p { margin: 0; }
.error { color: #c0392b; margin: 0; }

@media (prefers-color-scheme: dark) {
  .error { color: #ff9a8b; }
}

.offline {
  display: grid;
  gap: 12px;
  max-width: 340px;
  margin: 18vh auto 0;
  padding: 0 16px;
  text-align: center;
}

/* Stays hidden briefly so a normal, fast start does not flash it. */
.connecting {
  margin: 18vh auto 0;
  padding: 0 16px;
  color: var(--muted);
  text-align: center;
  opacity: 0;
  animation: connecting-appear 0.2s 0.4s forwards;
}

@keyframes connecting-appear {
  to { opacity: 1; }
}

.offline .icon { justify-self: center; width: 56px; height: 56px; margin-bottom: 4px; color: var(--muted); opacity: 0.55; }
.offline .icon-gap { fill: var(--bg); }
.offline h1 { margin: 0; font-size: 24px; }
.offline-note { margin: 0; color: var(--muted); }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -8px -16px 8px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.toolbar select { flex: 1 1 0; min-width: 0; max-width: 100%; }

.place {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.back {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 12px 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-decoration: none;
}

.back .icon { width: 14px; height: 14px; }
.back:focus-visible { outline-offset: 2px; }

.crumbs {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin: 0;
  overflow-x: auto;
  font-size: inherit;
  font-weight: 600;
  white-space: nowrap;
  scrollbar-width: none;
}

.crumbs::-webkit-scrollbar { display: none; }
.crumbs > * { flex: none; }

.crumbs a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
}

.crumbs a:focus-visible { outline-offset: -3px; }

/* A very long current folder name is cut short instead of filling the bar. */
.crumbs > a:last-child {
  display: block;
  max-width: 100%;
  overflow: hidden;
  line-height: 44px;
  text-overflow: ellipsis;
}

.crumbs span { color: var(--muted); }
.spacer { flex: 1; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
  html { scroll-padding-top: 76px; }
  .crumbs, .place { flex: 1 1 0; }
  .toolbar select { flex: none; }
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  text-decoration: none;
}

.thumb {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--line);
  color: var(--muted);
  font-size: 13px;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.folder { font-size: 40px; }

.tile .note {
  display: block;
  padding: 0 8px 6px;
  font-size: 12px;
  opacity: 0.6;
}

.name {
  padding: 6px 8px;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-folder {
  padding: 0 8px 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-note { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.play {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgb(0 0 0 / 70%);
  color: #fff;
  font-size: 12px;
}

.message { max-width: 560px; margin: 48px auto; color: var(--muted); text-align: center; }
.sentinel { height: 1px; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  background: #000;
  color: #fff;
}

.viewer-bar {
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) minmax(0, auto) minmax(max-content, 1fr);
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 8px 8px;
}

.viewer-bar > button { justify-self: start; }

.viewer-actions {
  display: flex;
  justify-self: end;
  gap: 8px;
}

.viewer-bar button, .viewer-bar a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #555;
  border-radius: 8px;
  background: #222;
  color: #fff;
  text-decoration: none;
}

.viewer-bar button:disabled { opacity: 0.4; }
.icon { width: 20px; height: 20px; }

.viewer-title {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-stage {
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 env(safe-area-inset-bottom);
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x pinch-zoom;
}

.viewer-stage::-webkit-scrollbar { display: none; }

.viewer-track {
  position: relative;
  width: calc(var(--count) * 100%);
  height: 100%;
}

.viewer-slide {
  position: absolute;
  inset-block: 0;
  left: calc(100% / var(--count) * var(--index));
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: calc(100% / var(--count));
  overflow: hidden;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}

.viewer-slide > * { grid-area: 1 / 1; }
.viewer-slide img, .viewer-slide video { max-width: 100%; max-height: 100%; }
.viewer-slide .viewer-thumb { width: 100%; height: 100%; object-fit: contain; }
.viewer-slide .viewer-thumb.soft { filter: blur(8px); }
.viewer-thumb-label { color: #aaa; }

.viewer-note { display: grid; gap: 12px; justify-items: center; padding: 16px; text-align: center; }
.viewer-note a { color: #fff; }
.viewer-preparing {
  align-self: center; justify-self: center; max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 8px; background: rgba(0, 0, 0, 0.7); color: #fff; text-align: center;
}

body.viewing { overflow: hidden; }

[hidden] { display: none !important; }

/* The owner's Sharing page and the bar shown while choosing a folder to share. */
.sharing { max-width: 640px; }
.sharing label { display: grid; gap: 4px; margin-bottom: 8px; }
.sharing .person, .sharing form { display: grid; gap: 8px; margin: 0 0 16px; }
.sharing .person { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sharing .summary { display: grid; gap: 2px; }
.sharing .folders, .sharing .help, .sharing .note, .sharing .copy-block p { margin: 0; color: var(--muted); font-size: 13px; }
.sharing .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sharing .actions.confirm span { flex: 1 1 100%; }
.sharing .folder-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.sharing .folder { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.sharing .folder .note { grid-column: 1 / -1; color: #c0392b; }
.sharing .invite-link { width: 100%; box-sizing: border-box; }
.pick-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.pick-bar span { flex: 1 1 auto; font-weight: 600; }
.share-sheet {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.share-sheet h2 { margin: 0; font-size: 16px; }
.share-sheet .share-person { display: flex; align-items: center; gap: 8px; }
.share-sheet .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-sheet .error { margin: 0; color: #c0392b; }
