/* snapdrive — Mini App styling.
 *
 * Two themes, ours, and light is the one it opens on. This reverses what was
 * here before, where every colour came from the client's --tg-theme-*
 * variables: it meant the app had as many appearances as Telegram has themes,
 * and on a desktop client with a custom one the archive came out in colours
 * nobody had ever looked at. A gallery is mostly other people's photographs,
 * and they are judged against the surface behind them, so that surface has to
 * be a decision rather than an inheritance.
 *
 * The viewer still chooses: the switch is in the profile, and the choice is
 * remembered. What is gone is Telegram choosing for them.
 */

:root {
  --bg: #ffffff;
  --bg2: #f1f2f4;
  --text: #0d0f12;
  --hint: #8c8f96;
  --link: #3390ec;
  --accent: #3390ec;
  --accent-fg: #ffffff;
  --sep: rgba(0, 0, 0, .10);
  --tile: #e7e9ec;
  --stripe-a: rgba(0, 0, 0, .045);
  --stripe-b: rgba(0, 0, 0, .10);
  --chrome: rgba(246, 247, 248, .92);
  /* The tab bar's own surface: thinner than --chrome, because the gallery is
   * meant to be visible through it rather than merely implied. */
  --glass: rgba(249, 249, 249, .55);
  /* An elevated surface: alerts, action sheets and the toast sit on it, above
   * the page rather than in it. */
  --elev: rgba(250, 250, 250, .82);
  --fill3: rgba(120, 120, 128, .12);
  --danger: #e0453b;

  --kind-photo: #3390ec;
  --kind-video: #4ec26a;
  --kind-document: #f0a23b;
  --kind-audio: #a274e8;

  /* The insets of a phone with a notch and a home bar. Telegram reports its
   * own on newer clients; env() covers the rest. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --chrome-h: 0px;
  --strip-h: 0px;
  --upbar-h: 0px;
  /* How much of the bottom edge the tab bar owns: six points of breathing
   * room, a row of forty-nine, and whatever the home indicator claims. Every
   * other thing anchored to the bottom is measured from this one number, so a
   * change to the bar cannot leave the button above it overlapping. */
  --tabbar-h: calc(58px + max(var(--safe-bottom), 22px));
}

body[data-theme="dark"] {
  --bg: #0b0b0d;
  --bg2: #16181b;
  --text: #e9eaec;
  --hint: #8b8e95;
  --link: #3b8ff0;
  --accent: #3b8ff0;
  --accent-fg: #ffffff;
  --sep: #212429;
  --tile: #1a1c1f;
  --stripe-a: rgba(255, 255, 255, .028);
  --stripe-b: rgba(255, 255, 255, .075);
  --chrome: rgba(15, 16, 19, .9);
  --glass: rgba(22, 22, 24, .5);
  --elev: rgba(38, 38, 40, .86);
  --fill3: rgba(120, 120, 128, .24);
  --danger: #e5544b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* A long press on a tile means "select", not "copy this image". Without
   * this, iOS opens its own share sheet and the selection never fires. */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }

.hint { color: var(--hint); }
.link { color: var(--link); }
.danger { color: var(--danger); }
.num { font-variant-numeric: tabular-nums; }

/* Icons are stroked, never filled, unless the symbol says otherwise. Setting it
 * once here is what keeps every glyph the same weight. */
.ic { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center; border-radius: 12px;
}
.icon-btn:active { background: var(--bg2); }

@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ovfade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes shimmer { from { background-position: -320px 0; } to { background-position: 320px 0; } }

/* Scrollbars are hidden everywhere. The content is the interface; a scrollbar
 * across a masonry grid is a line drawn through a photograph. */
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.scroll::-webkit-scrollbar, .hscroll::-webkit-scrollbar { width: 0; height: 0; }
.hscroll { overflow-x: auto; scrollbar-width: none; }
.scroll { scrollbar-width: none; }

/* ── Chrome (only outside Telegram) ─────────────────────────────────── */

