/* iPhone look. Every rule starts with .ios, so other devices keep app.css as it is. */
.ios {
  --ios-bg: #ffffff;
  --ios-grouped: #f2f2f7;
  --ios-cell: #ffffff;
  --ios-label: #000000;
  --ios-secondary: rgba(60, 60, 67, 0.6);
  --ios-separator: rgba(60, 60, 67, 0.29);
  --ios-blue: #007aff;
  --ios-red: #ff3b30;
  --ios-bar: rgba(249, 249, 249, 0.94);
}

@media (prefers-color-scheme: dark) {
  .ios {
    --ios-bg: #000000;
    --ios-grouped: #000000;
    --ios-cell: #1c1c1e;
    --ios-label: #ffffff;
    --ios-secondary: rgba(235, 235, 245, 0.6);
    --ios-separator: rgba(84, 84, 88, 0.65);
    --ios-blue: #0a84ff;
    --ios-red: #ff453a;
    --ios-bar: rgba(29, 29, 31, 0.94);
  }
}

/* Browse and Computer screens sit on the grouped background, with cells on top. */
.ios body:has(#app > .page) {
  background: var(--ios-grouped);
}

/* Pages without a nav bar keep clear of the status bar, which gets a backdrop
   so content scrolled under it isn't see-through. */
.ios :is(#app, .nav-layer) > .page:first-child {
  padding-top: max(16px, env(safe-area-inset-top));
}

.ios #app::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  height: env(safe-area-inset-top);
  background: var(--ios-bar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

/* Dynamic Type: follows the text size set in iPhone settings. */
.ios body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, sans-serif;
  font: -apple-system-body;
  -webkit-tap-highlight-color: transparent;
}

.ios .page {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* Room for the tab bar, which sits over the bottom of the page. */
.ios .page {
  padding-bottom: calc(49px + 16px + env(safe-area-inset-bottom));
}

.ios .tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border-top: 0.5px solid var(--ios-separator);
  background: var(--ios-bar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.ios .tab-bar .tab {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 49px;
  color: var(--ios-secondary);
  font-size: 0.75em;
  font-weight: 500;
  text-decoration: none;
}

.ios .tab-bar .tab[aria-current="page"] {
  color: var(--ios-blue);
}

.ios body.viewing .tab-bar {
  display: none;
}

.ios .large-title {
  margin: 8px 0 16px;
  color: var(--ios-label);
  font-size: 2.1em;
  font-weight: 700;
  line-height: 1.2;
}

/* Inset grouped lists. */
.ios .list-header {
  margin: 24px 16px 6px;
  color: var(--ios-secondary);
  font-size: 0.8em;
  font-weight: 400;
  text-transform: uppercase;
}

.ios .list-group {
  margin-bottom: 24px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--ios-cell);
}

.ios .list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 16px;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ios-label);
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.ios .list-row + .list-row {
  box-shadow: inset 0 0.5px 0 var(--ios-separator);
}

.ios a.list-row:active,
.ios button.list-row:active {
  opacity: 0.6;
}

.ios .list-row.destructive {
  justify-content: center;
  color: var(--ios-red);
}

