/* QuickDrop design system — no external fonts or assets */

:root {
  /* 8px spacing grid */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;

  /* Type scale (system stack, tabular nums for metrics) */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 15px;
  --text-lg: 18px;
  --text-xl: 22px;
  --leading: 1.45;
  --tracking-tight: -0.02em;

  /* Dark (default) surfaces + one restrained accent */
  --bg: #0c0d0f;
  --bg-elevated: #14161a;
  --bg-subtle: #1a1d23;
  --bg-hover: #22262e;
  --border: #2a2f38;
  --border-strong: #3a4150;
  --text: #e8eaed;
  --text-muted: #8b93a7;
  --text-faint: #5c6578;
  --accent: #3cb8a0;
  --accent-hover: #48c9af;
  --accent-muted: rgba(60, 184, 160, 0.14);
  --accent-fg: #04241e;

  /* Semantic — status only */
  --ok: #3cb8a0;
  --warn: #d4a017;
  --danger: #e06c75;
  --info: #6b9fd4;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.35);
  --sidebar-w: 220px;
  --touch: 44px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur: 180ms;
  --icon: 24px;
  --stroke: 1.5px;

  /* Fixed chrome heights — keep content scrollable and fully reachable */
  --chrome-bottom-nav: 56px;
  --chrome-devlog: 36px;
  --chrome-safe: env(safe-area-inset-bottom, 0px);
  --chrome-top: env(safe-area-inset-top, 0px);
  --chrome-bottom: calc(
    var(--chrome-bottom-nav) + var(--chrome-devlog) + var(--chrome-safe) + 24px
  );
}

@media (min-width: 860px) {
  :root {
    /* Desktop: no bottom nav, only collapsed Dev Log bar */
    --chrome-bottom: calc(var(--chrome-devlog) + 32px);
  }
}

/* Dev Log slid aside — free the space it was reserving */
html.devlog-docked {
  --chrome-devlog: 0px;
  --chrome-bottom: calc(var(--chrome-bottom-nav) + var(--chrome-safe) + 12px);
}

@media (min-width: 860px) {
  html.devlog-docked {
    --chrome-bottom: 12px;
  }
}

/* Light theme via system preference when theme=system */
@media (prefers-color-scheme: light) {
  :root[data-theme="system"],
  :root:not([data-theme]) {
    --bg: #f4f5f7;
    --bg-elevated: #ffffff;
    --bg-subtle: #eef0f3;
    --bg-hover: #e6e8ec;
    --border: #d8dce3;
    --border-strong: #c0c6d0;
    --text: #12141a;
    --text-muted: #5a6272;
    --text-faint: #8a93a3;
    --accent: #1f8f7a;
    --accent-hover: #187a68;
    --accent-muted: rgba(31, 143, 122, 0.12);
    --accent-fg: #ffffff;
    --ok: #1f8f7a;
    --warn: #a67c00;
    --danger: #c9444f;
    --info: #3d6fa8;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 20px rgba(16, 24, 40, 0.06);
  }
}

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-subtle: #eef0f3;
  --bg-hover: #e6e8ec;
  --border: #d8dce3;
  --border-strong: #c0c6d0;
  --text: #12141a;
  --text-muted: #5a6272;
  --text-faint: #8a93a3;
  --accent: #1f8f7a;
  --accent-hover: #187a68;
  --accent-muted: rgba(31, 143, 122, 0.12);
  --accent-fg: #ffffff;
  --ok: #1f8f7a;
  --warn: #a67c00;
  --danger: #c9444f;
  --info: #3d6fa8;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 20px rgba(16, 24, 40, 0.06);
}

:root[data-theme="dark"] {
  /* keep dark tokens from :root */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  isolation: isolate;
  padding-top: var(--chrome-top);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--bg);
  background-image: url("bg-atmosphere.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.55;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] body::before,
  :root:not([data-theme]) body::before {
    background-image: url("bg-atmosphere-light.jpg");
    opacity: 0.7;
  }
}

:root[data-theme="light"] body::before {
  background-image: url("bg-atmosphere-light.jpg");
  opacity: 0.7;
}

:root[data-theme="dark"] body::before {
  background-image: url("bg-atmosphere.jpg");
  opacity: 0.55;
}

