:root {
  /* Midnight theme, refined -- richer surfaces, a proper elevation scale
     via shadows, and a wider radius so cards/sheets/buttons read as
     "layers" instead of flat bordered boxes. */
  --blue: #4f9dff;
  --blue-strong: #3b82f6;
  --blue-tint: rgba(79, 157, 255, 0.14);
  --bg: #0c0e12;
  --card: #181c22;
  --card-2: #1f242c;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f2f4f7;
  --muted: #8b93a3;
  --danger: #fb7185;
  --danger-tint: rgba(251, 113, 133, 0.14);
  --on-blue: #06131f;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: light) {
  :root {
    --blue: #2f6fed;
    --blue-strong: #2563eb;
    --blue-tint: rgba(47, 111, 237, 0.1);
    --bg: #f3f5f8;
    --card: #ffffff;
    --card-2: #f3f5f8;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.16);
    --text: #161a20;
    --muted: #667085;
    --danger: #e11d48;
    --danger-tint: rgba(225, 29, 72, 0.08);
    --on-blue: #ffffff;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
    --shadow-lg: 0 20px 56px rgba(15, 23, 42, 0.16);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.screen { height: 100%; }
.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
button:active { transform: scale(0.97); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* Auth screen */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(600px 400px at 50% -10%, var(--blue-tint), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.auth-card p { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
#passphrase-input, #device-name-input {
  width: 100%;
  font-size: 16px;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  margin-bottom: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#passphrase-input:focus, #device-name-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-tint);
}
#pair-submit {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--blue), var(--blue-strong));
  color: var(--on-blue);
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(79, 157, 255, 0.35);
  margin-top: 6px;
}
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* App screen */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: env(safe-area-inset-top) 14px 10px 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
#devices-btn {
  border: none;
  background: none;
  font-size: 19px;
  line-height: 1;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
#devices-btn:hover, #logout-btn:hover { background: var(--card-2); color: var(--text); }
#breadcrumbs {
  font-size: 15px;
  font-weight: 500;
  overflow-x: auto;
  white-space: nowrap;
  flex: 1;
}
#breadcrumbs span {
  cursor: pointer;
  color: var(--blue);
}
#breadcrumbs span.current {
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: default;
}
#breadcrumbs .sep { color: var(--muted); margin: 0 4px; }
#logout-btn {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* Persistent toolbar -- replaces pcbridge's floating +/action-sheet/
   select-bar pattern with a single always-visible row, since the
   floating buttons weren't discoverable enough. */
#toolbar {
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
}
.toolbar-row button {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.toolbar-row button:hover { background: var(--card-2); }
.toolbar-row button.danger { color: var(--danger); }
.toolbar-row button.danger:hover { background: var(--danger-tint); }
.toolbar-icon { font-size: 16px; line-height: 1; }
.toolbar-spacer { flex: 1; }
#select-count { font-size: 13px; color: var(--muted); font-weight: 600; padding: 0 6px; white-space: nowrap; }

/* Narrow phones: icons only, or "New folder"/"Upload"/"Download"/etc next
   to each other overflow the row. */
@media (max-width: 420px) {
  .toolbar-label { display: none; }
  .toolbar-row button { padding: 9px; }
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.row {
  display: flex;
  align-items: center;
  padding: 10px 10px;
  margin-bottom: 3px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.row:hover { background: var(--card-2); }
.row .icon {
  font-size: 18px;
  margin-right: 12px;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--card-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.row:hover .icon { background: var(--bg); }
.row .name { flex: 1; font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 12px; color: var(--muted); margin-left: 8px; white-space: nowrap; }
.row .row-checkbox {
  width: 20px;
  height: 20px;
  margin-right: 12px;
  flex-shrink: 0;
  accent-color: var(--blue);
}
.row.selected { background: var(--blue-tint); border-color: var(--blue); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 70px 20px;
  font-size: 14px;
}

/* Right-click (desktop) / long-press (touch) context menu -- positioned
   at the click/touch point via JS (left/top set inline), not centered
   like the other sheets. */
.context-menu {
  position: fixed;
  z-index: 30;
  min-width: 170px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop-in 0.12s ease;
  transform-origin: top left;
}
.context-menu button {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.context-menu button:last-child { border-bottom: none; }
.context-menu button.danger { color: var(--danger); }
.context-menu button:hover { background: var(--card-2); }

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

#drop-hint {
  position: fixed;
  inset: 0;
  background: rgba(79, 157, 255, 0.12);
  backdrop-filter: blur(2px);
  border: 3px dashed var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--blue);
  z-index: 8;
  pointer-events: none;
}

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.sheet-inner {
  background: var(--card);
  width: 100%;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom)) 0;
  box-shadow: var(--shadow-lg);
  animation: slide-up 0.18s ease;
}
@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-title {
  padding: 14px 20px;
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet button {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.sheet button:hover { background: var(--card-2); }
.sheet button.danger { color: var(--danger); }
.sheet button:last-child { border-bottom: none; color: var(--muted); font-weight: 600; }

#upload-progress {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  z-index: 15;
}
#upload-progress-bar {
  height: 5px;
  background: linear-gradient(90deg, var(--blue), var(--blue-strong));
  border-radius: 3px;
  width: 0%;
  transition: width 0.2s;
  margin-bottom: 8px;
}
#upload-progress-text { font-size: 12px; color: var(--muted); font-weight: 500; }

/* Paired devices drawer */
#device-drawer {
  align-items: stretch;
  justify-content: flex-start;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
.drawer-inner {
  background: var(--card);
  width: min(320px, 84vw);
  height: 100%;
  margin-right: auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 16px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slide-right 0.18s ease;
}
@keyframes slide-right {
  from { transform: translateX(-12px); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 16px;
}
.drawer-header button {
  border: none;
  background: none;
  font-size: 16px;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.drawer-header button:hover { background: var(--card-2); color: var(--text); }
#device-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow-y: auto;
}
.device-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--card-2);
}
.device-row.this-device {
  border-color: var(--blue);
  background: var(--blue-tint);
}
.device-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.device-row-info { flex: 1; min-width: 0; }
.device-row-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.current-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 1px 5px;
  margin-left: 4px;
}
.device-row-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.device-row-remove {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.device-row-remove:hover { background: var(--danger-tint); color: var(--danger); }
.device-section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 4px 0 2px 2px;
}
