:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-hover: #f0f1f4;
  --text: #16181d;
  --muted: #646b78;
  --border: #e2e4e9;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --accent-soft-text: #3730a3;
  --danger: #b42318;
  --live: #16a34a;
  --waiting: #d97706;
  --shadow: 0 1px 2px rgb(16 18 23 / 0.06);
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101217;
    --surface: #191c22;
    --surface-hover: #22262e;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2b2f38;
    --accent: #8b8ff8;
    --accent-hover: #a3a6fa;
    --accent-text: #101217;
    --accent-soft: #252848;
    --accent-soft-text: #c7c9fd;
    --danger: #f97066;
    --live: #4ade80;
    --waiting: #fbbf24;
    --shadow: none;
  }
}

*,
*::before,
*::after {
  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 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

.muted {
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

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

.btn.danger {
  color: var(--danger);
}

.btn.wide {
  width: 100%;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn[aria-pressed='true'] {
  color: var(--accent);
}

.icon-btn[aria-pressed='true'] svg {
  fill: currentColor;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Form fields */

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 550;
}

.field small {
  font-weight: 400;
}

input[type='text'],
input[type='password'],
input[type='search'],
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming in on focus */
}

input[type='text'],
input[type='password'] {
  min-height: 44px;
  padding: 0 12px;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.form-message {
  min-height: 1.5em;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.form-message.success {
  color: var(--text);
}

.link-btn {
  justify-self: center;
  padding: 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-size: 12px;
  font-weight: 600;
  vertical-align: 1px;
}

/* Sign-in screen */

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(100%, 380px);
  padding: 28px 24px 24px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card .field {
  text-align: left;
}

.auth-card p {
  margin: 0;
}

.auth-logo {
  justify-self: center;
}

/* App layout */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px
    max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 650;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state='live']::before {
  background: var(--live);
}

.status[data-state='connecting']::before {
  background: var(--waiting);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* never let long content widen the page */
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* Composer */

.composer {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer textarea {
  min-height: 80px;
  max-height: 40vh;
  padding: 10px 12px;
  border-color: transparent;
  background: var(--bg);
  line-height: 1.5;
  resize: none;
}

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

.composer-actions .btn:first-of-type {
  margin-left: auto;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font: 12px var(--font);
}

/* Touch devices can't paste with a shortcut, so the hint would only confuse. */
@media (pointer: coarse) {
  .hint {
    display: none;
  }

  .composer-actions .btn {
    flex: 1;
  }
}

/* Search */

.search {
  position: relative;
}

.search svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search input {
  min-height: 42px;
  padding: 0 12px 0 38px;
}

/* Clips */

.clip-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.clip {
  padding: 14px 14px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.clip.pinned {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.clip-text {
  max-height: calc(1.5em * 8);
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.clip.clamped .clip-text {
  -webkit-mask-image: linear-gradient(to bottom, #000 65%, transparent);
  mask-image: linear-gradient(to bottom, #000 65%, transparent);
}

.clip.expanded .clip-text {
  max-height: none;
}

.more-btn {
  margin-top: 4px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

.clip-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.clip-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.clip-meta-text {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pin-badge {
  display: none;
  width: 14px;
  height: 14px;
  color: var(--accent);
  fill: currentColor;
}

.clip.pinned .pin-badge {
  display: block;
}

.clip-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.copy-btn {
  min-width: 92px;
  margin-left: 4px;
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.copy-btn:hover {
  background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent));
}

.copy-btn .check-icon,
.copy-btn.copied .copy-icon {
  display: none;
}

.copy-btn.copied .check-icon {
  display: block;
}

.empty-state {
  margin: 24px 0;
  color: var(--muted);
  text-align: center;
}

/* Settings dialog */

.dialog {
  width: min(calc(100% - 32px), 420px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
}

.dialog form,
.dialog-body {
  display: grid;
  gap: 16px;
}

.dialog h3 {
  margin: 0;
  font-size: 16px;
}

.dialog p {
  margin: 0;
}

.account-line {
  overflow-wrap: anywhere;
}

.people-list {
  display: grid;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  list-style: none;
}

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

.person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.person + .person {
  border-top: 1px solid var(--border);
}

.person-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.person-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.btn.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.add-person {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.dialog hr {
  width: 100%;
  margin: 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
  transform: translateX(-50%);
}

.toast-action {
  padding: 4px 2px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