@media (prefers-reduced-motion: reduce) {
  body::before {
    opacity: 0.35;
  }
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ---- Icons ---- */
.icon {
  width: var(--icon);
  height: var(--icon);
  stroke: currentColor;
  stroke-width: var(--stroke);
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.icon-sm {
  width: 18px;
  height: 18px;
}

/* ---- Shell ---- */
.app-shell {
  display: flex;
  align-items: stretch;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  display: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: var(--space-3) var(--space-2);
  padding-bottom: calc(var(--space-3) + var(--chrome-devlog) + 8px);
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
}

@media (min-width: 860px) {
  .sidebar {
    display: flex;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-1);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--accent-muted);
  color: var(--accent);
  display: grid;
  place-items: center;
}

.brand-name {
  font-size: var(--text-lg);
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--touch);
  padding: 0 var(--space-1);
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
    opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.nav-item:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item:active:not(:disabled) {
  transform: scale(0.98);
}

.nav-item.is-active {
  background: var(--accent-muted);
  color: var(--accent);
}

.nav-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tag-soon {
  margin-left: auto;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.sidebar-foot {
  margin-top: auto;
  padding: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Top/sides fluid; bottom clears fixed Dev Log (+ mobile nav) */
  padding:
    clamp(8px, 1.5vh, 28px)
    clamp(16px, 2.5vw, 48px)
    calc(var(--chrome-bottom) + 12px);
}

.view.is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100%;
}

/* Wide screens: two cards fill the window, not a short band at the top */
@media (min-width: 1080px) and (min-height: 761px) {
  #view-transfer.is-active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: var(--space-3);
    row-gap: var(--space-2);
    align-content: stretch;
    flex: 1;
    min-height: 100%;
  }

  #view-transfer > .page-header,
  #view-transfer > #identity-banner,
  #view-transfer > #prompt-area,
  #view-transfer > #send-area,
  #view-transfer > #progress-wrap,
  #view-transfer > #memory-warning,
  #view-transfer > #download-area {
    grid-column: 1 / -1;
  }

  #view-transfer > .panel {
    margin-top: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: clamp(24px, 3vh, 40px);
  }

  #view-transfer > .panel > .stack-gap,
  #view-transfer > .panel > .btn-block {
    margin-top: auto;
  }

  .page-header h1 {
    font-size: 28px;
  }

  input[type="text"],
  select,
  .btn,
  .mono-box {
    min-height: 52px;
  }
}

#view-settings .panel {
  max-width: 720px;
}

.view {
  display: none;
  animation: view-in var(--dur) var(--ease);
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---- Bottom nav (mobile) ---- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 900;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 860px) {
  .bottom-nav {
    display: none;
  }
}

.bottom-nav .nav-item {
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  padding: 6px 4px;
}

/* ---- Surfaces ---- */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow);
}

.panel + .panel {
  margin-top: var(--space-2);
}

.panel-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  /* Keep clear of the fixed version badge */
  padding-right: 88px;
}

@media (max-width: 420px) {
  .page-header {
    padding-right: 0;
    padding-top: 28px;
  }

  .panel {
    padding: var(--space-2);
  }

  .row {
    flex-wrap: wrap;
  }

  .row > .btn {
    flex: 1 1 auto;
  }
}

/* Short desktop windows: tighten so Transfer fits without a page scrollbar */
@media (max-height: 760px) and (min-width: 860px) {
  .page-header {
    margin-bottom: var(--space-2);
  }

  .page-sub {
    display: none;
  }

  .panel {
    padding: var(--space-2);
  }

  .panel + .panel {
    margin-top: var(--space-1);
  }

  .panel-title {
    margin-bottom: var(--space-1);
  }
}

@media (max-height: 620px) and (min-width: 860px) {
  .main {
    padding-top: 6px;
  }

  .page-header h1 {
    font-size: var(--text-lg);
  }

  .hint {
    display: none;
  }
}

.page-header h1 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 650;
  letter-spacing: var(--tracking-tight);
}

.page-sub {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* Always visible in the top-right corner (opens changelog) */
#app-version {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 1100;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-decoration: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

#app-version:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ---- Profile / status ---- */
.profile-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--text-md);
  color: #fff;
  flex-shrink: 0;
}

.profile-meta {
  min-width: 0;
}

.profile-name {
  font-weight: 650;
  margin: 0;
}

.profile-id {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-faint);
  word-break: break-all;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

.peer-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 220px;
  min-height: 32px;
  padding: 0 10px 0 6px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  font-weight: 650;
}

.peer-badge.hidden {
  display: none;
}

.peer-device {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent-muted);
  color: var(--accent);
  flex-shrink: 0;
}

.peer-badge .peer-icon-phone,
.peer-badge .peer-icon-pc {
  display: none;
}

.peer-badge[data-device="phone"] .peer-icon-phone,
.peer-badge[data-device="pc"] .peer-icon-pc {
  display: block;
}

.peer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}

