:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --fg: #121211;
  --muted: #5c5a54;
  --faint: #8a887f;
  --line: #d2d0c8;
  --column: #e7e5de;
  --card: #fffcf8;
  --hover: #e0ded6;
  --danger: #9b2c24;
  --select: #d4cfc3;
  --shadow: 0 1px 2px rgba(18, 18, 17, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101010;
    --fg: #f7f6f2;
    --muted: #c8c6be;
    --faint: #8a887f;
    --line: #3a3a36;
    --column: #1c1c1a;
    --card: #242422;
    --hover: #323230;
    --danger: #ffb4ac;
    --select: #4a4a44;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  }
}

[data-theme="ink"] {
  color-scheme: light;
  --bg: #e4eef8;
  --fg: #0c1b33;
  --muted: #3a5270;
  --faint: #6a829e;
  --line: #b7cce2;
  --column: #d0e2f2;
  --card: #f7fbff;
  --hover: #c5d8ec;
  --danger: #9b2436;
  --select: #b5d0ea;
  --shadow: 0 1px 2px rgba(12, 27, 51, 0.1);
}

@media (prefers-color-scheme: dark) {
  [data-theme="ink"] {
    color-scheme: dark;
    --bg: #0b1424;
    --fg: #f3f7fc;
    --muted: #b7c9de;
    --faint: #7d94b0;
    --line: #2c4260;
    --column: #152238;
    --card: #1c2d48;
    --hover: #243858;
    --danger: #ffb3bc;
    --select: #2e4e78;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

[data-theme="sage"] {
  color-scheme: light;
  --bg: #e3f0e2;
  --fg: #102416;
  --muted: #3a5c46;
  --faint: #6a8c76;
  --line: #b7d4bc;
  --column: #cfe4d2;
  --card: #f6fbf6;
  --hover: #c3dcc8;
  --danger: #9b2c24;
  --select: #b3d4b8;
  --shadow: 0 1px 2px rgba(16, 36, 22, 0.1);
}

@media (prefers-color-scheme: dark) {
  [data-theme="sage"] {
    color-scheme: dark;
    --bg: #0c1810;
    --fg: #f1f8f2;
    --muted: #b4d0bc;
    --faint: #7a9c86;
    --line: #2c4636;
    --column: #16281c;
    --card: #1c3426;
    --hover: #244432;
    --danger: #ffb4ac;
    --select: #2e523c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

[data-theme="sand"] {
  color-scheme: light;
  --bg: #f6e4cc;
  --fg: #2a1608;
  --muted: #6a4528;
  --faint: #9a7454;
  --line: #e0c4a4;
  --column: #edd3b4;
  --card: #fff8ef;
  --hover: #e4c8a4;
  --danger: #9b2c24;
  --select: #e2c094;
  --shadow: 0 1px 2px rgba(42, 22, 8, 0.1);
}

@media (prefers-color-scheme: dark) {
  [data-theme="sand"] {
    color-scheme: dark;
    --bg: #1a1008;
    --fg: #fbf4ea;
    --muted: #e0c4a4;
    --faint: #a88060;
    --line: #4a3420;
    --column: #2a1c10;
    --card: #3a2818;
    --hover: #4a3422;
    --danger: #ffb4ac;
    --select: #6a4830;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  touch-action: manipulation;
}

::selection { background: var(--select); }

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

button { cursor: pointer; }

textarea {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  line-height: 1.45;
  min-height: 1.45em;
}

textarea:focus, input:focus { outline: none; }

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

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth form,
.account-panel form {
  width: min(22rem, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.auth h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.lede { margin: 0; color: var(--muted); }

.auth label,
.account-panel label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth input,
.account-panel input {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: 0.45rem 0;
  font-size: 1rem;
}

.auth input:focus,
.account-panel input:focus { border-bottom-color: var(--fg); }

.primary, .ghost, .text-button, .switch button, .add, .quiet, .install {
  border: 0;
  background: transparent;
}

.primary {
  margin-top: 0.35rem;
  background: var(--fg);
  color: var(--bg);
  border-radius: 999px;
  padding: 0.7rem 1rem;
}

.ghost, .text-button, .quiet, .install, .add {
  color: var(--muted);
  padding: 0.35rem 0.2rem;
}

.primary:disabled { opacity: 0.6; }

.error { color: var(--danger); min-height: 1.2em; margin: 0; }

.header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  padding: 0.8rem 1.25rem 0.75rem;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.identity { flex: 1 1 16rem; min-width: 0; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.35rem;
  margin-bottom: 0.2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.crumbs:empty { display: none; }

.crumbs button {
  display: inline-block;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sep { color: var(--faint); }

.title-input {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-left: auto;
}

.account {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-panel {
  width: min(22rem, calc(100vw - 2rem));
  margin: auto;
  padding: 1.25rem 1.35rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}

.account-panel::backdrop {
  background: color-mix(in srgb, var(--fg) 28%, transparent);
}

.account-panel form { width: auto; }

.account-panel h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.account-panel .email {
  margin: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-panel .text-button { align-self: flex-start; }

.switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}

.switch button {
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  color: var(--muted);
}

.switch button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
}

.themes {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.themes button {
  width: 0.95rem;
  height: 0.95rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--fg) 22%, transparent);
}

.themes button[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--fg);
}

.swatch-paper { background: #3a3a36; }
.swatch-ink { background: #1d4e8f; }
.swatch-sage { background: #2d6a45; }
.swatch-sand { background: #c56a1a; }

.auth .themes { margin-top: 0.35rem; }

.search { position: relative; }

.search input {
  width: 8.5rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: 0.3rem 0;
}

.search input:focus { width: 12rem; border-bottom-color: var(--fg); }

.results {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  width: min(18rem, 70vw);
  max-height: 16rem;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 6;
}

.results button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.5rem 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results button:hover, .results button:focus-visible { background: var(--hover); }

main { padding: 1.1rem 1.25rem calc(4rem + env(safe-area-inset-bottom)); }

.outline-wrap { max-width: 40rem; margin: 0 auto; }

.done-bar {
  display: flex;
  gap: 0.85rem;
  margin-bottom: 0.35rem;
}

.done-bar button {
  font-size: 0.85rem;
  white-space: nowrap;
}

.done-bar button[aria-pressed="true"] { color: var(--fg); }

.done-bar button:disabled { opacity: 0.4; cursor: default; }

.board-wrap { display: flex; flex-direction: column; gap: 0.15rem; }

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

.outline .outline { margin-left: 1.15rem; }

.row {
  display: grid;
  grid-template-columns: 1.15rem 1.35rem 1.6rem 1.35rem minmax(0, 1fr);
  column-gap: 0.1rem;
  align-items: start;
  padding: 0.08rem 0;
}

.main { position: relative; min-width: 0; }

.twist, .zoom, .check, .handle, .quiet {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.twist, .zoom {
  width: 1.35rem;
  height: 1.6rem;
  margin-top: 0.05rem;
}

.twist.empty, .zoom.ghost { visibility: hidden; }

.check {
  width: 1.6rem;
  height: 1.6rem;
  border: 0;
  border-radius: 0;
  position: relative;
}

.check::before,
.check.ghost::before {
  content: "";
  display: block;
  width: 0.72rem;
  height: 0.72rem;
  margin: 0.28rem auto 0;
  border: 1.5px solid var(--faint);
  border-radius: 50%;
}

.check.ghost {
  display: inline-block;
  width: 1.6rem;
  height: 1.6rem;
}

.check.ghost::before { border-color: var(--line); }

.item.done > .row > .check::before,
.card.done .check::before {
  background: var(--muted);
  border-color: var(--muted);
}

.item.done > .row .editor,
.card.done .editor {
  color: var(--muted);
  text-decoration: line-through;
}

.note {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.12rem;
}

.row .note:placeholder-shown { display: none; }
.row:focus-within .note:placeholder-shown { display: block; }

.tools {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  gap: 0.35rem;
  margin: 0;
  padding-left: 0.6rem;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
}

.tools button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.15rem 0.2rem;
  font-size: 0.92rem;
}

.item:focus-within > .row .tools,
.row:hover .tools {
  opacity: 1;
  pointer-events: auto;
}

.item:focus-within > .row .editor,
.row:hover .editor { padding-right: 7.5rem; }

.board {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scroll-snap-type: x proximity;
}

.column {
  flex: 0 0 min(78vw, 17.5rem);
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: calc(100dvh - 8.5rem);
  padding: 0.55rem;
  border-radius: 12px;
  background: var(--column);
}

.col-top, .card-top {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.col-top .editor { font-weight: 600; }

.column .editor, .card .editor { min-width: 0; }

.card-top .editor {
  flex: 1;
  width: auto;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow-y: auto;
  min-height: 0.5rem;
}

.card {
  background: var(--card);
  border-radius: 8px;
  padding: 0.5rem 0.55rem 0.55rem;
  box-shadow: var(--shadow);
}

.card .note:placeholder-shown { display: none; }

.card:focus-within .note:placeholder-shown { display: block; }

.handle {
  cursor: grab;
  touch-action: none;
  color: var(--muted);
  letter-spacing: -0.12em;
  width: 1.15rem;
  height: 1.6rem;
  padding-top: 0.2rem;
}

.handle.ghost { visibility: hidden; }

.handle:active { cursor: grabbing; }

.item.drop-before > .row { box-shadow: inset 0 2px 0 var(--fg); }

.column-add { flex: 0 0 auto; align-self: stretch; }

.add { text-align: left; padding: 0.35rem 0.2rem; }

.card.drop-before { box-shadow: inset 0 2px 0 var(--fg), var(--shadow); }

.column.drop-before,
.column.column-drop { outline: 2px solid var(--fg); outline-offset: -2px; }

.drag-mirror {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  opacity: 0.94;
  transform: translate(-8%, -30%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 0.875rem;
  z-index: 40;
}

.toast:empty { display: none; }

@media (max-width: 700px) {
  .identity { flex-basis: 100%; }
  .actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .search input, .search input:focus { width: 6.5rem; }
  main { padding-left: 0.9rem; padding-right: 0.9rem; }
  .item:focus-within > .row .tools {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    justify-content: space-around;
    padding: 0.65rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    z-index: 5;
  }
  .item:focus-within > .row .editor { padding-right: 0; }
}
