:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1d1f24;
  --muted: #6b7079;
  --faint: #a3a8b1;
  --line: #e8e9ed;
  --hover: #f3f4f6;
  --selected: #e8ecfb;
  --side: #f7f8fa;
  --popover: #ffffff;
  --accent: #3b5bdb;
  --accent-fg: #ffffff;
  --box: #c3c7ce;
  --danger: #e03131;
  --flash: #fff1b8;
  --toast-bg: #24262c;
  --toast-fg: #f3f4f6;
  --toast-accent: #9db0ff;
  --shadow: 0 12px 32px rgba(15, 20, 30, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --fg: #e8e9ec;
    --muted: #979ca6;
    --faint: #62666f;
    --line: #2a2c33;
    --hover: #222429;
    --selected: #262b3e;
    --side: #1b1c21;
    --popover: #212328;
    --accent: #7d94ff;
    --accent-fg: #10131c;
    --box: #4d515a;
    --danger: #ff6b6b;
    --flash: #3d3720;
    --toast-bg: #e8e9ec;
    --toast-fg: #17181c;
    --toast-accent: #3b5bdb;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

svg .f {
  fill: currentColor;
  stroke: none;
}

.offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
  opacity: 0;
}

/* ------------------------------------------------------------ layout */

.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  flex: none;
  width: 264px;
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  background: var(--side);
  border-right: 1px solid var(--line);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.backdrop {
  display: none;
}

.content {
  flex: 1;
  min-width: 0;
}

.topbar,
.main {
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: calc(60px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 16px;
  background: var(--bg);
}

.main {
  padding: 4px max(8px, env(safe-area-inset-right)) calc(120px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.icon-btn.drawer-btn {
  display: none;
}

.auth-error .sidebar,
.auth-error .topbar {
  display: none;
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 86vw);
    height: auto;
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s 0.24s;
    visibility: hidden;
  }

  .drawer-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: var(--shadow);
  }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(0, 0, 0, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .drawer-open .backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .icon-btn.drawer-btn {
    display: inline-flex;
    margin-left: -8px;
  }

  .topbar {
    padding-left: max(12px, env(safe-area-inset-left));
  }
}

/* ------------------------------------------------------------ top bar */

.title {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 6px 6px;
  border-radius: 8px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}

.title-input {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
}

.status {
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

@media (hover: hover) {
  .icon-btn:hover {
    background: var(--hover);
    color: var(--fg);
  }
}

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

.items {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: 10px;
}

.row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  min-height: 48px;
  border-radius: 10px;
  background: var(--bg);
  touch-action: pan-y;
  transition: background-color 0.15s;
}

.hit {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 6px 11px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.check-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.box {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--box);
  border-radius: 50%;
  transition: background-color 0.15s, border-color 0.15s, transform 0.15s;
}

.box svg {
  width: 14px;
  height: 14px;
  stroke: var(--accent-fg);
  stroke-width: 3;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.15s, transform 0.15s;
}

.check-input:checked + .box {
  background: var(--accent);
  border-color: var(--accent);
}

.check-input:checked + .box svg {
  opacity: 1;
  transform: none;
}

.check-input:focus-visible + .box {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.hit:active .box {
  transform: scale(0.9);
}

.text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  text-decoration-line: none;
  transition: color 0.2s;
}

.ticked .text,
.is-finished .text {
  color: var(--muted);
  text-decoration-line: line-through;
  text-decoration-color: var(--faint);
}

.is-finished .box {
  border-color: var(--faint);
}

.is-finished .check-input:checked + .box {
  background: var(--faint);
  border-color: var(--faint);
}

.edit-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
  user-select: text;
  -webkit-user-select: text;
}

.editing .row {
  background: var(--hover);
}

.editing .hit {
  cursor: default;
}

.del {
  width: 36px;
  height: 36px;
  margin-right: 6px;
  opacity: 0;
  transition: opacity 0.12s;
}

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

@media (hover: hover) and (pointer: fine) {
  .row:hover {
    background: var(--hover);
  }

  .row:hover .del,
  .del:focus-visible {
    opacity: 1;
  }

  .item:not(.is-finished) .text {
    cursor: text;
  }
}

@media (hover: none), (pointer: coarse) {
  .del {
    display: none;
  }
}

.item.swiping,
.item.swipe-armed {
  background: color-mix(in srgb, var(--danger) 55%, var(--bg));
}

.item.swipe-armed {
  background: var(--danger);
}

.item.swiping::after,
.item.swipe-armed::after {
  content: attr(data-delete-label);
  position: absolute;
  z-index: 0;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}