.status-chip[data-state="Waiting"] .status-dot { background: var(--text-faint); }
.status-chip[data-state="Connecting"] .status-dot {
  background: var(--warn);
  animation: pulse-dot 1.1s var(--ease) infinite;
}
.status-chip[data-state="Connected"] .status-dot { background: var(--ok); }
.status-chip[data-state="Sending"] .status-dot { background: var(--info); }
.status-chip[data-state="Done"] .status-dot { background: var(--ok); }
.status-chip[data-state="Declined"],
.status-chip[data-state="Aborted"] .status-dot { background: var(--danger); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

/* Hide raw status text node but keep ID for JS */
#status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---- Forms / controls ---- */
.field-label {
  display: block;
  margin: 0 0 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.row {
  display: flex;
  gap: var(--space-1);
  align-items: stretch;
}

.row > .grow {
  flex: 1;
  min-width: 0;
}

.mono-box {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  word-break: break-all;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--text);
  min-height: var(--touch);
  display: flex;
  align-items: center;
}

input[type="text"],
select {
  width: 100%;
  min-height: var(--touch);
  padding: 0 12px;
  font: inherit;
  font-size: var(--text-md);
  color: var(--text);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

input[type="text"]:focus,
select:focus,
button:focus-visible,
.nav-item:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="text"]::placeholder {
  color: var(--text-faint);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 0 16px;
  font: inherit;
  font-weight: 650;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(224, 108, 117, 0.12);
}

.btn-block {
  width: 100%;
  margin-top: var(--space-1);
}

.stack-gap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.muted {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
}

/* ---- Share link hidden by default ---- */
.share-mask {
  letter-spacing: 0.12em;
  color: var(--text-faint);
}

#qrcode {
  display: none;
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: #fff;
  border-radius: var(--radius-md);
  width: fit-content;
}

#qrcode.is-visible {
  display: flex;
}

/* ---- Drop zone ---- */
#drop-zone {
  position: relative;
  margin-top: var(--space-1);
  padding: 28px var(--space-2) 22px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.04), transparent 62%),
    var(--bg-subtle);
  text-align: center;
  color: var(--text-muted);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

#drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-muted);
  color: var(--text);
}

#drop-zone .hint {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
}

#file-input,
.file-input-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.file-pick {
  position: relative;
  z-index: 1;
  min-width: 140px;
}

.sign-mark {
  display: block;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}

.sign-mark-side {
  width: min(168px, 100%);
  margin: 0 0 10px;
  opacity: 0.92;
}

.sign-mark-share {
  width: min(220px, 70%);
  margin: 18px auto 0;
  opacity: 0.9;
}

.sign-mark-drop {
  width: min(280px, 78%);
  margin: 0 auto 14px;
}

#send-area.hidden,
.hidden {
  display: none !important;
}

/* ---- Progress ---- */
#progress-wrap {
  display: none;
  margin-top: 0;
}

#progress-file {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: 8px;
  word-break: break-word;
}

progress {
  width: 100%;
  height: 10px;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-subtle);
  transition: opacity var(--dur) var(--ease);
}

progress::-webkit-progress-bar {
  background: var(--bg-subtle);
  border-radius: 999px;
}

progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
  transition: width 200ms var(--ease);
}

progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

#progress-text {
  margin-top: 6px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.progress-actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

/* ---- Prompt (unmissable) ---- */
#prompt-area {
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow);
  animation: prompt-in var(--dur) var(--ease);
}

#prompt-area.hidden {
  display: none !important;
}

@keyframes prompt-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

#prompt-text {
  font-weight: 650;
  font-size: var(--text-md);
  margin-bottom: var(--space-1);
}

#prompt-warn {
  color: var(--warn);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

#prompt-warn.hidden {
  display: none !important;
}

.prompt-actions {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

#memory-warning {
  margin-top: var(--space-2);
  padding: 12px;
  background: rgba(212, 160, 23, 0.12);
  color: var(--warn);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  border: 1px solid rgba(212, 160, 23, 0.35);
}

#download-area {
  margin-top: var(--space-2);
}

#download-area a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 16px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 650;
  text-decoration: none;
}

/* ---- Settings ---- */
.settings-block + .settings-block {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.settings-block h2 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-md);
  font-weight: 650;
}

/* ---- Confirm dialog ---- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: var(--space-2);
  animation: view-in var(--dur) var(--ease);
}

.dialog-backdrop.hidden {
  display: none !important;
}

.dialog {
  width: min(400px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: var(--text-lg);
}

.dialog p {
  margin: 0 0 var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
}

/* ---- Dev Log ---- */
#dev-log {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  z-index: 1000;
  background: #12141a;
  color: #d7dbe3;
  font-family: var(--font-mono);
  font-size: 12px;
  border-top: 1px solid #2a2f38;
  transition: width var(--dur) var(--ease);
}

/* Tucked to the corner: only the < tab stays */
#dev-log.is-docked {
  left: auto;
  width: 36px;
}

