:root {
  --bg: #f5f6f8;
  --bg-soft: #eceef2;
  --card: #ffffff;
  --border: #e3e6ec;
  --border-strong: #d3d7e0;
  --text: #14171f;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --bg-soft: #151820;
    --card: #171a22;
    --border: #262b36;
    --border-strong: #333a48;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent: #3b82f6;
    --accent-ink: #ffffff;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body { min-height: 100dvh; }

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.06s, opacity 0.15s;
  user-select: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: var(--border-strong); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-soft); }
.btn.block { width: 100%; padding: 11px 14px; }
.btn.icon {
  padding: 4px 8px; border: 0; background: transparent; color: var(--muted);
  font-size: 18px; line-height: 1; border-radius: 8px;
}
.btn.icon:hover { background: var(--bg-soft); color: var(--text); }

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.logo { margin-bottom: 12px; }
.field { display: block; margin: 18px 0 12px; }
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.error { color: var(--danger); font-size: 13px; min-height: 20px; margin: 10px 0 0; }

/* ---------- shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 16px calc(48px + env(safe-area-inset-bottom));
}

/* ---------- composer ---------- */

.composer {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 12px 10px;
}
.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.55;
  padding: 4px 4px 0;
  min-height: 44px;
  max-height: 40vh;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.composer-actions .hint { font-size: 12px; color: var(--muted); }
.spacer { flex: 1; }

/* ---------- uploads ---------- */

.uploads { display: grid; gap: 8px; margin-top: 10px; }
.upload {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
}
.upload-top {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.upload-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-status { color: var(--muted); font-variant-numeric: tabular-nums; }
.upload.error .upload-status { color: var(--danger); }
.bar {
  height: 3px;
  margin-top: 7px;
  border-radius: 3px;
  background: var(--bg-soft);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.18s ease-out;
}
.upload.error .bar > i { background: var(--danger); }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 4px; margin: 16px 0 10px; }
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }

/* ---------- items ---------- */

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.item-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.item-head .kind { font-weight: 600; letter-spacing: 0.02em; }
.item-head .time { margin-left: auto; font-variant-numeric: tabular-nums; }

.text-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  margin: 0;
}
.text-body.clamp {
  max-height: 340px;
  overflow: hidden;
  position: relative;
}
.text-body.clamp::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 52px;
  background: linear-gradient(transparent, var(--card));
}

.file-card { display: flex; align-items: center; gap: 12px; }
.file-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  text-transform: uppercase;
}
.file-meta { min-width: 0; flex: 1; }
.file-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  text-decoration: none;
}
.file-name:hover { color: var(--accent); }
.file-sub { font-size: 12px; color: var(--muted); }

.thumb {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 10px;
  margin-top: 8px;
  background: var(--bg-soft);
}

.item-actions { display: flex; gap: 4px; align-items: center; }
.item-actions .btn.icon { font-size: 13px; padding: 5px 9px; color: var(--muted); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 14px;
}
.sentinel { height: 1px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: #14171f;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  backdrop-filter: blur(2px);
}
.drop-card {
  background: var(--accent);
  color: #fff;
  padding: 14px 22px;
  border-radius: 14px;
  font-weight: 600;
  box-shadow: 0 12px 40px rgba(37, 99, 235, 0.35);
}

@media (max-width: 480px) {
  .wrap { padding: 14px 12px 40px; }
  .composer-actions .hint { display: none; }
  .btn { padding: 8px 12px; }
}
