/* ============================================================
   Phone / installed-app layer: safe areas, sync sheet, update toast.
   ============================================================ */

/* the iPhone status bar floats over the app (black-translucent): keep content clear of it */
.library { padding-top: env(safe-area-inset-top); }
@media (display-mode: standalone) {
  /* white status-bar text needs a little shade on the light themes */
  :root[data-theme="light"] body::before,
  :root[data-theme="sepia"] body::before {
    content: ""; position: fixed; inset: 0 0 auto 0; z-index: 90; pointer-events: none;
    height: calc(env(safe-area-inset-top) + 8px);
    background: linear-gradient(rgba(var(--shade), .5), rgba(var(--shade), 0));
  }
  body { overscroll-behavior-y: none; }
}
html.phone-mode { -webkit-tap-highlight-color: transparent; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------- library hooks ---------------- */
.sync-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px 0 12px; border-radius: 999px;
  font: 600 14px/1 var(--ui); color: var(--ink-2); background: var(--bg-2);
  transition: background-color .2s, color .2s, transform .15s var(--ease);
}
.sync-btn:hover { color: var(--ink); background: color-mix(in oklab, var(--bg-2) 80%, var(--ink) 8%); }
.sync-btn:active { transform: scale(.97); }
.sync-btn svg { width: 18px; height: 18px; color: var(--crimson); }
.hero-empty { flex-wrap: wrap; }
.hero-empty p { flex: 1 1 260px; margin: 0; font: 400 17px/1.5 var(--serif); }

/* ---------------- update toast ---------------- */
.toast-update { cursor: pointer; border: 0; font: 600 14px/1 var(--ui); pointer-events: auto; }

/* ---------------- sync sheet ---------------- */
body.sync-open { overflow: hidden; }
.sync { position: fixed; inset: 0; z-index: 200; display: grid; grid-template-columns: minmax(0, 1fr); align-items: end; justify-items: center; }
.sync-scrim {
  position: absolute; inset: 0; background: rgba(var(--shade), .38);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .35s ease;
}
.sync-sheet {
  position: relative; width: min(640px, 100%); min-width: 0; max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  background-image: var(--paper);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 60px -20px rgba(var(--shade), .5);
  transform: translateY(104%);
  transition: transform .55s var(--spring, var(--ease-out));
  outline: none;
}
.sync.in .sync-scrim { opacity: 1; }
.sync.in .sync-sheet { transform: none; }
.sync.out .sync-scrim { opacity: 0; transition-duration: .3s; }
.sync.out .sync-sheet { transform: translateY(104%); transition: transform .38s cubic-bezier(.5, 0, .75, 0); }
@media (min-width: 720px) {
  .sync { align-items: center; }
  .sync-sheet { border-radius: 22px; max-height: min(86vh, 820px); transform: translateY(24px) scale(.97); opacity: 0; transition: transform .5s var(--spring, var(--ease-out)), opacity .3s ease; }
  .sync.in .sync-sheet { opacity: 1; }
  .sync.out .sync-sheet { transform: translateY(16px) scale(.98); opacity: 0; transition: transform .3s ease, opacity .25s ease; }
}
@media (prefers-reduced-motion: reduce) {
  .sync-sheet, .sync-scrim { transition-duration: .01s !important; }
}

.sync-head > div { min-width: 0; }
.sync-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 22px 20px 8px 24px;
}
.sync-head::before {
  content: ""; position: absolute; top: 8px; left: 50%; width: 38px; height: 5px; margin-left: -19px;
  border-radius: 3px; background: var(--line);
}
@media (min-width: 720px) { .sync-head::before { display: none; } }
.sync-kicker { margin: 0 0 6px; display: flex; align-items: center; gap: 7px; font: 600 12px/1 var(--ui); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.sync-kicker svg { width: 14px; height: 14px; color: var(--crimson); }
.sync-head h2 { margin: 0; font: 500 28px/1.12 var(--serif); font-variation-settings: "opsz" 48; letter-spacing: -0.015em; }
.sync-x { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--ink-2); background: var(--bg-2); }
.sync-x:hover { color: var(--ink); }

.sync-body {
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 10px max(20px, env(safe-area-inset-left)) calc(28px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-right));
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px;
}

.sync-err {
  padding: 12px 14px; border-radius: 14px;
  background: color-mix(in oklab, var(--crimson) 12%, var(--bg)); color: var(--ink);
  border: 1px solid color-mix(in oklab, var(--crimson) 30%, transparent);
  font: 500 14px/1.45 var(--ui);
}