#dev-log.is-docked #dev-log-toggle,
#dev-log.is-docked #dev-log-panel {
  display: none !important;
}

#dev-log-bar {
  display: flex;
  align-items: stretch;
}

@media (max-width: 859px) {
  #dev-log {
    bottom: calc(var(--chrome-bottom-nav) + var(--chrome-safe) + 4px);
  }
}

#dev-log-toggle {
  margin: 0;
  flex: 1;
  min-width: 0;
  text-align: left;
  background: #1a1d23;
  color: #e8eaed;
  border: none;
  border-radius: 0;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 650;
  font-family: var(--font);
  cursor: pointer;
  min-height: 36px;
}

#dev-log-dock {
  flex: 0 0 36px;
  width: 36px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  border-left: 1px solid #2a2f38;
  background: #1a1d23;
  color: #e8eaed;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
}

#dev-log.is-docked #dev-log-dock {
  border-left: none;
  width: 36px;
  flex-basis: 36px;
}

#dev-log-panel {
  display: none;
  flex-direction: column;
  max-height: 220px;
  padding: 0 8px 8px;
}

#dev-log-panel.is-open {
  display: flex !important;
}

#dev-log-stats {
  padding: 6px 4px;
  color: #8eb6d9;
  border-bottom: 1px solid #2a2f38;
  font-variant-numeric: tabular-nums;
}

#dev-log-entries {
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
  max-height: 140px;
  padding: 4px;
}

#dev-log-entries .info { color: #c8ced8; }
#dev-log-entries .warn { color: #e0c36a; }
#dev-log-entries .error { color: #e06c75; }

#dev-log-actions {
  display: flex;
  gap: 8px;
}

#dev-log-actions button {
  margin-top: 6px;
  padding: 8px 12px;
  min-height: 36px;
  font-size: 12px;
  background: #22262e;
  color: #e8eaed;
  border: 1px solid #3a4150;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
}

.identity-banner {
  display: none;
  margin-bottom: var(--space-2);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(224, 108, 117, 0.4);
  background: rgba(224, 108, 117, 0.1);
  color: var(--danger);
  font-size: var(--text-sm);
}

.identity-banner.is-visible {
  display: block;
}

.mobile-top,
.hint-mobile {
  display: none;
}

/* ---- Phone layout (desktop rules above stay put) ---- */
@media (max-width: 859px) {
  :root {
    --chrome-bottom-nav: 72px;
  }
  .mobile-top {
    display: flex;
    align-items: center;
    min-height: 48px;
    margin: 0 0 4px;
    padding-right: 76px;
  }

  .mobile-top .brand-name {
    font-size: 17px;
  }

  .main {
    padding: 8px 16px calc(var(--chrome-bottom) + 16px);
  }

  .view.is-active {
    min-height: 0;
    flex: 0 0 auto;
  }

  .page-header {
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    padding-top: 0;
    padding-right: 0;
  }

  .header-meta {
    width: 100%;
    margin-left: 0;
  }

  .page-header h1 {
    font-size: 22px;
  }

  .page-sub {
    display: block;
    margin-top: 2px;
    font-size: 13px;
    line-height: 1.35;
  }

  #app-version {
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
  }

  .panel {
    padding: 16px;
    border-radius: 16px;
  }

  .panel + .panel {
    margin-top: 12px;
  }

  .panel-title {
    margin-bottom: 12px;
    font-size: 11px;
  }

  .profile-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 12px;
  }

  .profile-meta {
    overflow: hidden;
  }

  .profile-id {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: normal;
  }

  #copy-code-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 0;
    gap: 0;
  }

  .share-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .share-row > .mono-box {
    grid-column: 1 / -1;
    min-height: 48px;
  }

  .share-row > .btn {
    width: 100%;
    min-height: 48px;
    flex: none;
  }

  .muted {
    line-height: 1.4;
  }

  input[type="text"],
  select,
  .btn-block {
    min-height: 48px;
    font-size: 16px;
  }

  #qrcode.is-visible {
    margin-left: auto;
    margin-right: auto;
  }

  .hint-desktop {
    display: none;
  }

  .hint-mobile {
    display: inline;
  }

  #drop-zone {
    padding: 20px 16px;
  }

  #file-input {
    max-width: none;
    font-size: 16px;
  }

  .prompt-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .prompt-actions .btn {
    min-height: 48px;
  }

  .dialog {
    border-radius: 16px;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .btn {
    width: 100%;
    min-height: 48px;
  }

  .bottom-nav {
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
    backdrop-filter: blur(16px);
  }

  .bottom-nav .nav-item {
    min-height: 52px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 650;
    gap: 3px;
  }

  .bottom-nav .nav-item.is-active {
    background: var(--accent-muted);
    color: var(--accent);
  }
}