.item.pressed .row {
  background: var(--hover);
  transform: scale(0.985);
  transition: transform 0.2s, background-color 0.2s;
}

.item.leaving {
  opacity: 0;
  pointer-events: none;
  transition: height 0.26s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.item.entering {
  animation: item-in 0.22s ease-out;
}

.item.flash .row {
  animation: flash 1.2s ease-out;
}

@keyframes item-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@keyframes flash {
  0%,
  30% {
    background-color: var(--flash);
  }
}

/* ------------------------------------------------------------ adders */

.adder-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.adder-btn svg,
.adder-icon svg {
  flex: none;
  width: 22px;
  height: 22px;
}

@media (hover: hover) {
  .adder-btn:hover {
    background: var(--hover);
    color: var(--fg);
  }
}

.adder-form {
  display: none;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--hover);
}

.adder.open .adder-btn {
  display: none;
}

.adder.open .adder-form {
  display: flex;
}

.adder-icon {
  display: flex;
  color: var(--accent);
}

.adder-input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
}

.adder-input::placeholder {
  color: var(--faint);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 6px 48px;
}

.suggestion {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 14px;
  cursor: pointer;
}

.suggestion.selected,
.suggestion:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.empty {
  margin: 0;
  padding: 6px 12px 10px 48px;
  color: var(--faint);
}

/* ------------------------------------------------------------ finished */

.finished {
  margin-top: 18px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.finished-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.finished-toggle .count {
  font-weight: 500;
  color: var(--faint);
}

.chev {
  display: flex;
}

.chev svg {
  width: 18px;
  height: 18px;
  transition: transform 0.2s;
}

.finished.open .chev svg {
  transform: rotate(90deg);
}

.finished-body {
  display: none;
}

.finished.open .finished-body {
  display: block;
}

.finished-actions {
  display: flex;
  gap: 18px;
  padding: 6px 12px 0 48px;
}

.link-btn {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
}

/* ------------------------------------------------------------ sidebar */

.switcher {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 14px 10px 16px;
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}

.list-links {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-link,
.side-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.list-link .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.list-link .count {
  color: var(--faint);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.list-link.current {
  background: var(--selected);
  font-weight: 600;
}

.shared-icon {
  display: flex;
  color: var(--faint);
}

.shared-icon svg {
  width: 17px;
  height: 17px;
}

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

.side-btn svg {
  flex: none;
  width: 20px;
  height: 20px;
}

.side-btn.subtle {
  font-size: 14px;
}

@media (hover: hover) {
  .list-link:not(.current):hover,
  .side-btn:hover {
    background: var(--hover);
    color: var(--fg);
  }
}

.side-actions {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.inline-input {
  display: none;
  width: 100%;
  margin: 2px 0;
  padding: 10px 12px;
  border: 1.5px solid var(--accent);
  border-radius: 9px;
  outline: 0;
  background: var(--bg);
  font-size: 16px;
}

.inline-input:disabled {
  opacity: 0.6;
}

.inline.open .side-btn {
  display: none;
}

.inline.open .inline-input {
  display: block;
}

.side-foot {
  margin-top: auto;
  padding-top: 16px;
}

/* ------------------------------------------------------------ menu, dialog, toast */

.menu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--popover);
  box-shadow: var(--shadow);
  animation: pop 0.12s ease-out;
}

.menu-item {
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  outline: none;
  background: var(--hover);
}

.menu-item.danger {
  color: var(--danger);
}

.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 22px;
  border: 0;
  border-radius: 16px;
  background: var(--popover);
  color: var(--fg);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.36);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.link-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--hover);
  font: 14px/1.4 ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 15px;
  cursor: pointer;
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

.toasts {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 46px;
  padding: 8px 16px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: var(--shadow);
  font-size: 15px;
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.18s, transform 0.18s;
}

.toast:has(.toast-action) {
  padding-right: 6px;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(8px);
}

.toast-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-action {
  flex: none;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--toast-accent);
  font-weight: 650;
  cursor: pointer;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ------------------------------------------------------------ messages and landing page */

.message {
  padding: 72px 16px;
  text-align: center;
  color: var(--muted);
}

.message .btn {
  margin-top: 8px;
}

body.landing {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.landing-card {
  max-width: 420px;
  text-align: center;
}

.landing-card h1 {
  margin: 12px 0 8px;
  font-size: 22px;
}

.landing-card p {
  color: var(--muted);
}

.join-link {
  display: block;
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--hover);
  font-size: 13px;
  word-break: break-all;
}

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