#chrome {
  position: fixed; top: 0; left: 0; right: 0; z-index: 29;
  height: calc(52px + var(--safe-top)); padding: var(--safe-top) 8px 0 6px;
  display: flex; align-items: center; gap: 4px;
  background: var(--chrome); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--sep);
}
.chrome-titles { min-width: 0; flex: 1; padding-left: 10px; }
#chrome-back:not([hidden]) ~ .chrome-titles { padding-left: 0; }
#chrome-title { font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
#chrome-subtitle { font-size: 11px; }
#chrome-title, #chrome-subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Upload strip and offline strip ─────────────────────────────────── */

#upbar {
  position: fixed; top: var(--chrome-h); left: 0; right: 0; z-index: 28;
  background: var(--bg); border-bottom: 1px solid var(--sep); cursor: pointer;
}
.upbar-track { height: 2px; background: var(--sep); }
.upbar-fill { height: 2px; width: 0; background: var(--accent); transition: width .3s linear; }
.upbar-row { display: flex; align-items: center; gap: 8px; padding: 7px 16px; font-size: 12px; color: var(--hint); }
.upbar-label { color: var(--text); font-weight: 600; }

#offline {
  position: fixed; top: calc(var(--chrome-h) + var(--upbar-h)); left: 0; right: 0; z-index: 27;
  padding: 5px 16px; background: #8a6d1f; color: #fff;
  font-size: 11.5px; font-weight: 600; text-align: center;
}

/* ── The screen ─────────────────────────────────────────────────────── */

#screen {
  position: fixed; inset: 0;
  top: calc(var(--chrome-h) + var(--strip-h));
  overflow: hidden;
  transition: top .2s ease;
}
.screen-body { height: 100%; overflow-y: auto; scrollbar-width: none; animation: fadeup .28s ease both; }
.screen-body::-webkit-scrollbar { width: 0; }
/* Room under the last row for the floating tab bar, which is not in flow. */
/* The end of a scrolling list has to clear the bar and the button above it,
 * or the last row of a gallery is unreachable. */
.tail { height: calc(var(--tabbar-h) + 62px); }

/* ── Library ────────────────────────────────────────────────────────── */

.lib-top { padding: 12px 16px 10px; display: flex; align-items: center; gap: 10px; }
.searchbox {
  flex: 1; display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 12px; border-radius: 11px;
  background: var(--bg2); color: var(--hint); font-size: 15px;
}
.searchbox .ic { stroke-width: 2; flex: none; }
.view-toggle {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: 11px; background: var(--bg2); color: var(--text);
}
.view-toggle .ic { stroke-width: 1.9; }

.chips {
  position: sticky; top: 0; z-index: 8;
  display: flex; gap: 7px; padding: 8px 16px 10px;
  background: var(--bg);
}
.chip {
  flex: none; height: 32px; padding: 0 14px; border-radius: 16px;
  font-size: 13.5px; font-weight: 600;
  background: var(--bg2); color: var(--hint);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }

.month {
  position: sticky; top: 50px; z-index: 6;
  padding: 14px 16px 8px;
  background: linear-gradient(var(--bg) 60%, transparent);
  font-size: 13px; font-weight: 700; color: var(--hint);
}

/* The masonry. Two columns of stacked tiles rather than a CSS grid: the grid
 * would need every tile's height in advance, and the whole point is that a
 * tile keeps the proportions of the photograph inside it. */
.grid { display: flex; gap: 3px; padding: 0 3px 10px; }
.col { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.tile {
  position: relative; overflow: hidden; border-radius: 2px;
  background-color: var(--tile); background-size: cover; background-position: center;
  cursor: pointer;
  transition: transform .18s ease, filter .18s ease;
}
.tile.striped {
  background-image: repeating-linear-gradient(135deg, var(--stripe-a) 0 7px, var(--stripe-b) 7px 14px);
}
.tile img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transition: opacity .22s ease;
}
.tile img.ready { opacity: 1; }
.tile.picked { transform: scale(.93); filter: brightness(.78); }

/* A file with no picture, drawn as what it is.
 *
 * The extension in the colour the format is known by, the size next to it, and
 * the plain-language name underneath. The corner fold is the one decoration:
 * it says "document" at a size where nothing else can. */
