:root {
  --bg: #0f1117;
  --panel: #181b24;
  --panel-2: #20242f;
  --line: #2b3040;
  --text: #e7e9ee;
  --muted: #9aa1b1;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --ok: #35c98a;
  --err: #ff6b6b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --glow: #1a2030;
}

/* ---------- daytime (light) theme ---------- */
[data-theme="light"] {
  --bg: #f3f6fc;
  --panel: #ffffff;
  --panel-2: #eef2f9;
  --line: #d7deec;
  --text: #1d2230;
  --muted: #5c6678;
  --accent: #3b6cff;
  --accent-2: #7c5cff;
  --ok: #149a64;
  --err: #d64545;
  --shadow: 0 10px 30px rgba(25, 40, 80, .12);
  --glow: #e4ecfc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, var(--glow) 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .25s ease, color .25s ease;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.logo { font-size: 30px; }
h1 { font-size: 22px; margin: 0; letter-spacing: .5px; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }

.pill {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
}
/* connection status sits on its own line below the scan/code row */
#conn-pill { display: inline-block; margin-top: 8px; white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: rgba(53, 201, 138, .4); }
.pill.warn { color: #f5c451; border-color: rgba(245, 196, 81, .4); }
.pill.err { color: var(--err); border-color: rgba(255, 107, 107, .4); }

.top-right { display: flex; align-items: center; gap: 12px; }
.theme-toggle {
  width: 40px; height: 40px; flex: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text); font-size: 18px; line-height: 1;
  transition: background .15s, transform .1s;
}
.theme-toggle:hover { background: var(--panel-2); }
.theme-toggle:active { transform: scale(.92); }
.lang-select {
  height: 40px; flex: none; cursor: pointer; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text); font: inherit; font-size: 14px;
  transition: background .15s;
}
.lang-select:hover { background: var(--panel-2); }
.lang-select:focus { outline: none; border-color: var(--accent); }

/* ---------- layout ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 24px 40px;
}
/* ---------- single reused panel ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- mode switch (Receive | Send) ---------- */
.mode-switch {
  display: flex; gap: 6px; padding: 5px; margin-bottom: 22px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
}
.mode-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; border: none; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  transition: background .15s, color .15s;
}
.mode-btn span { font-size: 18px; }
.mode-btn:not(.active):hover { color: var(--text); }
.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; box-shadow: var(--shadow);
}
.mode-body { animation: fade .2s ease; }

h2 { font-size: 18px; font-weight: 600; margin: 0 0 16px; display: flex; align-items: center; gap: 9px; }
.h-icon { font-size: 20px; }
.fineprint { color: var(--muted); font-size: 12.5px; text-align: center; margin: 6px 0 0; line-height: 1.6; }

/* ---------- dropzone ---------- */
/* shared file window (send: click to add · receive: click a file to download) */
.filebox {
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--panel-2); padding: 12px; margin: 14px 0; min-height: 180px;
  cursor: default; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column;
}
.filebox.drag { border-color: var(--accent); background: var(--panel); }
.filebox.receiving { border-style: solid; }
.filebox-files { flex: 1; min-height: 70px; overflow-y: auto; }
.filebox:not(.receiving) .filebox-files { cursor: pointer; }   /* only the area above the divider */
.filebox-hint { text-align: center; color: var(--muted); margin: 32px 0 20px; font-size: 14px; }
/* bottom composer: a paste/clear toolbar (top-right, outside the box) above the
   text input, with the ➕ "add as item" button beside the input */
