:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f1f0ec;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e0db;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --accent-soft: #e7ecfd;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1e1e21;
    --surface-2: #26262a;
    --text: #ececef;
    --muted: #9a9aa1;
    --border: #313136;
    --accent: #7b93ff;
    --accent-text: #0c1233;
    --accent-soft: #1f2747;
    --danger: #ff6b6b;
    --ok: #69db7c;
    --warn: #f0b429;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { line-height: 1.25; margin: 0; }
a { color: var(--accent); }
p { margin: 0; }
kbd { font-family: var(--mono); font-size: 0.8em; padding: 0 0.3em; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--danger); margin-top: 1rem; }
.stack { display: grid; gap: 0.9rem; }
.row-between { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.spacer { flex: 1; }
.offscreen { position: fixed; left: -9999px; top: 0; }

.icon { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- Buttons and fields ---------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.small-btn { min-height: 2rem; padding: 0.25rem 0.75rem; font-size: 0.875rem; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: grid; gap: 0.35rem; font-weight: 550; font-size: 0.9rem; }
input[type="email"], input[type="text"], textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  font-size: 16px; /* Stops iOS zooming on focus. */
}
input:focus, textarea:focus, .btn:focus-visible, .act:focus-visible, .link:focus-visible, .image-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; line-height: 1.45; }
.pin-input { font-family: var(--mono); font-size: 1.6rem !important; letter-spacing: 0.4em; text-align: center; }

/* ---- Loading and sign in ---------------------------------------------------- */

.loading { display: grid; place-items: center; min-height: 100dvh; }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 2rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; margin-bottom: 1.5rem; }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; margin-top: 0.4rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

.brand { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.brand h1 { font-size: 1.15rem; letter-spacing: -0.01em; }
.brand-lg h1 { font-size: 1.5rem; }
.logo { width: 1.6rem; height: 1.6rem; fill: var(--accent); flex: none; }
.brand-lg .logo { width: 2rem; height: 2rem; }

/* ---- Top bar ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right), calc((100% - 1200px) / 2)) 0.6rem max(1rem, env(safe-area-inset-left), calc((100% - 1200px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.live { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.live[data-status="live"] { background: var(--ok); }
.live[data-status="offline"] { background: var(--danger); }

.menu-wrap { position: relative; }
.user-name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  flex: none;
}
.avatar.sm { width: 1.5rem; height: 1.5rem; font-size: 0.65rem; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 13rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.15);
}
.menu-email { padding: 0.4rem 0.7rem 0.5rem; border-bottom: 1px solid var(--border); margin-bottom: 0.3rem; overflow-wrap: anywhere; }
.menu button {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }

/* ---- Board --------------------------------------------------------------------- */

.board {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.nudge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border-radius: var(--radius);
}
.nudge-actions { display: flex; gap: 0.5rem; }

.composer {
  margin-bottom: 1.25rem;
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.composer textarea { border: 0; padding: 0.4rem 0.5rem; resize: none; min-height: 3.2rem; max-height: 50vh; background: transparent; }
.composer textarea:focus { outline: none; }
.composer:focus-within { border-color: var(--accent); }
.composer-bar { display: flex; align-items: center; gap: 0.5rem; padding-top: 0.35rem; }
.composer-bar .hint { flex: 1; text-align: right; }
.composer-bar label.btn { cursor: pointer; }
@media (max-width: 560px) {
  .composer-bar .hint { visibility: hidden; }
}
@media (hover: none) {
  .composer-bar .hint { visibility: hidden; }
}

.items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
  gap: 1rem;
  align-items: start;
}

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.enter { animation: enter 0.25s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .card.enter { animation: none; } }

.card-head { display: flex; align-items: center; gap: 0.45rem; padding: 0.6rem 0.8rem 0; font-size: 0.85rem; min-width: 0; }
.card-by { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { margin-left: auto; white-space: nowrap; font-size: 0.8rem; }
.card-body { padding: 0.55rem 0.8rem; min-width: 0; }

.text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  max-height: 16.5em;
  overflow: hidden;
}
.text.clamped:not(.expanded) { mask-image: linear-gradient(to bottom, #000 75%, transparent); -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent); }
.text.expanded { max-height: none; }
.show-more { margin-top: 0.35rem; }

.card-image .card-body { padding: 0.55rem 0 0; }
.image-btn { display: block; width: 100%; padding: 0; border: 0; background: var(--surface-2); cursor: zoom-in; }
.image-btn img { display: block; width: 100%; height: auto; max-height: 420px; object-fit: contain; }

.file {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}
.file:hover { background: var(--accent-soft); }
.file-icon { position: relative; display: grid; place-items: center; color: var(--accent); flex: none; }
.file-icon .icon { width: 2.6rem; height: 2.6rem; stroke-width: 1.3; }
.file-ext { position: absolute; bottom: 0.45rem; font-size: 0.5rem; font-weight: 800; letter-spacing: 0.02em; }
.file-meta { display: grid; min-width: 0; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-actions { display: flex; align-items: center; gap: 0.15rem; padding: 0.15rem 0.4rem 0.4rem; margin-top: auto; }
.act {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 2rem;
  padding: 0.25rem 0.55rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  text-decoration: none;
  cursor: pointer;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act.danger:hover { color: var(--danger); }
@media (max-width: 420px) {
  .act span { display: none; }
  .act { min-width: 2.4rem; justify-content: center; }
}

.edit-text { min-height: 120px; font-size: 0.95rem; }
.card-actions .btn + .btn { margin-left: 0.35rem; }

.upload-card .card-body { display: grid; gap: 0.35rem; padding: 0.8rem; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-bar { width: 0; height: 100%; background: var(--accent); transition: width 0.15s; }

.empty { text-align: center; padding: 3rem 1rem; }
.more { display: flex; justify-content: center; margin-top: 1.25rem; }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  pointer-events: none;
}
.drop-overlay div {
  padding: 2rem 3rem;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: var(--surface);
  font-weight: 600;
}

/* ---- Dialogs ------------------------------------------------------------------- */

dialog {
  width: min(480px, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem 0 1.25rem; }
.dialog-head h2 { font-size: 1.15rem; }
.dialog-body { padding: 0.75rem 1.25rem; display: grid; gap: 0.75rem; }
.dialog-foot { display: flex; justify-content: flex-end; padding: 0.5rem 1.25rem 1.25rem; }

.passkey-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.passkey {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.passkey-actions { display: flex; gap: 0.25rem; flex: none; }

.viewer {
  width: auto;
  max-width: calc(100vw - 1rem);
  max-height: calc(100dvh - 1rem);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}
.viewer::backdrop { background: rgb(0 0 0 / 0.85); }
.viewer img { display: block; max-width: calc(100vw - 1rem); max-height: calc(100dvh - 1rem); object-fit: contain; border-radius: 8px; cursor: zoom-out; }
.viewer-close { position: fixed; top: calc(0.5rem + env(safe-area-inset-top)); right: 0.5rem; color: #fff; background: rgb(0 0 0 / 0.4); }
.viewer-close:hover { background: rgb(0 0 0 / 0.6); color: #fff; }

/* ---- Toast --------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.2);
}
.toast-error { background: var(--danger); color: #fff; }
