/* Vault — dark by design. The visual break from the other tido.site apps is
   deliberate: it should be obvious at a glance that you are inside the vault. */

:root {
  --bg: #0e1013;
  --bg-soft: #14171c;
  --surface: #191d23;
  --surface-hi: #1f242b;
  --border: #272d36;
  --border-hi: #333b46;
  --text: #e6e9ee;
  --text-soft: #9aa4b2;
  --text-faint: #6b7482;
  --accent: #6ea8fe;
  --accent-hi: #8bbcff;
  --accent-dim: #1d3557;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --red-dim: #3b1d1d;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

[hidden] { display: none !important; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  background: var(--surface-hi);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover:not(:disabled) { background: #262c35; border-color: #3f4854; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b1220; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn-danger { color: var(--red); border-color: #4a2a2a; background: var(--red-dim); }
.btn-danger:hover:not(:disabled) { background: #4d2323; border-color: #6b3333; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hi); color: var(--text); }
.btn-small { padding: 6px 11px; font-size: 12.5px; }

input[type="text"], input[type="password"], input[type="search"], textarea {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 254, .13);
}
input::placeholder { color: var(--text-faint); }

/* ── Lock screen ─────────────────────────────────────────────────────────── */

.fatal { padding: 48px 24px; text-align: center; color: var(--text-soft); font-size: 14px; }

.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* Scrollable so the on-screen keyboard cannot bury the submit button. */
  overflow-y: auto;
  background:
    radial-gradient(900px 500px at 50% -10%, #182233 0%, transparent 70%),
    var(--bg);
  z-index: 100;
}
.gate-card { width: 100%; max-width: 350px; text-align: center; }
.gate-mark {
  width: 52px; height: 52px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  background: var(--surface);
  color: var(--accent);
}
.gate-card h1 { font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.gate-sub { margin: 7px 0 22px; font-size: 13.5px; color: var(--text-soft); line-height: 1.5; }
#gateForm { display: flex; flex-direction: column; gap: 9px; }
.gate-remember {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-soft);
  cursor: pointer; user-select: none;
  padding: 2px 0 4px;
}
.gate-remember input { width: auto; accent-color: var(--accent); cursor: pointer; }
#gateSubmit {
  padding: 11px;
  border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #0b1220;
  font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
#gateSubmit:hover:not(:disabled) { background: var(--accent-hi); }
#gateSubmit:disabled { opacity: .5; cursor: not-allowed; }
.gate-error { min-height: 1.3em; font-size: 13px; color: var(--red); }
.gate-warning {
  margin-top: 18px;
  padding: 13px 15px;
  border: 1px solid #4a3a1d;
  border-radius: var(--radius-sm);
  background: #241d10;
  color: #e7d9b8;
  font-size: 12.5px;
  line-height: 1.6;
  text-align: left;
}
.gate-warning strong { display: block; margin-bottom: 4px; color: var(--amber); }

/* ── Shell ───────────────────────────────────────────────────────────────── */

.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 208px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 18px 12px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 10px 18px;
  font-size: 15px; font-weight: 600;
  color: var(--text);
}
.brand svg { color: var(--accent); }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 11px;
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px; font-weight: 500;
  text-align: left; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.is-active { background: var(--surface-hi); color: var(--text); }
.nav-badge {
  margin-left: auto;
  min-width: 19px; padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-dim); color: var(--accent-hi);
  font-size: 11px; font-weight: 600; text-align: center;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

/* Sidebar download indicator */
.dl-widget {
  display: block; width: 100%; text-align: left;
  padding: 9px 11px;
  border: 1px solid var(--border-hi); border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dl-widget:hover { background: var(--surface-hi); border-color: #3f4854; }
.dl-widget-top {
  display: flex; justify-content: space-between; gap: 8px;
  margin-bottom: 7px;
  font-size: 12px; font-weight: 500; color: var(--text);
}
.dl-widget-top span:last-child { color: var(--accent); font-variant-numeric: tabular-nums; }
.dl-widget-sub {
  margin-top: 6px;
  font-size: 11px; color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.usage { padding: 0 11px; font-size: 11.5px; color: var(--text-faint); line-height: 1.6; }
.lock-btn {
  padding: 9px;
  border: 1px solid var(--border-hi); border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.lock-btn:hover { background: var(--surface-hi); color: var(--text); }

.content { flex: 1; min-width: 0; overflow-y: auto; }
.view { display: none; padding: 22px 26px 60px; }
.view.is-active { display: block; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  min-height: 34px;
}
.topbar h2 { font-size: 17px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.searchbox input { width: 190px; padding: 7px 12px; font-size: 13px; }

.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 14px; min-width: 0; }
.crumb {
  padding: 4px 8px;
  border: none; border-radius: 6px;
  background: transparent; color: var(--text-soft);
  font-size: 14px; cursor: pointer;
}
.crumb:hover { background: var(--surface); color: var(--text); }
.crumb.is-last { color: var(--text); font-weight: 600; cursor: default; }
.crumb.is-last:hover { background: transparent; }
.crumb-sep { color: var(--text-faint); }

/* ── File listing ────────────────────────────────────────────────────────── */

.dropzone {
  border: 1px dashed transparent;
  border-radius: var(--radius);
  transition: border-color .15s, background .15s;
  min-height: 220px;
}
.dropzone.is-dragover { border-color: var(--accent); background: rgba(110, 168, 254, .05); }

.listing {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.listing:empty { display: none; }

.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bg-soft);
  cursor: pointer;
  transition: background .1s;
}
.row-item:last-child { border-bottom: none; }
.row-item:hover { background: var(--surface-hi); }
.row-item.is-selected { background: #1b2735; }
/* The checkbox itself stays small; the label around it is the tap target. */
.row-checkwrap {
  flex-shrink: 0;
  display: grid; place-items: center;
  width: 30px; height: 30px; margin: -6px 0 -6px -6px;
  cursor: pointer;
}
.row-check { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.row-more {
  flex-shrink: 0;
  width: 32px; height: 32px; margin: -6px -6px -6px 0;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-faint);
  font-size: 17px; line-height: 1; cursor: pointer;
  transition: background .12s, color .12s;
}
.row-more:hover { background: var(--surface-hi); color: var(--text); }
.row-icon { width: 20px; flex-shrink: 0; color: var(--text-faint); display: grid; place-items: center; }
.row-icon.is-dir { color: var(--accent); }
.row-name { flex: 1; min-width: 0; }
/* The label is its own element so the mobile line-clamp can apply to the name
   without also clamping the search-result trail underneath it. */
.row-label { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 12.5px; color: var(--text-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.row-size { min-width: 76px; text-align: right; }
.row-date { min-width: 108px; text-align: right; }

.empty { padding: 56px 20px; text-align: center; color: var(--text-faint); }
.empty p { font-size: 14.5px; color: var(--text-soft); margin-bottom: 5px; }
.empty span { font-size: 13px; }

.selection-bar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; padding: 9px 13px;
  border: 1px solid var(--border-hi); border-radius: var(--radius);
  background: var(--surface-hi);
  font-size: 13px;
}
.spacer { flex: 1; }

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

.uploads {
  position: fixed; right: 20px; bottom: 20px;
  width: 320px; max-height: 45vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 7px;
  z-index: 40;
}
.upload-item {
  padding: 10px 13px;
  border: 1px solid var(--border-hi); border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  font-size: 12.5px;
}
.upload-item .name { display: flex; gap: 8px; margin-bottom: 7px; }
.upload-item .name span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item .pct { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.upload-item.is-error { border-color: #4a2a2a; }
.upload-item.is-error .pct { color: var(--red); }

.bar { height: 4px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s; }
.bar.is-done > i { background: var(--green); }

/* ── Panels ──────────────────────────────────────────────────────────────── */

.panel {
  padding: 18px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.panel h3 { font-size: 14px; font-weight: 600; margin-bottom: 13px; }
.panel-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 13px; }
.panel-head h3 { margin-bottom: 0; }
.panel-note { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* With the concurrency limit raised, Active can hold ten cards. Cap it so the
   results below stay reachable without a long scroll. */
#torrentActive { max-height: 46vh; overflow-y: auto; }
.hint { margin-top: 11px; font-size: 12.5px; color: var(--text-faint); line-height: 1.6; }
.stack { display: flex; flex-direction: column; gap: 9px; max-width: 380px; }
.row { display: flex; align-items: center; gap: 11px; }
.form-note { font-size: 12.5px; color: var(--text-soft); }
.form-note.is-error { color: var(--red); }
.form-note.is-ok { color: var(--green); }

.search-form { display: flex; gap: 8px; }
.search-form input { flex: 1; }

.results { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.result {
  display: flex; align-items: center; gap: 13px;
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-soft);
}
.result-name { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta { font-size: 12px; color: var(--text-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.seeds { color: var(--green); }
.peers { color: var(--text-faint); }

.active-list { display: flex; flex-direction: column; gap: 9px; }
.torrent {
  padding: 12px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-soft);
}
.torrent-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.torrent-actions { display: flex; align-items: center; gap: 10px; margin-top: 9px; }
.torrent-name { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.torrent-foot {
  display: flex; gap: 14px; margin-top: 7px;
  font-size: 11.5px; color: var(--text-faint);
  font-variant-numeric: tabular-nums; flex-wrap: wrap;
}
.tag {
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: lowercase;
  background: var(--surface-hi); color: var(--text-soft);
  flex-shrink: 0;
}
.tag.is-encrypting { background: var(--accent-dim); color: var(--accent-hi); }
.tag.is-complete { background: #14331f; color: var(--green); }
.tag.is-error { background: var(--red-dim); color: var(--red); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; font-size: 13px; }
.facts dt { color: var(--text-faint); }
.facts dd { color: var(--text); font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

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

.viewer {
  position: fixed; inset: 0; z-index: 80;
  display: flex; flex-direction: column;
  background: #08090b;
}
.viewer-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  flex-shrink: 0;
}
.viewer-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  overflow: auto;
}
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body video { max-width: 100%; max-height: 100%; background: #000; }
.viewer-body audio { width: min(560px, 100%); }
.viewer-body iframe { width: 100%; height: 100%; border: none; background: #fff; border-radius: 6px; }
.viewer-body textarea {
  width: 100%; height: 100%;
  padding: 16px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  resize: none;
  tab-size: 2;
}
.viewer-note { color: var(--text-soft); font-size: 13.5px; text-align: center; line-height: 1.7; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(4, 6, 9, .72);
}
.modal-card {
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 13px;
  padding: 20px;
  border: 1px solid var(--border-hi); border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.modal-card h3 { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.modal-message { font-size: 13px; color: var(--text-soft); line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Action sheet: one full-width button per choice. */
.modal-choices { display: flex; flex-direction: column; gap: 6px; }
.modal-choice {
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-hi);
  color: var(--text);
  font-size: 14px; text-align: left; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.modal-choice:hover { background: #262c35; border-color: var(--border-hi); }
.modal-choice.is-danger { color: var(--red); border-color: #4a2a2a; background: var(--red-dim); }
.modal-choice.is-danger:hover { background: #4d2323; border-color: #6b3333; }

.tree { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 5px; }
.tree-node {
  display: block; width: 100%;
  padding: 6px 9px;
  border: none; border-radius: 5px;
  background: transparent; color: var(--text-soft);
  font-size: 13px; text-align: left; cursor: pointer;
}
.tree-node:hover { background: var(--surface-hi); color: var(--text); }
.tree-node.is-selected { background: var(--accent-dim); color: var(--accent-hi); font-weight: 500; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 7px;
  z-index: 120;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border: 1px solid var(--border-hi); border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .5);
  font-size: 13px;
  animation: toast-in .18s ease-out;
}
.toast.is-error { border-color: #4a2a2a; color: #ffbcbc; }
.toast.is-ok { border-color: #1f4030; color: #b6f3cd; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Touch ───────────────────────────────────────────────────────────────── */

/* Applies to any touch device, phone or not: no hover to reveal things with,
   and taps need targets a fingertip can actually hit. */
@media (hover: none) {
  button, .row-item, .crumb, .tree-node, .nav-item { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  .btn { min-height: 40px; }
  .btn-small { min-height: 36px; }
  .row-item { min-height: 52px; }
  .row-check { width: 19px; height: 19px; }
  .row-checkwrap { width: 40px; height: 40px; margin: -10px 4px -10px -10px; }
  .row-more { width: 40px; height: 40px; margin: -8px -8px -8px 0; font-size: 19px; }
  .modal-choice { min-height: 48px; }
  .tree-node { padding: 11px 10px; }
  .crumb { padding: 7px 9px; }
  /* Hover styling sticks after a tap on touch, which reads as a stuck selection. */
  .row-item:hover { background: none; }
  .row-item.is-selected:hover { background: #1b2735; }
}

/* ── Narrow screens ──────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  /* Mobile browser chrome makes 100vh taller than the visible area, which puts
     the bottom of the app under the URL bar. dvh tracks the real viewport. */
  .app { flex-direction: column; height: auto; min-height: 100vh; min-height: 100dvh; }
  .sidebar {
    width: 100%;
    flex-direction: row; align-items: center;
    gap: 4px; padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-right: none; border-bottom: 1px solid var(--border);
    overflow-x: auto;
    position: sticky; top: 0; z-index: 30;
  }
  .brand { padding: 0 8px 0 2px; }
  .brand span { display: none; }
  .nav-item { padding: 9px 12px; white-space: nowrap; }
  .sidebar-foot { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; gap: 8px; }
  .usage { display: none; }
  .dl-widget { width: auto; min-width: 128px; padding: 6px 9px; }
  .dl-widget-sub { display: none; }
  .content { height: auto; }
  .view { padding: 14px 12px calc(72px + env(safe-area-inset-bottom)); }

  .topbar { gap: 10px; }
  .topbar-actions { width: 100%; margin-left: 0; }
  /* Search takes the first row on its own; the buttons share the next one. */
  .searchbox { flex: 1 1 100%; }
  .searchbox input { width: 100%; }
  .topbar-actions .btn { flex: 1; }

  .row-item { padding: 11px 12px; gap: 10px; }
  .row-date { display: none; }
  .row-size { min-width: 0; }
  .row-name { font-size: 14.5px; }
  /* A phone fits about 30 characters, so one ellipsised line hid most of a
     filename. Wrap to three — enough for almost everything, and rows only grow
     for the names that need it. Anything longer still reads in full in the ⋯
     sheet, which titles itself with the whole name. */
  .row-label {
    display: -webkit-box; -webkit-box-orient: vertical;
    -webkit-line-clamp: 3; line-clamp: 3;
    white-space: normal; overflow-wrap: anywhere;
    line-height: 1.35;
  }

  /* The selection bar is the only way to act on a multi-select, and it sits
     above the listing in the markup — so sticky would scroll away with it.
     Fixed to the bottom keeps it under a thumb however long the list is. */
  .selection-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    margin: 0; border-radius: 0;
    border-left: none; border-right: none; border-bottom: none;
    flex-wrap: wrap; gap: 6px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--bg-soft);
    box-shadow: 0 -10px 26px rgba(4, 6, 9, .55);
  }
  .selection-bar .spacer { flex-basis: 100%; height: 0; }
  .selection-bar .btn { flex: 1; }

  /* Room for the fixed selection bar, so it never covers the last row. */
  .has-selection .view { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }

  .uploads { right: 12px; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); width: auto; }
  .toasts { left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); transform: none; align-items: center; }
  .has-selection .toasts { bottom: calc(160px + env(safe-area-inset-bottom)); }
  .has-selection .uploads { bottom: calc(110px + env(safe-area-inset-bottom)); }

  /* Modals as bottom sheets — reachable, and they do not fight the keyboard. */
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none;
    border-radius: var(--radius) var(--radius) 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    max-height: 88dvh; overflow-y: auto;
  }
  .modal-actions .btn { flex: 1; }
  .tree { max-height: 42dvh; }

  .viewer { padding-top: env(safe-area-inset-top); }
  .viewer-bar { padding: 10px 12px; align-items: flex-start; }
  /* Two lines, so you can tell which of three similar files you opened. */
  .viewer-name {
    display: -webkit-box; -webkit-box-orient: vertical;
    -webkit-line-clamp: 2; line-clamp: 2;
    white-space: normal; overflow-wrap: anywhere; line-height: 1.35;
  }
  .viewer-body { padding: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

  .panel { padding: 14px; }
  .stack { max-width: none; }
  .search-form { flex-wrap: wrap; }
  .search-form input { flex: 1 1 100%; }
  .search-form .btn { flex: 1; }
  #torrentActive { max-height: 50dvh; }

  /* Name on its own line, then the numbers and Add together underneath —
     six things on one line is unreadable at phone width. */
  .result { flex-wrap: wrap; gap: 7px 10px; padding: 11px 12px; }
  /* Release names are one long dotted token; without anywhere they run off the
     side of the card rather than wrapping. */
  .result-name {
    flex-basis: 100%; white-space: normal; overflow: visible;
    overflow-wrap: anywhere; line-height: 1.45;
  }
  .result .btn { margin-left: auto; }

  .facts { grid-template-columns: 1fr; gap: 3px; }
  .facts dt { margin-top: 7px; }
  .facts dt:first-child { margin-top: 0; }

  .gate-card { padding-bottom: env(safe-area-inset-bottom); }

  /* iOS zooms the page in when it focuses an input under 16px. */
  input[type="text"], input[type="password"], input[type="search"], textarea, select { font-size: 16px; }
  .searchbox input { font-size: 16px; }
}
