:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --success: #059669;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #222631;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #2a2f3c;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59, 130, 246, 0.15);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.15);
    --warn: #f59e0b;
    --warn-soft: rgba(245, 158, 11, 0.16);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app-shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 110px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ttl-pill {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-2);
}

.btn-danger-ghost {
  color: var(--danger);
  background: transparent;
  padding: 8px 10px;
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

/* Compose Card */
.compose-card {
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 16px;
}

.compose-card:focus-within {
  border-style: solid;
  border-color: var(--primary);
}

.compose-textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  min-height: 54px;
  max-height: 220px;
  font-size: 15px;
  line-height: 1.5;
}

.compose-textarea::placeholder {
  color: var(--text-muted);
}

.compose-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.compose-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid transparent;
  transition: all 0.15s;
}

.toggle-chip.active {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: rgba(217, 119, 6, 0.35);
}

/* Upload Progress */
.upload-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.upload-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}

.upload-item-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.progress-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.12s linear;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.filter-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
}

.filter-pill.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Stream Cards */
.stream {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.15s;
}

.item-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.item-check {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.item-body {
  flex: 1;
  min-width: 0;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-burn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-kind {
  background: var(--surface-2);
  color: var(--text-muted);
}

.item-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  max-height: 240px;
  overflow-y: auto;
}

.item-text a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.item-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-name {
  font-weight: 500;
  word-break: break-all;
}

.item-thumb {
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  display: block;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

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

/* Selection Floating Bar */
.selection-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 40;
  font-size: 13.5px;
}

.selection-bar.hidden {
  display: none;
}

.selection-bar .btn-share-go {
  background: var(--primary);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
}

/* Mobile Bottom Bar */
.mobile-bar {
  display: none;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px 12px calc(86px + env(safe-area-inset-bottom));
  }
  .hide-mobile {
    display: none !important;
  }
  .mobile-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    z-index: 30;
  }
  .mobile-bar button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border-radius: 10px;
    font-size: 11.5px;
    color: var(--text);
  }
  .mobile-bar button:active {
    background: var(--surface-2);
  }
  .selection-bar {
    bottom: calc(74px + env(safe-area-inset-bottom));
  }
}

/* Drag Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(37, 99, 235, 0.14);
  backdrop-filter: blur(4px);
  border: 3px dashed var(--primary);
  z-index: 100;
  display: none;
  place-items: center;
  pointer-events: none;
}

.drop-overlay.active {
  display: grid;
}

.drop-overlay-box {
  background: var(--surface);
  padding: 24px 36px;
  border-radius: 18px;
  font-size: 17px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: none;
  place-items: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.qr-box {
  display: flex;
  justify-content: center;
  padding: 14px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 12px 0;
}

.pair-code-display {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums;
  padding: 8px 0;
}

.input-field {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
}

.input-field:focus {
  border-color: var(--primary);
}

.form-row {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 120;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