.ios .list-label,
.ios .list-detail {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ios .list-label {
  flex: 1 1 auto;
}

.ios .list-row.destructive .list-label {
  flex: 0 1 auto;
}

.ios .list-detail {
  flex: 0 1 auto;
  color: var(--ios-secondary);
}

.ios .list-row > .icon {
  flex: none;
  width: 1.35em;
  height: 1.35em;
  color: var(--ios-blue);
}

.ios .list-chevron {
  display: flex;
  flex: none;
  color: var(--ios-secondary);
  opacity: 0.6;
}

.ios .list-chevron .icon {
  width: 0.55em;
  height: 0.9em;
}

.ios .computer .message {
  color: var(--ios-secondary);
}

/* Navigation bar: a blue back button, a small title that shows once the large title has scrolled under it, and actions. */
.ios .nav-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  /* The title takes only the room it needs, so the back label can use the rest. */
  grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--ios-bar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.ios .nav-bar.collapsed {
  box-shadow: 0 0.5px 0 var(--ios-separator);
}

.ios .nav-leading,
.ios .nav-trailing {
  display: flex;
  min-width: 0;
}

.ios .nav-trailing {
  justify-content: flex-end;
}

.ios .nav-back,
.ios .nav-button {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0 8px 0 0;
  border: 0;
  background: none;
  color: var(--ios-blue);
  font: inherit;
  text-decoration: none;
}

.ios .nav-button {
  justify-content: flex-end;
  padding: 0 8px;
}

/* The label sits in its own span, because text-overflow does nothing on bare text in a flex box. */
.ios .nav-back-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ios .nav-back .icon {
  flex: none;
  width: 0.75em;
  height: 1.1em;
}

.ios .nav-back:active,
.ios .nav-button:active {
  opacity: 0.4;
}

.ios .nav-title {
  max-width: 40vw;
  overflow: hidden;
  color: var(--ios-label);
  font-weight: 600;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
}

.ios .nav-bar.collapsed .nav-title {
  opacity: 1;
}

.ios .large-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The Sort menu. */
.ios .sort-menu {
  position: relative;
}

.ios .menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 6;
  min-width: 200px;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  border-radius: 12px;
  background: var(--ios-cell);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.ios .menu[hidden] {
  display: none;
}

.ios .menu [role="menuitemradio"] {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  margin: 0;
  position: relative;
  padding: 0 16px 0 36px;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ios-label);
  font: inherit;
  text-align: left;
}

.ios .menu [role="menuitemradio"] + [role="menuitemradio"] {
  box-shadow: inset 0 0.5px 0 var(--ios-separator);
}

.ios .menu [aria-checked="true"]::before {
  content: "\2713";
  position: absolute;
  left: 14px;
  font-weight: 600;
}

.ios .menu [role="menuitemradio"]:active {
  background: var(--ios-separator);
}

/* Folder screen: the Show choice, then subfolders, then an edge-to-edge grid of square thumbnails. */
.ios .filter-controls {
  margin-bottom: 16px;
}

.ios .segmented {
  display: flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--ios-separator);
}

.ios .segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--ios-label);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ios .segmented button[aria-checked='true'] {
  background: var(--ios-cell);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ios .filter-controls .list-group {
  margin-top: 12px;
}

.ios .switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.ios .switch-row input[role='switch'] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  /* Undo the app-wide input rule: its 44px min-height and border would stretch the track. */
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--ios-separator);
  transition: background 0.2s;
}

.ios .switch-row input[role='switch']::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}

.ios .switch-row input[role='switch']:checked {
  background: #34c759;
}

.ios .switch-row input[role='switch']:checked::after {
  transform: translateX(20px);
}

.ios .folder-screen .grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  margin-left: calc(-1 * max(16px, env(safe-area-inset-left)));
  margin-right: calc(-1 * max(16px, env(safe-area-inset-right)));
}

.ios .folder-screen .tile {
  border: 0;
  border-radius: 0;
  background: var(--ios-grouped);
}

.ios .folder-screen .tile .name,
.ios .folder-screen .tile .tile-folder {
  display: none;
}

.ios .folder-screen .tile .play {
  top: auto;
  right: 4px;
  bottom: 4px;
  padding: 0;
  background: none;
  font-size: 0.7em;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}

.ios .folder-screen .message,
.ios .folder-screen .scan-note {
  color: var(--ios-secondary);
}

/* The viewer: black, with floating controls over the photo that a tap hides. */
.ios .viewer {
  grid-template-rows: minmax(0, 1fr);
  /* A swipe down fades the black, showing the folder behind. */
  background: rgb(0 0 0 / calc(1 - var(--viewer-fade, 0)));
}

/* A swipe down that is let go too soon springs back. */
.ios .viewer.springing {
  transition: background-color 200ms;
}

.ios .viewer.springing .viewer-slide.current {
  transition: transform 200ms;
}

.ios .viewer-bar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  background: linear-gradient(rgb(0 0 0 / 70%), transparent);
  transition: opacity 200ms;
}

