:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f7f7fa;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --faint: #aeaeb2;
  --line: rgba(60, 60, 67, 0.13);
  --accent: #0a7aff;
  --accent-press: #0062d6;
  --accent-soft: rgba(10, 122, 255, 0.12);
  --danger: #ff3b30;
  --ok: #30c85a;
  --chip: #e6e6eb;
  --overlay: rgba(0, 0, 0, 0.32);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 6px 20px rgba(0, 0, 0, 0.05);
  --sheet-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #232326;
    --text: #f2f2f7;
    --muted: #98989f;
    --faint: #636366;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #0a84ff;
    --accent-press: #3d9bff;
    --accent-soft: rgba(10, 132, 255, 0.2);
    --chip: #2c2c2e;
    --overlay: rgba(0, 0, 0, 0.55);
    --shadow: none;
    --sheet-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 96px) calc(var(--safe-left) + 16px);
}
.boot { padding: 40vh 0; text-align: center; color: var(--faint); font-weight: 600; letter-spacing: 0.02em; }

/* ---------- icons ---------- */
.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ic svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ic.big { width: 44px; height: 44px; }
.ic.sm { width: 18px; height: 18px; }

/* ---------- header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -16px;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.top { margin-top: calc(-1 * var(--safe-top) - 6px); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.status { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); transition: background 0.3s; }
.status.on { background: var(--ok); }
.top-actions { display: flex; gap: 4px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  text-decoration: none;
  flex: none;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn:active { opacity: 0.6; }
.icon-btn.muted { color: var(--muted); }
.icon-btn.danger { color: var(--danger); }

/* ---------- tabs (segmented) ---------- */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  margin: 4px 0 12px;
  border-radius: 10px;
  background: var(--chip);
}
.tabs button {
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
  background: transparent;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.tabs button[aria-selected="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.tabs .count { color: var(--muted); font-weight: 500; margin-left: 4px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0 10px;
  height: 38px;
  border-radius: 10px;
  background: var(--chip);
  color: var(--muted);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; }
.search input::-webkit-search-cancel-button { opacity: 0.5; }
.sort {
  height: 38px;
  max-width: 46%;
  padding: 0 30px 0 10px;
  border: 0;
  border-radius: 10px;
  background: var(--chip) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  font-size: 15px;
  -webkit-appearance: none;
  appearance: none;
}

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 0;
  border-radius: 999px;
  padding: 6px 13px;
  background: var(--chip);
  font-size: 14px;
  font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }

/* ---------- list ---------- */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list:empty { display: none; }
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 8px 10px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 68px; border-top: 1px solid var(--line); }
.row.note + .row.note::before { left: 14px; }
.row:hover { background: var(--card-2); }
.row:active { background: var(--chip); }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.info { flex: 1; min-width: 0; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { margin-top: 2px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snippet {
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.row.note { padding-left: 14px; }
.row.note .name { font-weight: 600; }

.thumb {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  overflow: hidden;
  background: #8e8e93;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.c-media { background: linear-gradient(135deg, #ff9f0a, #ff375f); }
.c-doc { background: linear-gradient(135deg, #0a84ff, #5e5ce6); }
.c-audio { background: linear-gradient(135deg, #bf5af2, #ff2d55); }
.c-archive { background: linear-gradient(135deg, #a2845e, #7d6448); }
.c-code { background: linear-gradient(135deg, #30b0c7, #34c759); }
.c-other { background: linear-gradient(135deg, #8e8e93, #636366); }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty .ic.big { color: var(--faint); margin-bottom: 10px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

.summary { margin: 10px 4px 0; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- uploads ---------- */
.uploads { display: grid; gap: 8px; margin-bottom: 10px; }
.upload {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.upload .info .name { font-weight: 500; }
.bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--chip); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--accent); transition: width 0.15s; }
.upload.error .bar > i { background: var(--danger); }
.upload.done .bar > i { background: var(--ok); }
.upload .meta.err { color: var(--danger); }

/* ---------- bottom action bar ---------- */
.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 16px);
  background: linear-gradient(to top, var(--bg) 55%, color-mix(in srgb, var(--bg) 0%, transparent));
  pointer-events: none;
}
.actionbar > * { pointer-events: auto; }
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 220px;
  height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 25px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  box-shadow: 0 6px 18px rgba(10, 122, 255, 0.35);
}
.primary:active { background: var(--accent-press); transform: scale(0.98); }
.primary:disabled { opacity: 0.5; }
.primary.wide { width: 100%; }

/* ---------- generic buttons ---------- */
.btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 14px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--chip);
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.45; }
.btn.danger { color: var(--danger); }
.btn.solid { background: var(--accent); color: #fff; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 4px; font-size: 17px; }

/* ---------- sheets ---------- */
.sheet-root { position: fixed; inset: 0; z-index: 20; }
.backdrop { position: absolute; inset: 0; background: var(--overlay); opacity: 0; transition: opacity 0.2s; }
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100% - var(--safe-top) - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(var(--safe-bottom) + 18px);
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  box-shadow: var(--sheet-shadow);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet::before { content: ""; display: block; width: 36px; height: 5px; margin: 0 auto 10px; border-radius: 3px; background: var(--faint); opacity: 0.6; }
.sheet.full { top: calc(var(--safe-top) + 10px); display: flex; flex-direction: column; overflow: hidden; padding-bottom: calc(var(--safe-bottom) + 8px); }
.sheet-root.open .backdrop { opacity: 1; }
.sheet-root.open .sheet { transform: none; }
@media (min-width: 760px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 600px; max-height: 86vh; border-radius: 16px; transform: translate(-50%, -46%); opacity: 0; transition: transform 0.22s, opacity 0.22s; padding-bottom: 18px; }
  .sheet::before { display: none; }
  .sheet.full { top: 50%; height: 80vh; }
  .sheet-root.open .sheet { transform: translate(-50%, -50%); opacity: 1; }
}
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 19px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .meta { white-space: normal; }

.preview { margin: 6px 0 4px; border-radius: 12px; overflow: hidden; background: var(--card); display: grid; place-items: center; }
.preview img, .preview video { display: block; max-width: 100%; max-height: 58vh; margin: 0 auto; }
.preview audio { width: 100%; margin: 14px; }
.preview pre { width: 100%; max-height: 50vh; overflow: auto; margin: 0; padding: 12px 14px; font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- groups (settings) ---------- */
.group-title { margin: 20px 4px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.group { background: var(--card); border-radius: 12px; overflow: hidden; }
.item { position: relative; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 14px; }
.item + .item::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--line); }
.item .grow { flex: 1; min-width: 0; }
.item .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.hint { margin: 8px 4px 0; font-size: 13px; color: var(--muted); }
.hint code, .steps code { font: 12.5px ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--chip); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--chip); transition: background 0.2s; pointer-events: none; }
.switch span::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.25); transition: transform 0.2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.pair-code { font: 700 34px/1.1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.08em; text-align: center; padding: 14px 0 6px; }
.qr { display: block; width: 200px; height: 200px; margin: 6px auto; background: #fff; border-radius: 12px; padding: 8px; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret input { flex: 1; min-width: 0; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card-2); font: 13px ui-monospace, SFMono-Regular, Consolas, monospace; }
.steps { margin: 8px 0 0; padding-left: 22px; font-size: 14.5px; }
.steps li { margin: 6px 0; }

/* ---------- note editor ---------- */
.note-editor { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.note-bar { display: flex; align-items: center; gap: 4px; padding-bottom: 6px; }
.note-status { flex: 1; text-align: center; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-status.warn { color: var(--danger); }
.note-ta {
  flex: 1;
  min-height: 0;
  width: 100%;
  resize: none;
  border: 0;
  outline: 0;
  padding: 14px;
  border-radius: 12px;
  background: var(--card);
  font-size: 17px;
  line-height: 1.5;
}
.conflict { margin-bottom: 8px; padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--danger) 14%, var(--card)); font-size: 14px; }
.conflict .btns { margin-top: 8px; }

/* ---------- drag & drop ---------- */
.dropzone {
  position: fixed;
  inset: 12px;
  z-index: 30;
  display: none;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 24px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
}
.dropzone.on { display: grid; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 84px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  padding: 11px 16px;
  border-radius: 14px;
  background: #2c2c2e;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  pointer-events: none;
}
.toast.show { transform: none; opacity: 1; pointer-events: auto; }
.toast button { flex: none; border: 0; background: none; color: #64d2ff; font-weight: 600; padding: 4px 0; }

/* ---------- pairing ---------- */
.pair-wrap { max-width: 420px; margin: 0 auto; padding-top: 9vh; text-align: center; }
.pair-wrap > img { width: 84px; height: 84px; border-radius: 19px; box-shadow: 0 10px 30px rgba(10, 122, 255, 0.3); }
.pair-wrap h1 { margin: 16px 0 6px; font-size: 30px; letter-spacing: -0.02em; }
.pair-wrap > p { margin: 0 0 22px; color: var(--muted); }
.pair-card { display: grid; gap: 10px; padding: 16px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); text-align: left; }
.pair-card label { font-size: 13px; color: var(--muted); margin: 0 2px -4px; }
.field { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-2); font-size: 17px; outline: 0; }
.field:focus { border-color: var(--accent); }
.field.code { text-align: center; font: 600 24px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.12em; text-transform: uppercase; }
.error { color: var(--danger); font-size: 14px; text-align: center; }
.pair-help { margin-top: 18px; font-size: 14px; color: var(--muted); text-align: left; }
.pair-help ol { padding-left: 20px; margin: 6px 0; }