.composer {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 10px; padding-top: 34px; border-top: 1px solid var(--line);  /* top band holds the tab buttons */
}
/* tools float just ABOVE the box's top-right corner — the textarea border stays fully visible */
.composer-tools { position: absolute; bottom: 100%; right: 52px; margin-bottom: -1px; z-index: 0; display: flex; gap: 6px; }   /* shifted left by ~one button width; box's top border overlaps the buttons' bottom edge */
.composer-tool {
  height: 24px; padding: 0 9px; cursor: pointer; font-size: 12px; line-height: 1; white-space: nowrap;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 0;
  background: var(--panel); color: var(--muted);
  transition: color .15s, border-color .15s, background .15s;
}
.composer-tool:hover { color: var(--text); border-color: var(--accent); background: var(--panel-2); }
.composer-row { position: relative; display: flex; align-items: flex-end; gap: 8px; }
.composer-btn {
  flex: none; width: 40px; height: 40px; cursor: pointer; font-size: 18px; line-height: 1;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text);
  transition: background .15s, border-color .15s, transform .1s;
}
.composer-btn:hover { background: var(--panel-2); border-color: var(--accent); }
.composer-btn:active { transform: scale(.92); }
.composer-text {
  position: relative; z-index: 1;   /* sit above the tab buttons so the box border covers their bottom edge */
  flex: 1; min-width: 0; box-sizing: border-box; resize: none; overflow-y: auto;
  min-height: 84px; max-height: 160px; padding: 9px 10px; font: inherit;   /* ~3 lines tall by default */
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  scrollbar-width: none;            /* hide the scrollbar (still scrollable) — Firefox */
}
.composer-text::-webkit-scrollbar { display: none; }   /* hide it — Chrome/Safari */
.composer-text:focus { outline: none; border-color: var(--accent); }
.filebox.receiving .composer { display: none; }   /* receive mode: window shows files only */
/* relay (stealth) mode — small, unobtrusive icon in the header; grey when off,
   accent-colored when on. State is toggled by adding the .on class. */
.relay-btn {
  flex: none; width: 30px; height: 30px; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted); opacity: .55;
  transition: color .15s, opacity .15s;
}
.relay-btn svg { width: 16px; height: 16px; }
.relay-btn:hover { opacity: 1; }
.relay-btn.on { color: var(--accent); opacity: 1; }
.filebox .file-list { margin: 0; }
.filebox .file-row { background: var(--panel); }
.file-row.clickable { cursor: pointer; }
.file-row.clickable:hover { border-color: var(--accent); }
.fi-act { font-size: 13px; color: var(--accent); min-width: 30px; text-align: right; }
.file-row.fi-done .fi-act { color: var(--ok); }
.muted { color: var(--muted); font-size: 13px; }
/* received text shown inline in the window (auto-displayed, copyable) */
.file-row.text-card { display: block; }
.text-card .tc-meta { width: 100%; }
.text-card .recv-text {
  width: 100%; min-height: 64px; margin: 6px 0 8px; resize: vertical;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; font: inherit; font-size: 13px;
}
.text-card .copy-text { padding: 6px 14px; font-size: 13px; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* ---------- file list ---------- */
.file-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 5px; }
.file-row {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px;
}
.file-row .fi-icon { font-size: 16px; }
.file-row .fi-meta { flex: 1; min-width: 0; }
.file-row .fi-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-row .fi-size { font-size: 11px; color: var(--muted); }
.file-row .fi-edit {
  flex: none; background: none; cursor: pointer; white-space: nowrap;
  font-size: 12px; line-height: 1; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 6px; color: var(--muted);
  transition: color .15s, border-color .15s;
}
.file-row .fi-edit:hover { color: var(--text); border-color: var(--accent); }
.file-row .fi-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.file-row .fi-remove:hover { color: var(--err); }
.file-list.selectable .file-row { cursor: pointer; }
.file-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

/* per-row progress */
.fi-bar { height: 3px; border-radius: 999px; background: var(--line); margin-top: 4px; overflow: hidden; }
.fi-bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }
.fi-pct { font-size: 11px; color: var(--muted); margin-left: 8px; min-width: 56px; text-align: right; }
.fi-done .fi-pct { color: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 12px 20px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  transition: transform .1s, opacity .15s, background .15s;
}
.btn:hover { background: var(--panel); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; margin-top: 8px; }