.card {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: 10px 11px 11px; background: var(--bg2); overflow: hidden;
}
.card-head { display: flex; align-items: center; gap: 7px; }
.card-tag {
  flex: none; padding: 2px 6px; border-radius: 5px;
  color: #fff; font-size: 10px; font-weight: 800; letter-spacing: .04em;
  line-height: 1.35;
}
.card-size { font-size: 11.5px; font-weight: 600; color: var(--hint); font-variant-numeric: tabular-nums; }
.card-body { flex: 1; min-height: 0; display: flex; align-items: center; }
.card-name {
  font-size: 12px; line-height: 1.3; font-weight: 600; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.card-what { margin-top: 2px; font-size: 11px; color: var(--hint); }
/* The folded corner. A triangle of the tile's own background, rotated over the
 * card, so it reads as paper turning rather than as a shape stuck on top. */
.card-corner {
  position: absolute; right: 0; top: 0; width: 17px; height: 17px;
  background: linear-gradient(225deg, var(--bg) 0 50%, rgba(0, 0, 0, .16) 50% 54%, transparent 54%);
}

/* An invented waveform: the bytes that would say what this sounds like are in
 * Telegram, and reading them for a tile would be a download per file. */
.wave { display: flex; align-items: flex-end; gap: 2px; width: 100%; height: 42px; }
.wave i { flex: 1; min-width: 2px; border-radius: 1px; opacity: .85; }

.card-sm { padding: 5px 5px 4px; }
.card-sm .card-head { gap: 4px; }
.card-sm .card-tag { padding: 1px 3px; font-size: 8px; letter-spacing: 0; }
.card-sm .card-size, .card-sm .card-name, .card-sm .card-what, .card-sm .card-corner { display: none; }
.card-sm .wave { height: 26px; gap: 1px; }

.tile-dur {
  position: absolute; right: 5px; bottom: 5px;
  display: flex; align-items: center; gap: 3px;
  padding: 2px 6px 2px 5px; border-radius: 5px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(4px);
  color: #fff; font-size: 10.5px; font-weight: 700;
}
.tile-dur svg { fill: #fff; stroke: none; }

.pick {
  position: absolute; left: 6px; top: 6px;
  width: 21px; height: 21px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1.8px solid rgba(255, 255, 255, .9);
  background: rgba(0, 0, 0, .18);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.picked .pick, .row.picked .pick { background: var(--accent); }
.pick .ic { stroke: #fff; stroke-width: 3.2; }

/* The list alternative to the grid. */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; }
.row.picked { background: var(--bg2); transform: none; filter: none; }
.row-thumb {
  position: relative; width: 44px; height: 44px; flex: none;
  border-radius: 8px; overflow: hidden;
  /* The colour is set apart from the image so that the blurred stand-in, which
   * arrives as an inline background-image, is not wiped by the shorthand. */
  background-color: var(--tile);
  background-size: cover; background-position: center;
  display: grid; place-items: center;
}
.row-thumb .ic { stroke: var(--hint); stroke-width: 1.6; }
.row-main { min-width: 0; flex: 1; }
.row-name { font-size: 14.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { margin-top: 2px; font-size: 12px; color: var(--hint); }
.row .pick { position: static; border-color: var(--sep); box-shadow: none; }

.skel {
  border-radius: 2px; background: var(--tile);
  background-image: linear-gradient(100deg, transparent 20%, var(--stripe-b) 50%, transparent 80%);
  background-size: 320px 100%;
  animation: shimmer 1.1s linear infinite;
}

.empty { padding: 90px 40px; text-align: center; }
.empty .ic { stroke: var(--hint); stroke-width: 1.3; opacity: .8; }
.empty p { margin-top: 14px; font-size: 15px; color: var(--hint); }
.empty button { margin-top: 14px; font-size: 15px; font-weight: 600; color: var(--link); }

.more { padding: 18px 0 0; text-align: center; font-size: 12px; color: var(--hint); }

/* ── Folders ────────────────────────────────────────────────────────── */

.folders-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.folders-top .count { font-size: 13px; font-weight: 700; color: var(--hint); }
.folders-top button { display: flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 600; color: var(--link); }
.folders-top .ic { stroke-width: 2.4; }

.folder {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 16px; border-top: 1px solid var(--sep); cursor: pointer;
}
.folder > .ic { stroke: var(--hint); stroke-width: 1.6; flex: none; }
.folder-name { font-size: 15.5px; font-weight: 500; }
.folder-meta { margin-top: 2px; font-size: 12.5px; color: var(--hint); }
.folder .chev { opacity: .6; stroke-width: 2; }
.folders-note { border-top: 1px solid var(--sep); padding: 14px 16px; font-size: 12px; color: var(--hint); }

/* ── Profile ────────────────────────────────────────────────────────── */

.me { display: flex; align-items: center; gap: 12px; padding: 16px 16px 20px; }
.avatar {
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  background: var(--bg2); font-size: 17px; font-weight: 700; color: var(--hint);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.me-name { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.me-handle { font-size: 13px; color: var(--hint); }

/* The one number the screen is about. It is the largest thing on it because
 * the product's claim is "look how much you have kept", not "look how much
 * room is left". */
.hero { padding: 0 16px 26px; }
.hero-num { font-size: 64px; font-weight: 800; letter-spacing: -.045em; line-height: .95; color: var(--accent); }
.hero-sub { margin-top: 6px; font-size: 13.5px; color: var(--hint); }

.mixbar { display: flex; height: 9px; border-radius: 5px; overflow: hidden; background: var(--bg2); margin: 0 16px 8px; }
.mixbar i { display: block; height: 100%; }
.legend { padding: 6px 0 26px; }
.legend-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--sep); cursor: pointer;
}
.legend-dot { width: 9px; height: 9px; flex: none; border-radius: 3px; }
.legend-label { flex: 1; font-size: 14.5px; font-weight: 500; }
.legend-count { font-size: 14px; font-weight: 600; }
.legend-pct { width: 44px; text-align: right; font-size: 13px; color: var(--hint); }

.section-title { padding: 0 16px 10px; font-size: 13px; font-weight: 700; color: var(--hint); }

/* Activity, as a year of days. Seven rows because a week has seven; the
 * columns run forward in time, exactly like the contribution graph everyone
 * already knows how to read. */
.heat-wrap { padding: 0 16px 2px; }
.heat { display: flex; gap: 6px; width: max-content; }
.heat-days {
  display: grid; grid-template-rows: repeat(7, 12px); gap: 3px;
  font-size: 9px; line-height: 12px; color: var(--hint);
}
.heat-months {
  display: grid; grid-auto-flow: column; margin-bottom: 4px;
  font-size: 9.5px; color: var(--hint);
}
.heat-cells {
  display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(7, 12px); grid-auto-columns: 12px; gap: 3px;
}
.heat-cells i { display: block; width: 12px; height: 12px; border-radius: 3px; cursor: pointer; }
.heat-note { padding: 10px 16px 0; font-size: 12px; color: var(--hint); }

.channel {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border-top: 1px solid var(--sep); border-bottom: 1px solid var(--sep); cursor: pointer;
}
.channel-name { font-size: 15px; font-weight: 600; }
.channel-sub { margin-top: 2px; font-size: 12.5px; color: var(--hint); }
.channel-state { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.channel-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--kind-video); }
.channel.warn { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.channel.warn .channel-name, .channel.warn .channel-state { color: var(--danger); }
.channel.warn .channel-dot { background: var(--danger); }

.actions { padding: 0 0 6px; }
.action { padding: 14px 16px; border-bottom: 1px solid var(--sep); font-size: 15px; font-weight: 500; cursor: pointer; }
.action .note { margin-top: 3px; font-size: 12px; font-weight: 400; color: var(--hint); }
.version { padding: 18px 16px 0; font-size: 11.5px; color: var(--hint); }

/* ── Connect ────────────────────────────────────────────────────────── */

.connect { padding: 30px 22px 0; }
.connect h1 { font-size: 19px; font-weight: 700; line-height: 1.35; letter-spacing: -.025em; text-wrap: pretty; }
.steps { padding: 30px 0 0; display: flex; flex-direction: column; gap: 22px; }
.step { display: flex; gap: 14px; }
.step b {
  width: 26px; height: 26px; flex: none; display: grid; place-items: center;
  border-radius: 50%; background: var(--bg2); font-size: 13px; font-weight: 700; color: var(--hint);
}
.step span { flex: 1; padding-top: 3px; font-size: 15.5px; line-height: 1.4; }
.connect-error { margin: 28px 0 0; padding: 14px 16px; border-radius: 14px; background: var(--bg2); }
.connect-error p { font-size: 14.5px; font-weight: 600; line-height: 1.4; color: var(--danger); }
.connect-error button { margin-top: 10px; font-size: 14.5px; font-weight: 600; color: var(--link); }
.connect-note { padding: 20px 0 40px; font-size: 12.5px; line-height: 1.5; color: var(--hint); text-wrap: pretty; }
.big-btn {
  width: 100%; height: 50px; border-radius: 12px;
  background: var(--accent); color: var(--accent-fg);
  font-size: 16px; font-weight: 600;
}
.big-btn[disabled] { opacity: .6; }

/* ── The tab bar ─────────────────────────────────────────────────────── */

/* Four icons on glass, rounded at the top, with the gallery visible through
 * it. Labels are gone: at twenty-six pixels a filled glyph is read faster than
 * a ten-point caption under it, and the row gains the space back.
 *
 * The numbers are the designer's, taken from the canvas as they are — height,
 * corner radius, blur, the opacity an idle icon sits at, and the sliver of
 * scale the current one gains. The one thing not copied is the gap under the
 * row: the canvas draws a phone with a home indicator, so it can hard-code
 * twenty-two points there. Here that space is whatever the device says it is,
 * and never less than the design's. */

.fab {
  position: fixed; right: 18px; z-index: 45;
  bottom: calc(var(--tabbar-h) + 14px);
  width: 52px; height: 52px; display: grid; place-items: center;
  border-radius: 50%; background: var(--accent); color: var(--accent-fg);
  box-shadow: 0 14px 30px -8px rgba(0, 0, 0, .45);
}

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 58;
  padding: 12px 6px max(var(--safe-bottom), 22px);
  border-radius: 22px 22px 0 0;
  background: var(--glass);
  backdrop-filter: blur(30px) saturate(1.9);
  -webkit-backdrop-filter: blur(30px) saturate(1.9);
  box-shadow: 0 -.5px 0 var(--sep);
}
/* The bar reaches both edges; the buttons inside it stop short of them on a
 * wide window, because four items stretched across a tablet stop looking like
 * a group and start looking like four separate things. */
.tabs { display: flex; align-items: flex-start; max-width: 560px; margin-inline: auto; }
.tab {
  flex: 1; height: 46px; display: grid; place-items: center;
  color: var(--text); transition: color .18s ease;
}
.tab:active { opacity: .5; }
.tab[aria-current="page"] { color: var(--accent); }
/* Filled, so the icon is the whole signal. The idle ones are dimmed rather
 * than greyed: on glass, a colour that is nearly the background disappears
 * entirely over a bright photograph, and opacity keeps the contrast with
 * whatever happens to be underneath. */
.tab .ic {
  fill: currentColor; stroke: none; opacity: .32;
  transition: opacity .18s ease, transform .18s cubic-bezier(.32, .72, 0, 1);
}
.tab[aria-current="page"] .ic { opacity: 1; transform: scale(1.04); }

/* ── Selection ──────────────────────────────────────────────────────── */

#selectbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 52;
  display: flex; align-items: center; justify-content: space-between;
  height: calc(52px + var(--safe-top)); padding: var(--safe-top) 16px 0;
  background: var(--chrome); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--sep); animation: ovfade .18s ease;
  font-size: 15px;
}
#sel-count { font-weight: 700; }
#selectactions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 52;
  display: flex; padding: 10px 8px calc(26px + var(--safe-bottom));
  background: var(--chrome); backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
  animation: sheetup .24s cubic-bezier(.32, .72, 0, 1);
}
#selectactions button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 6px 0;
}
#selectactions span { font-size: 11px; font-weight: 600; }

