:root {
  --bg: #faf7f2;
  --bg-raised: #ffffff;
  --ink: #1d1a17;
  --ink-2: #5f5852;
  --ink-3: #746b63;
  --line: rgba(29, 26, 23, 0.12);
  --accent: #c2410c;
  --accent-ink: #faf7f2;
  --accent-soft: rgba(194, 65, 12, 0.10);
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(29, 26, 23, 0.06), 0 8px 24px -12px rgba(29, 26, 23, 0.18);
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --display: "Fraunces", Georgia, serif;
  --text: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur: 200ms;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --bg-raised: #1e1a17;
    --ink: #f3ede6;
    --ink-2: #b5aba1;
    --ink-3: #8f857c;
    --line: rgba(243, 237, 230, 0.12);
    --accent: #f0783c;
    --accent-ink: #14110f;
    --accent-soft: rgba(240, 120, 60, 0.14);
    --danger: #f28b82;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
@media (pointer: fine) { html { overscroll-behavior: none; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: 17px;
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { touch-action: manipulation; }
h1, h2, p.empty-title, p.error-title { text-wrap: balance; }

.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;
}

.app {
  width: min(100% - 2rem, 42rem);
  margin-inline: auto;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

/* ---------- Typography ---------- */
.brand {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
  font-variation-settings: "opsz" 144;
}
.brand-big { font-size: clamp(2.75rem, 12vw, 3.75rem); }

.lede {
  color: var(--ink-2);
  margin: 0.75rem 0 2rem;
  max-width: 28ch;
}

.label {
  display: block;
  font-size: 0.875rem;
  color: var(--ink-2);
  margin-bottom: 0.375rem;
  font-weight: 500;
}

.hint, .sync {
  font-size: 0.875rem;
  color: var(--ink-3);
  margin: 0.5rem 0 0;
}

/* ---------- Buttons & inputs ---------- */
.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 500;
  min-height: 48px;
  padding: 0 1.125rem;
  border-radius: var(--r-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--bg-raised); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--accent); padding-inline: 0.75rem; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary:hover { border-color: var(--ink-3); }

.link {
  appearance: none; background: none; border: 0; padding: 0.5rem 0;
  font: inherit; font-size: 0.875rem; color: var(--ink-3);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
  min-height: 44px;
}
.link:hover { color: var(--ink-2); }

input[type="text"] {
  font: inherit;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 0.875rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-raised);
  color: var(--ink);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input[type="text"]::placeholder { color: var(--ink-3); }
input[type="text"]:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible, input:focus-visible { outline-offset: 1px; }

/* ---------- Join screen ---------- */
.screen-join {
  min-height: calc(100dvh - 3rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.join-inner { width: 100%; max-width: min(26rem, 100%); min-width: 0; padding-block: 2rem; }

.divider {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 1.5rem 0;
  color: var(--ink-3); font-size: 0.875rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.input-row { display: flex; gap: 0.5rem; }
.input-row input { flex: 1; }

/* ---------- Header ---------- */
.top { margin-bottom: 1rem; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }

.chip {
  appearance: none; border: 1px solid var(--line); background: var(--bg-raised);
  color: var(--ink-2); font: inherit; font-size: 0.875rem; font-weight: 500;
  min-height: 44px; padding: 0 0.75rem 0 0.875rem; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
  max-width: 55%;
}
.chip:hover { background: var(--accent-soft); color: var(--accent); }
.chip-code { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-icon { width: 18px; height: 18px; flex: none; }

.sync { display: flex; align-items: center; gap: 0.4rem; min-height: 1.3rem; }
.sync::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3); flex: none;
  transition: background-color var(--dur) var(--ease);
}
.sync.is-live::before { background: #2f8f5b; }
.sync.is-offline::before { background: var(--danger); }
.sync.is-busy::before { background: var(--accent); animation: pulse 1s infinite var(--ease); }

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

/* ---------- Add form ---------- */
.add {
  display: flex; gap: 0.5rem;
  position: sticky; top: 0; z-index: 2;
  padding: 0.5rem 0 0.75rem;
  background: linear-gradient(var(--bg) 85%, transparent);
}
.add input { flex: 1; }

.notice {
  margin: 0 0 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.9375rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.notice.is-error { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.notice .link { color: var(--ink); min-height: 44px; padding: 0 0.5rem; margin: -0.5rem -0.5rem -0.5rem 0; flex: none; }

/* ---------- States ---------- */
.state { padding: 2rem 0; text-align: center; }
.state-empty .empty-title, .state-error .error-title {
  font-family: var(--display); font-weight: 600; font-size: 1.375rem;
  letter-spacing: -0.02em; margin: 0 0 0.5rem;
}
.empty-hint, .error-hint { color: var(--ink-2); margin: 0 auto 1.25rem; max-width: 30ch; }

.skeleton {
  height: 56px; border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--line), transparent, var(--line));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  margin-bottom: 0.5rem;
}
.skeleton.short { width: 70%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Items ---------- */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

.item {
  display: flex; align-items: stretch;
  background: var(--bg-raised);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: slide-in 260ms var(--ease) both;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.item.is-leaving { animation: slide-out 200ms var(--ease) forwards; }
@keyframes slide-out { to { opacity: 0; transform: translateX(-12px); height: 0; } }
.item.is-pending { opacity: 0.7; }

.item-btn {
  appearance: none; border: 0; background: none; font: inherit; color: inherit;
  flex: 1; min-width: 0; min-height: 56px;
  display: flex; align-items: center; gap: 0.875rem;
  padding: 0.75rem 0.5rem 0.75rem 0.875rem;
  text-align: left; cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.item-btn:active { background: var(--accent-soft); }
.item-btn:focus-visible { outline-offset: -3px; border-radius: var(--r-md); }

.box {
  flex: none; width: 24px; height: 24px;
  border: 1.5px solid var(--ink-3);
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: var(--accent-ink);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.box svg { width: 18px; height: 18px; }
.tick { stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset 250ms var(--ease) 60ms; }

.name {
  flex: 1; min-width: 0;
  overflow-wrap: anywhere;
  position: relative;
  transition: color var(--dur) var(--ease);
}
.name::after {
  content: ""; position: absolute; left: 0; top: 50%;
  height: 1.5px; width: 100%; background: var(--ink-3);
  transform: scaleX(0); transform-origin: left center;
  transition: transform 250ms var(--ease);
}

.item-btn[aria-checked="true"] .box { background: var(--accent); border-color: var(--accent); }
.item-btn[aria-checked="true"] .tick { stroke-dashoffset: 0; }
.item-btn[aria-checked="true"] .name { color: var(--ink-3); }
.item-btn[aria-checked="true"] .name::after { transform: scaleX(1); }

.remove {
  appearance: none; border: 0; background: none; cursor: pointer;
  color: var(--ink-3); width: 48px; flex: none;
  display: grid; place-items: center;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.remove svg { width: 20px; height: 20px; }
.remove:hover, .remove:focus-visible { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.remove:focus-visible { outline-offset: -3px; }

/* ---------- Footer ---------- */
.bottom {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 1rem; padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.count { font-size: 0.875rem; color: var(--ink-3); }

.leave { text-align: center; margin: 2rem 0 0; }

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

@media (min-width: 640px) {
  .brand { font-size: 2rem; }
  .app { padding-top: 2.5rem; }
}