/* ---------- code ---------- */
.code-panel, .code-entry { margin-top: 16px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 20px; text-align: center; }
.code-display {
  /* scales with viewport so all 5 digits fit even on narrow portrait phones */
  font-size: clamp(32px, 12vw, 52px); font-weight: 700;
  letter-spacing: clamp(6px, 2.2vw, 14px); padding-left: clamp(6px, 2.2vw, 14px);
  margin: 4px 0 14px; color: var(--accent);
  font-variant-numeric: tabular-nums; cursor: pointer;
  max-width: 100%; white-space: nowrap; overflow: hidden;
}
.code-display.copied { color: var(--ok); }
/* receive card: status + scan + code + connect on one row, plus the code error */
.recv-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.recv-box .status.error { margin: 8px 0 0; min-height: 0; }
.recv-box .status.error:empty { display: none; }   /* no empty gap inside the card */
/* compact one-row receive: [status] [scan] [code] [connect] */
.recv-row { display: flex; align-items: stretch; gap: 8px; }
.icon-btn { flex: none; width: 48px; padding: 0; display: flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 22px; height: 22px; }
.code-input {
  flex: 1; min-width: 0;
  font-size: 26px; letter-spacing: 8px; padding-left: 8px; padding-right: 8px;
  text-align: center; text-indent: 8px;   /* text-indent = letter-spacing, offsets the trailing gap so digits stay centered */
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.code-input:focus { outline: none; border-color: var(--accent); }
.code-input-wrap { flex: 1; min-width: 0; display: flex; }
#connect-btn { flex: none; }

/* shareable URL row (above the code) */
.share-link-row { display: flex; gap: 8px; margin-bottom: 14px; }
.share-link {
  flex: 1; min-width: 0; font-size: 13px; padding: 10px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.share-link:focus { outline: none; border-color: var(--accent); }
#copy-link-btn { flex: none; white-space: nowrap; }

/* QR shown to the sender */
.qr-box { display: flex; justify-content: center; margin: 14px 0 4px; }
.qr-box canvas {
  width: 180px; height: 180px; image-rendering: pixelated;
  background: #fff; padding: 8px; border-radius: 10px;
}

/* camera scanner modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .65);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px; width: 100%; max-width: 360px; text-align: center;
}
.modal-title { margin: 0 0 14px; font-weight: 600; }
#scan-video {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  background: #000; border-radius: 12px;
}

/* received-text viewer */
#text-view {
  width: 100%; min-height: 160px; resize: vertical; margin-bottom: 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: inherit;
}

.select-actions { display: flex; gap: 16px; margin-top: 10px; font-size: 13px; }

.status { font-size: 14px; color: var(--muted); margin-top: 14px; }
.status.error { color: var(--err); min-height: 18px; }
.status.ok { color: var(--ok); }
.diag { font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); word-break: break-all; min-height: 0; margin-top: 4px; }

.progress-area { margin-top: 16px; text-align: left; }

/* ---------- footer ---------- */
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.foot span { color: var(--text); font-weight: 600; }
.foot-sep { color: var(--muted); margin: 0 8px; }
.foot-link {
  color: var(--muted); font-size: 12px; font-family: inherit; text-decoration: none;
  background: none; border: none; padding: 0; cursor: pointer; transition: color .15s;
}
.foot-link:hover { color: var(--text); }

/* terms-of-service modal: wider, scrollable, left-aligned body */
.terms-card { max-width: 640px; max-height: 84vh; display: flex; flex-direction: column; }
.terms-body {
  text-align: left; overflow-y: auto; padding-right: 4px; margin-bottom: 14px;
  font-size: 13.5px; line-height: 1.7; color: var(--text);
}
.terms-body h3 { font-size: 14px; font-weight: 600; margin: 18px 0 6px; color: var(--text); }
.terms-body h3:first-of-type { margin-top: 8px; }
.terms-body p { margin: 0 0 8px; }
.terms-body .terms-meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.terms-body strong { font-weight: 600; }

.hidden { display: none !important; }

@media (max-width: 560px) {
  .choices { grid-template-columns: 1fr; }
  /* .code-display now scales via clamp(), no fixed override needed here */
  .code-input {
    font-size: clamp(16px, 5vw, 22px);
    letter-spacing: clamp(2px, 1vw, 4px);
    text-indent: clamp(2px, 1vw, 4px);   /* match letter-spacing to re-center */
    padding-left: 6px; padding-right: 6px;
  }
  /* narrower side padding on portrait so 5 digits still fit between the ✕ and the left edge */
  /* let the header wrap so the status pill (e.g. "连接已断开") is never clipped */
  .top { padding: 14px 16px; flex-wrap: wrap; row-gap: 8px; }
  .top-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .pill { white-space: normal; }
}