/* ── Layers ─────────────────────────────────────────────────────────── */

.layer { position: fixed; inset: 0; z-index: 55; background: var(--bg); }
#search, #upscreen {
  top: var(--chrome-h); overflow-y: auto; scrollbar-width: none;
  animation: fadeup .22s ease both;
}
#search::-webkit-scrollbar, #upscreen::-webkit-scrollbar { width: 0; }

/* ── Uploads ────────────────────────────────────────────────────────── */

.up-head {
  position: sticky; top: 0; z-index: 5;
  padding: 12px 16px 14px; background: var(--bg); border-bottom: 1px solid var(--sep);
}
.up-head-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.up-title { font-size: 15px; font-weight: 700; }
.up-track { height: 3px; border-radius: 2px; background: var(--bg2); }
.up-track i { display: block; height: 3px; border-radius: 2px; background: var(--accent); transition: width .3s linear; }
.up-row { padding: 13px 16px; border-bottom: 1px solid var(--sep); }
.up-row-top { display: flex; align-items: baseline; gap: 10px; }
.up-name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-cancel { font-size: 13px; font-weight: 600; color: var(--hint); }
.up-bar { margin: 9px 0 7px; height: 5px; border-radius: 3px; background: var(--bg2); }
.up-bar i { display: block; height: 5px; border-radius: 3px; width: 0; background: var(--accent); transition: width .3s linear; }
.up-meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--hint); }

