:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #fff;
  --text: #24272e;
  --muted: #6a707c;
  --border: #e5e7ec;
  --accent: #1666ce;
  --accent-soft: #edf4ff;
  --danger: #bf3535;
  --ok: #22764c;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181a1e;
    --panel: #22252b;
    --text: #edf0f5;
    --muted: #a5acb9;
    --border: #353a44;
    --accent: #83b7ff;
    --accent-soft: #29394e;
    --danger: #ff9696;
    --ok: #86d4a8;
  }
}

* {
  box-sizing: border-box;
}

/* Author display rules must never override the authentication gates. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

button, input {
  font: inherit;
}

button, a, [role="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: .55;
}

button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

button, a {
  transition: background .15s ease, border-color .15s ease;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.link {
  color: var(--accent);
  text-underline-offset: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 16px max(24px, calc((100vw - 1060px) / 2));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
}

.brand-mark, .gate-symbol {
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
  width: 34px;
  height: 34px;
}

.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.conn::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.conn.live {
  color: var(--ok);
}

.conn.down {
  color: var(--danger);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Keep the whole content in one compositing layer on virtualized macOS WebKit. */
.app {
  transform: translateZ(0);
}

.files, .text-share {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.public-note {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin: 0;
}

h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px;
  padding: 16px;
  min-height: 88px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
}

.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.dragover {
  border-style: solid;
}

.dropzone-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 36px;
  color: var(--accent);
  font-size: 26px;
}

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

.dropzone-title {
  font-size: 14px;
  font-weight: 600;
}

.dropzone-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.shortcut {
  white-space: nowrap;
}

.shortcut kbd {
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 11px;
}

.choose-file {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.touch-hint {
  display: none;
}

.files-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 20px 14px;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0 20px 8px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.file-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 40px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
}

.file-icon svg {
  width: 24px;
  height: 24px;
}

.file-main {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-sub {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.file-dl, .text-copy-button {
  flex: 0 0 auto;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.file-dl:hover, .text-copy-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.empty {
  text-align: center;
  padding: 30px 20px 40px;
  color: var(--muted);
  font-size: 13px;
}

.empty-icon {
  display: block;
  margin: 0 auto 12px;
  opacity: .65;
}

.empty p {
  margin: 5px 0 0;
  font-size: 12px;
}

.upload-list {
  list-style: none;
  margin: 0 16px 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-list {
  max-height: 240px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

.upload-list:empty {
  display: none;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
}

.upload-name {
  flex: 1 1 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-bar {
  flex: 1 1 40px;
  min-width: 32px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.upload-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s ease;
}

.upload-status {
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.upload-status.ok {
  color: var(--ok);
}

.upload-status.err {
  color: var(--danger);
}

.upload-action {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 5px;
  font: inherit;
  border-radius: 6px;
}

.upload-action:hover {
  background: var(--accent-soft);
}

.upload-notice {
  display: flex;
  align-items: start;
  gap: 8px;
  font-size: 12px;
  padding: 12px;
  border: 1px solid var(--danger);
  border-radius: 10px;
}

.upload-notice-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.upload-notice-close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.upload-notice-close:hover {
  color: var(--danger);
  background: var(--bg);
}

.text-share {
  padding: 20px;
}

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

.text-share-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.text-copy-button.is-copied {
  color: var(--ok);
}

.text-copy-button.is-error {
  color: var(--danger);
}

.text-continue-button {
  display: none;
}

.text-editor {
  width: 100%;
  min-height: 140px;
  max-height: 340px;
  padding: 12px;
  font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  overflow: auto;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  contain: layout paint style;
  -webkit-user-modify: read-write;
}

.text-editor::-webkit-scrollbar-corner, .text-editor::-webkit-resizer {
  background: var(--bg);
}

.text-editor:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.text-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.text-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  margin-top: 8px;
}

.text-footer .muted {
  font-size: 11px;
}

#text-sync-status.is-error {
  color: var(--danger);
}

.text-pending {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--muted);
  font-size: 12px;
}

.join-page {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.join-card, .pin-card {
  width: 100%;
  max-width: 420px;
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 8px 32px #00000004;
}

.join-card h1 {
  margin: 32px 0 8px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -.5px;
}

.join-intro {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.join-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 28px 0 0;
}

.join-card label {
  font-size: 12px;
  font-weight: 600;
}

.join-card input, .pin-card input {
  width: 100%;
  min-width: 0;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: 550 28px ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: normal;
  text-align: center;
}

.join-card input::placeholder, .pin-card input::placeholder {
  opacity: .4;
  color: var(--muted);
}

.join-card input[aria-invalid="true"], .pin-card input[aria-invalid="true"] {
  border-color: var(--danger);
}

.join-card button, .pin-card button {
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--panel);
  font-size: 14px;
  font-weight: 600;
}

.join-card button:hover, .pin-card button:hover {
  filter: brightness(.94);
}

.pin-gate {
  min-height: calc(100vh - 72px);
  min-height: calc(100svh - 72px);
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.pin-card {
  text-align: center;
}

.gate-symbol {
  width: 48px;
  height: 48px;
  margin: 0 auto 20px;
  border-radius: 14px;
  font-size: 32px;
}

.pin-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 650;
}

.pin-card .muted {
  font-size: 13px;
  margin: 0 0 24px;
}

.pin-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#pairing-request, #connection-retry {
  width: 100%;
}

.pairing-code {
  font: 600 40px ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  padding: 20px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  margin: 20px 0 12px;
}

.pairing-code::before {
  content: "确认码";
  display: block;
  font: 12px -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--muted);
  letter-spacing: 0;
  text-indent: 0;
  margin-bottom: 8px;
}

#pairing-hint {
  font-size: 12px;
  margin-bottom: 0;
}

.pin-error {
  margin: 8px 0 16px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.join-card .pin-error {
  margin: 0;
}

.pairing-home {
  display: inline-block;
  padding: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  text-underline-offset: 4px;
}

@media (max-width: 760px) {
  .topbar {
    padding: 14px 20px;
    min-height: 64px;
  }
  .pin-gate {
    min-height: calc(100svh - 64px);
  }
}

@media (max-width: 380px) {
  .join-card, .pin-card {
    padding: 28px 20px;
  }
  .dropzone {
    padding: 12px;
    gap: 8px;
  }
  .dropzone-icon {
    display: none;
  }
  .text-share {
    padding: 16px;
  }
}

@media (any-pointer: coarse) {
  .touch-hint {
    display: inline;
  }
  .desktop-hint {
    display: none;
  }
  .text-continue-button {
    display: inline-flex;
  }
  .text-copy-button, .file-dl, .upload-action, .upload-notice-close {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