.sync-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.sync-store, .adv-form { grid-template-columns: minmax(0, 1fr); }
.sync-lede { margin: 0; font: 400 18px/1.5 var(--serif); color: var(--ink-2); text-wrap: pretty; }
.sync-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; color: var(--ink-2); font: 400 15px/1.5 var(--ui); }
.sync-steps b { color: var(--ink); font-weight: 600; }
.sync-steps code { font: 500 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 6px; border-radius: 6px; background: var(--bg-2); }

.code-form { display: flex; gap: 10px; min-width: 0; }
.code-in {
  flex: 1 1 0; width: 0; min-width: 0; height: 60px; padding: 0 16px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font: 600 28px/1 var(--ui); letter-spacing: .32em; text-transform: uppercase; text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color .2s, box-shadow .2s;
}
.code-in::placeholder { color: var(--ink-3); opacity: .45; }
.code-in:focus { outline: none; border-color: var(--crimson); box-shadow: 0 0 0 4px color-mix(in oklab, var(--crimson) 18%, transparent); }
.code-go { height: 60px; padding: 0 24px; border-radius: 16px; font-size: 16px; }
.code-go[disabled] { opacity: .7; }

.sync-adv summary { cursor: pointer; color: var(--ink-3); font: 500 14px/1.4 var(--ui); padding: 6px 0; list-style-position: inside; }
.adv-form { display: grid; gap: 12px; padding-top: 10px; }
.adv-form label { display: grid; gap: 6px; font: 500 13px/1.3 var(--ui); color: var(--ink-2); }
.adv-form input {
  height: 46px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font: 400 15px/1 var(--ui);
}
.adv-form input:focus { outline: none; border-color: var(--crimson); }
.adv-form .btn { justify-self: start; }
.muted { color: var(--ink-3); font-weight: 400; }

.sync-conn {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 14px; background: var(--bg-2); font: 400 14px/1.4 var(--ui); color: var(--ink-2);
}
.sync-conn b { color: var(--ink); font-weight: 600; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #3f9b6a; box-shadow: 0 0 0 0 rgba(63, 155, 106, .5); animation: syncPulse 2.4s ease-out infinite; }
@keyframes syncPulse { 0% { box-shadow: 0 0 0 0 rgba(63, 155, 106, .45); } 70%, 100% { box-shadow: 0 0 0 9px rgba(63, 155, 106, 0); } }
@media (prefers-reduced-motion: reduce) { .sync-dot { animation: none; } }
.link-btn { margin-left: auto; min-height: 40px; padding: 0 6px; color: var(--ink-3); font: 500 14px/1 var(--ui); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in oklab, currentColor 40%, transparent); }
.link-btn:hover { color: var(--ink); }
.link-btn.danger { color: var(--crimson); }

.sync-list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: -8px; }
.sync-list-head h3 { margin: 0; font: 500 19px/1.2 var(--serif); font-variation-settings: "opsz" 28; }
.btn.sm { height: 40px; padding: 0 14px; font-size: 14px; }
.btn.sm svg { width: 16px; height: 16px; }

.sync-books { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sb {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.sb:last-child { border-bottom: 0; }
.sb-art { width: 56px; height: 56px; border-radius: 8px; overflow: hidden; background: var(--bg-2); display: grid; place-items: center; box-shadow: 0 6px 16px -10px rgba(var(--shade), .6); }
.sb-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sb-art svg { width: 22px; height: 22px; color: var(--ink-3); }
.sb-main { min-width: 0; display: grid; gap: 3px; }
.sb-title { font: 500 17px/1.25 var(--serif); font-variation-settings: "opsz" 24; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-status { font: 400 13px/1.35 var(--ui); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.st-complete .sb-status { color: var(--ink-2); }
.sb-bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--bg-2); overflow: hidden; }
.sb-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--crimson), var(--gold)); transform-origin: left; transition: transform .6s var(--ease-out); }
.sb-act { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.sb-act .link-btn { margin-left: 0; }
.confirm { display: inline-flex; align-items: center; gap: 2px; font: 500 14px/1 var(--ui); color: var(--ink-2); }
@media (max-width: 480px) {
  .sb { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 12px; }
  .sb-art { width: 48px; height: 48px; }
  .sb-act .btn.sm { height: 38px; padding: 0 13px; }
  .sb-act .btn.sm svg { display: none; }
  .sb-act { flex-direction: column; align-items: flex-end; gap: 0; }
}

.sync-store { display: grid; gap: 8px; }
.sync-store p { margin: 0; font: 400 13px/1.5 var(--ui); color: var(--ink-3); }
.store-bar { height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; }
.store-bar span { display: block; height: 100%; background: var(--ink-3); transform-origin: left; transition: transform .6s var(--ease-out); }