.search-head { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--sep); }
.search-field { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.search-field > div {
  flex: 1; display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 12px; border-radius: 11px; background: var(--bg2);
}
.search-field input { width: 100%; background: transparent; border: 0; outline: none; font-size: 15px; color: var(--text); }
.search-field .ic { stroke: var(--hint); stroke-width: 2; flex: none; }
.search-chips { display: flex; gap: 7px; padding: 0 12px 10px; }
.search-chip {
  flex: none; display: flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 12px; border-radius: 15px;
  font-size: 13px; font-weight: 600; background: var(--bg2); color: var(--hint);
}
.search-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.search-count { padding: 10px 16px 6px; font-size: 12.5px; color: var(--hint); }
.history-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--sep); cursor: pointer; }
.history-row .ic { stroke: var(--hint); stroke-width: 1.7; flex: none; }
.soon { margin: 24px 16px 0; padding: 14px 16px; border-radius: 14px; background: var(--bg2); font-size: 13px; color: var(--hint); }

/* ── Viewer ─────────────────────────────────────────────────────────── */

/* Black regardless of the theme. A photograph is judged against its
 * surroundings, and a light grey frame changes what the picture looks like. */
.viewer { z-index: 70; background: #000; animation: ovfade .2s ease; }
.stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.stage-track { display: flex; height: 100%; will-change: transform; }
.slide { position: relative; flex: none; width: 100%; height: 100%; display: grid; place-items: center; overflow: hidden; }
.slide img, .slide video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }
.slide video { width: 100%; background: #000; }
.slide-fallback {
  width: 100%; aspect-ratio: 1; background: #141414;
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.05) 0 9px, rgba(255,255,255,.11) 9px 18px);
}
.slide .spin { position: absolute; color: rgba(255,255,255,.5); font-size: 12px; }