.ios .viewer.controls-hidden .viewer-bar {
  opacity: 0;
  pointer-events: none;
}

.ios .viewer-bar button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 15%);
}

.ios .viewer-title {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ios .viewer-title > * {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ios .viewer-date {
  color: rgb(255 255 255 / 70%);
  font-size: 0.8em;
}

.ios .viewer-slide.video {
  /* The bar's measured height, which already includes the safe area. */
  padding-top: var(--viewer-bar-height, calc(env(safe-area-inset-top) + 64px));
}

.ios .viewer .share {
  position: relative;
}

/* While Share copies the file, a ring fills with the progress, or spins when the size is unknown,
   around a stop square that cancels. */
.ios .viewer-bar .share.busy::before {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--ios-blue) calc(var(--progress, 0) * 1turn), rgb(255 255 255 / 25%) 0);
  content: '';
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}

.ios .viewer-bar .share.busy.unknown::before {
  background: conic-gradient(var(--ios-blue) 0.25turn, rgb(255 255 255 / 25%) 0);
  animation: share-spin 1s linear infinite;
}

.ios .viewer-bar .share.busy .icon {
  visibility: hidden;
}

.ios .viewer-bar .share.busy::after {
  position: absolute;
  inset: calc(50% - 6px);
  border-radius: 2px;
  background: #fff;
  content: '';
}

/* The copy has arrived, and a tap opens the share sheet. */
.ios .viewer-bar .share.ready {
  background: var(--ios-blue);
}

@keyframes share-spin {
  to {
    transform: rotate(1turn);
  }
}

/* Share in place of Download, for files the viewer can't show. */
.ios .viewer-note .share {
  min-width: 88px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 22px;
  background: rgb(255 255 255 / 15%);
  color: #fff;
  font: inherit;
}

.ios .viewer-note .share.busy {
  background: linear-gradient(90deg, var(--ios-blue) calc(var(--progress, 0) * 100%), rgb(255 255 255 / 15%) 0);
}

.ios .viewer-note .share.ready {
  background: var(--ios-blue);
}

.ios .viewer-toast {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  z-index: 2;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgb(40 40 40 / 92%);
  color: #fff;
  text-align: center;
  pointer-events: none;
  transition: opacity 200ms;
}

.ios .viewer-toast:empty {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .ios .viewer-bar .share.busy.unknown::before {
    animation-duration: 4s;
  }

  .ios .viewer-bar,
  .ios .viewer-toast,
  .ios .viewer.springing,
  .ios .viewer.springing .viewer-slide.current {
    transition: none;
  }
}

/* Folder slides: both screens sit in layers on a clipped stage while they move, under the tab bar and status bar. */
.ios .nav-stage {
  position: fixed;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.ios .nav-layer {
  position: absolute;
  inset: 0;
  overflow: hidden auto;
  background: var(--ios-grouped);
  will-change: transform;
}

.ios .nav-layer.over {
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
}

.ios .nav-dim {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
}

/* Sign-in and offline: a large title, a rounded field and a full-width blue button. */
.ios .signin,
.ios .offline {
  max-width: none;
  margin-top: max(18vh, calc(env(safe-area-inset-top) + 48px));
  padding: 0 20px;
  gap: 16px;
}

.ios .signin h1 {
  font-size: 34px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.ios .offline h1 {
  font-size: 22px;
  font-weight: 600;
}

.ios .signin input {
  border: 0;
  border-radius: 12px;
  background: var(--ios-cell);
  color: var(--ios-label);
  min-height: 48px;
  padding: 0 16px;
  font-size: 17px;
}

.ios .signin button.primary,
.ios .offline button.primary {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 12px;
  background: var(--ios-blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}

.ios .signin button.primary:disabled {
  opacity: 0.5;
}

.ios .offline-note {
  color: var(--ios-secondary);
}
.nav-actions { display: flex; align-items: center; gap: 12px; }
.nav-actions .share-button { background: none; border: 0; color: inherit; font: inherit; padding: 0; }