.viewer-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 8px 12px;
  background: linear-gradient(rgba(0, 0, 0, .6), transparent);
  transition: opacity .2s ease;
}
.viewer-top button { width: 42px; height: 42px; display: grid; place-items: center; color: #fff; }
.viewer-counter { font-size: 13px; font-weight: 600; color: rgba(255, 255, 255, .85); }
.viewer-foot {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 16px calc(28px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  color: rgba(255, 255, 255, .8); font-size: 12.5px; cursor: pointer;
  transition: opacity .2s ease;
}
.viewer-foot .ic { stroke-width: 2.2; }
.viewer.ui-hidden .viewer-top, .viewer.ui-hidden .viewer-foot { opacity: 0; pointer-events: none; }

.vpanel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 20px 16px calc(34px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 9px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85) 40%);
}
.vbtn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; border-radius: 14px; font-size: 15.5px; font-weight: 700;
}
.vbtn.primary { background: #fff; color: #000; }
.vbtn.ghost {
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .2);
  color: #fff; font-weight: 600; backdrop-filter: blur(12px);
}
.vprep { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); z-index: 4; padding: 0 40px; text-align: center; color: #fff; }
.vprep .t { font-size: 14px; font-weight: 600; }
.vprep .bar { margin: 12px auto 0; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .18); }
.vprep .bar i { display: block; height: 3px; border-radius: 2px; background: #fff; width: 0; transition: width .3s linear; }
.vprep .p { margin-top: 8px; font-size: 12px; color: rgba(255, 255, 255, .6); }

.vcontrols {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 18px 16px calc(30px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .8) 45%); color: #fff;
  transition: opacity .2s ease;
}
.viewer.ui-hidden .vcontrols { opacity: 0; pointer-events: none; }
/* The seek bar shows what has been buffered as a separate shade. Big files
 * pause while they load, and without this the pause is indistinguishable from
 * a freeze — the viewer waits, decides the app is broken, and leaves. */
.seek { position: relative; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .16); margin-bottom: 12px; touch-action: none; cursor: pointer; }
.seek-buf, .seek-pos { position: absolute; left: 0; top: 0; height: 4px; border-radius: 2px; width: 0; }
.seek-buf { background: rgba(255, 255, 255, .42); }
.seek-pos { background: #fff; }
.seek-knob { position: absolute; top: -4px; left: 0; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: #fff; }
.vrow { display: flex; align-items: center; gap: 14px; }
.vrow button { color: #fff; display: grid; place-items: center; width: 34px; height: 34px; }
.vtime { font-size: 12.5px; color: rgba(255, 255, 255, .85); }
.vcontrols .open-tg { margin-top: 12px; font-size: 13px; font-weight: 600; color: rgba(255, 255, 255, .75); }
.verror { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; padding: 22px 16px calc(34px + var(--safe-bottom)); background: linear-gradient(transparent, rgba(0, 0, 0, .85) 40%); text-align: center; }
.verror p { margin-bottom: 14px; font-size: 14.5px; font-weight: 600; color: #fff; }

.info-scrim { position: absolute; inset: 0; z-index: 6; background: rgba(0, 0, 0, .4); animation: ovfade .2s ease; }
.info-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 7;
  max-height: 70%; overflow-y: auto; scrollbar-width: none;
  border-radius: 22px 22px 0 0; padding: 14px 20px calc(28px + var(--safe-bottom));
  background: var(--bg); color: var(--text);
  animation: sheetup .26s cubic-bezier(.32, .72, 0, 1);
}
.grabber { margin: 0 auto 16px; width: 36px; height: 4px; border-radius: 2px; background: var(--sep); }
.info-row { display: flex; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--sep); }
.info-row .k { width: 120px; flex: none; font-size: 13px; color: var(--hint); }
.info-row .v { flex: 1; font-size: 14px; font-weight: 500; word-break: break-all; }
.info-sheet .open-tg { margin-top: 16px; display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--link); }

/* ── Sheet, dialog, toast ───────────────────────────────────────────── */

#sheet { position: fixed; inset: 0; z-index: 64; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: ovfade .2s ease; }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  border-radius: 24px 24px 0 0; padding: 14px 20px calc(30px + var(--safe-bottom));
  background: var(--bg); border-top: 1px solid var(--sep);
  animation: sheetup .28s cubic-bezier(.32, .72, 0, 1);
}
.sheet-card { padding: 16px 18px; border-radius: 16px; background: var(--bg2); }
.sheet-card h2 { font-size: 16.5px; font-weight: 700; letter-spacing: -.02em; }
.sheet-card p { margin-top: 5px; font-size: 13.5px; line-height: 1.45; color: var(--hint); }
.sheet-card button { margin-top: 14px; width: 100%; height: 46px; border-radius: 12px; background: var(--accent); color: var(--accent-fg); font-size: 15.5px; font-weight: 600; }
.sheet-alt { margin-top: 8px; width: 100%; display: flex; align-items: center; gap: 10px; padding: 18px; font-size: 15.5px; font-weight: 500; text-align: left; }
.sheet-alt .ic { stroke: var(--hint); }

#dialog { position: fixed; inset: 0; z-index: 80; }
.dialog-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); animation: ovfade .18s ease; }
/* An alert, drawn the way the platform draws one.
 *
 * Narrow and centred rather than edge to edge, because the width is what says
 * "answer this" instead of "here is a screen". Two choices sit side by side and
 * more than two stack: a row of two reads as this-or-that, a column reads as a
 * list to pick from, and swapping them makes a confirmation feel like a menu. */
.dialog-body {
  position: absolute; left: 50%; top: 50%; width: 272px; margin-left: -136px;
  transform: translateY(-50%);
  border-radius: 14px; overflow: hidden;
  background: var(--elev); backdrop-filter: blur(28px) saturate(1.8);
  -webkit-backdrop-filter: blur(28px) saturate(1.8);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .5);
  animation: alertin .22s cubic-bezier(.32, .72, 0, 1) both;
}
.dialog-head { padding: 19px 16px 16px; text-align: center; }
.dialog-body h2 { font-size: 16px; font-weight: 600; letter-spacing: -.02em; text-wrap: pretty; }
.dialog-body p { margin-top: 4px; font-size: 13px; line-height: 1.35; opacity: .9; text-wrap: pretty; }
.dialog-input {
  margin: 12px 0 2px; width: 100%; height: 36px; padding: 0 10px;
  border-radius: 8px; border: 1px solid var(--sep); background: var(--bg);
  color: var(--text); font-size: 15px; outline: none; text-align: left;
}
.dialog-input:focus { border-color: var(--accent); }

.dialog-actions { display: flex; flex-direction: column; }
.dialog-actions button {
  min-height: 44px; padding: 11px 14px; border-top: .5px solid var(--sep);
  font-size: 16px; font-weight: 400; color: var(--link); text-align: center;
}
.dialog-actions.row { flex-direction: row; }
.dialog-actions.row button { flex: 1; }
.dialog-actions.row button + button { border-left: .5px solid var(--sep); }
.dialog-actions button.cancel { font-weight: 600; }
.dialog-actions button.danger { color: var(--danger); }
.dialog-actions button:active { background: var(--fill3); }

@keyframes alertin {
  from { opacity: 0; transform: translateY(-50%) scale(1.12); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}

/* A pill, not a banner. It reports something that already happened, so it says
 * so in as little of the screen as the words need. */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 90;
  bottom: calc(var(--tabbar-h) + 16px);
  max-width: calc(100% - 48px);
  padding: 11px 18px; border-radius: 22px;
  background: var(--elev); color: var(--text);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .35);
  font-size: 14.5px; font-weight: 500; text-align: center; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(28px) saturate(1.8);
  -webkit-backdrop-filter: blur(28px) saturate(1.8);
  animation: fadeup .22s cubic-bezier(.32, .72, 0, 1) both;
}

/* ── Wider screens ──────────────────────────────────────────────────── */

/* The design has to work up to 1024px. More columns rather than wider tiles:
 * a photograph blown up to half a tablet is not a gallery, it is a slideshow
 * with extra steps. */
@media (min-width: 700px) {
  .grid { padding: 0 4px 12px; gap: 4px; }
  .col { gap: 4px; }
  .month, .lib-top, .chips { max-width: 1024px; margin-inline: auto; }
}


/* ── Playback ─────────────────────────────────────────────────────────── */

/* A spinner only while there is something to wait for.
 *
 * The old screen counted a percentage of the whole file, which was honest
 * arithmetic about the wrong thing: a video does not need all of itself to
 * start. With the index moved to the front it needs about a second of it, and
 * the right report for a second is a turning ring, not a number. */
.vwait {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 34px; height: 34px;
}
.vwait i {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .22);
  border-top-color: rgba(255, 255, 255, .9);
  animation: vspin .8s linear infinite;
}
@keyframes vspin { to { transform: rotate(360deg); } }

/* Buffering mid-play: the same ring, over the controls, without taking them
 * away — a viewer who wants to seek out of a stall must be able to. */
.viewer.buffering .vcontrols::after {
  content: ''; position: absolute; left: 50%; bottom: 130px;
  width: 28px; height: 28px; margin-left: -14px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .22);
  border-top-color: rgba(255, 255, 255, .9);
  animation: vspin .8s linear infinite;
}

.open-tg.primary { background: var(--accent); color: var(--accent-fg); }
.open-tg.primary .ic { stroke: var(--accent-fg); }

.sheet-note {
  padding: 14px 18px 2px; font-size: 12.5px; line-height: 1.4; color: var(--hint);
  text-align: center;
}
