@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, ul, ol { margin: 0; }
  ul, ol { padding: 0; list-style: none; }
  button, input, select, textarea { font: inherit; color: inherit; }
}

@layer base {
  body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: var(--text-md); line-height: 1.45; }
  a { color: var(--accent); text-decoration: none; }
  a:hover { text-decoration: underline; }
  h1 { font-size: var(--text-xl); font-weight: 650; letter-spacing: -0.01em; }
  h2 { font-size: var(--text-lg); font-weight: 600; margin-top: var(--s6); margin-bottom: var(--s3); }
  h3 { font-size: var(--text-md); font-weight: 600; margin-top: var(--s5); margin-bottom: var(--s1); }
  input, select, textarea {
    width: 100%; padding: var(--s2) var(--s3); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
  }
  textarea { resize: vertical; }
  input:focus, select:focus, textarea:focus, button:focus-visible, .card:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--accent); }
  button, .button {
    display: inline-flex; align-items: center; gap: var(--s2); white-space: nowrap;
    padding: var(--s2) var(--s4); border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); cursor: pointer; font-weight: 500; color: var(--text);
  }
  button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
  button:disabled { opacity: 0.6; cursor: default; }
  label { display: grid; gap: var(--s1); font-size: var(--text-sm); font-weight: 500; }
}

@layer components {
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--s3) var(--s5); background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .brand { font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
  .session { display: flex; align-items: center; gap: var(--s2); font-size: var(--text-sm); }

  .page { max-width: 960px; margin: 0 auto; padding: var(--s6) var(--s5); }
  .page.narrow { max-width: 480px; }
  .pad { padding: var(--s5); }
  .crumbs { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--s1); }
  .crumbs a { color: var(--muted); }

  .hero { text-align: center; margin: var(--s6) 0 var(--s5); }
  .hero p { margin-top: var(--s2); }
  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s5); box-shadow: var(--shadow); }
  .panel h2 { margin-top: 0; }
  .tabs { display: flex; gap: var(--s1); margin-bottom: var(--s4); border-bottom: 1px solid var(--border); }
  .tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: var(--s2) var(--s3); color: var(--muted); }
  .tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
  .stack { display: grid; gap: var(--s4); }
  .magic { margin-top: var(--s4); font-size: var(--text-sm); }
  .magic summary { cursor: pointer; color: var(--muted); }
  .magic form { margin-top: var(--s2); }

  .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .primary:hover { background: var(--accent-hover); }
  .link { border: 0; background: none; padding: var(--s1) var(--s2); color: var(--accent); font-weight: 500; }
  .link:hover { background: none; text-decoration: underline; }
  .danger { color: var(--danger); }
  .icon { border: 0; background: none; padding: 0 var(--s2); font-size: 1.4rem; line-height: 1; color: var(--muted); }
  .icon.small { font-size: 1rem; }
  button.small { padding: var(--s1) var(--s3); font-size: var(--text-sm); }

  .inline-form { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-top: var(--s3); }
  .inline-form input { flex: 1; min-width: 12rem; width: auto; }
  .inline-form .form-error { flex-basis: 100%; }
  .form-error { color: var(--danger); font-size: var(--text-sm); }
  .form-error:empty { display: none; }
  .toast { margin-bottom: var(--s3); }
  .row { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s2); }

  .list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
  .list li + li { border-top: 1px solid var(--border); }
  .list-link { display: flex; justify-content: space-between; align-items: center; padding: var(--s3) var(--s4); color: var(--text); }
  .list-link:hover { background: var(--surface-2); text-decoration: none; }
  .member { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); }

  .project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s3); }
  .project-tile {
    display: grid; gap: var(--s1); padding: var(--s4); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow);
  }
  .project-tile:hover { border-color: var(--accent); text-decoration: none; }

  .editable { cursor: text; border-radius: var(--radius-sm); }
  .editable:hover { background: var(--surface-2); }
  .title-input { font-size: var(--text-xl); font-weight: 650; padding: 0 var(--s1); max-width: 32rem; }

  .avatar {
    display: inline-grid; place-items: center; flex: none; width: 2rem; height: 2rem; border-radius: 50%;
    color: #fff; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em;
  }
  .avatar.small { width: 1.5rem; height: 1.5rem; font-size: 0.625rem; }

  /* Board */
  .board-page { padding: var(--s4) var(--s5) var(--s6); }
  .board-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s4); margin-bottom: var(--s4); }
  .board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: var(--s4); align-items: start; overflow-x: auto; }
  .column { background: var(--surface-2); border-radius: var(--radius); padding: var(--s3); display: grid; gap: var(--s2); }
  .column header { display: flex; justify-content: space-between; align-items: center; font-size: var(--text-sm); font-weight: 600; padding: 0 var(--s1); }
  .column .count { color: var(--muted); font-weight: 500; }
  .column-done .card-title { color: var(--muted); }
  .card-list { display: grid; gap: var(--s2); min-height: 3rem; align-content: start; }
  .card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: var(--s3); box-shadow: var(--shadow); cursor: pointer; display: grid; gap: var(--s2);
  }
  .card:hover { border-color: #c9c9c1; }
  .card.dragging { opacity: 0.4; }
  .card-title { font-size: var(--text-sm); font-weight: 500; overflow-wrap: anywhere; white-space: pre-wrap; }
  .card-meta { display: flex; justify-content: space-between; align-items: center; font-size: var(--text-xs); color: var(--muted); }
  .meta-icons { display: flex; gap: var(--s3); }
  .meta-icons .complete { color: var(--accent); }
  .avatars { display: flex; }
  .avatars .avatar + .avatar { margin-left: -6px; box-shadow: 0 0 0 2px var(--surface); }
  .drop-marker { height: 3px; border-radius: 2px; background: var(--accent); }
  .add-card-button { width: 100%; justify-content: flex-start; border: 0; background: none; color: var(--muted); font-size: var(--text-sm); padding: var(--s2); }
  .add-card-button:hover { background: var(--border); color: var(--text); }
  .add-card textarea { font-size: var(--text-sm); }

  /* Card dialog */
  .card-dialog {
    width: min(680px, 94vw); max-height: 88vh; padding: 0; border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg); background: var(--surface); color: var(--text);
  }
  .card-dialog[open] { display: flex; flex-direction: column; }
  .card-dialog::backdrop { background: rgb(20 20 20 / 0.35); }
  .card-head { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s4) var(--s4) 0 var(--s5); }
  .card-title-input { border: 1px solid transparent; font-size: var(--text-lg); font-weight: 600; padding: var(--s1) var(--s2); resize: none; overflow: hidden; }
  .card-title-input:hover { border-color: var(--border); }
  .card-dialog > .form-error { padding: 0 var(--s5); }
  .card-body { overflow-y: auto; padding: var(--s4) var(--s5) var(--s5); display: grid; gap: var(--s5); }
  .fields { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
  .field { display: grid; gap: var(--s2); }
  .field-head { display: flex; justify-content: space-between; align-items: center; }
  .field-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
  .assignees { display: flex; flex-wrap: wrap; gap: var(--s2); }
  .chip { padding: var(--s1) var(--s3) var(--s1) var(--s1); border-radius: 999px; font-size: var(--text-sm); font-weight: 400; color: var(--muted); }
  .chip .avatar { opacity: 0.45; }
  .chip.on { border-color: var(--accent); color: var(--text); background: #2f6f5e12; }
  .chip.on .avatar { opacity: 1; }
  .description-input { font-family: var(--mono); font-size: var(--text-sm); }
  .clickable { cursor: text; border-radius: var(--radius-sm); padding: var(--s2); margin: calc(var(--s2) * -1); }
  .clickable:hover { background: var(--bg); }
  .placeholder { font-size: var(--text-sm); }
  .checklist li { display: flex; align-items: center; justify-content: space-between; padding: var(--s1) 0; }
  .checklist label { display: flex; align-items: center; gap: var(--s2); font-weight: 400; font-size: var(--text-sm); }
  .checklist input { width: auto; }
  .checklist .done span { text-decoration: line-through; color: var(--muted); }
  .subtasks .inline-form { margin-top: 0; }
  .comments { display: grid; gap: var(--s4); }
  .comments li { display: flex; gap: var(--s3); }
  .comment-head { display: flex; align-items: baseline; gap: var(--s2); font-size: var(--text-sm); }
  .card-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: var(--s3); }

  .markdown { font-size: var(--text-sm); overflow-wrap: anywhere; }
  .markdown > * + * { margin-top: var(--s2); }
  .markdown ul { list-style: disc; padding-left: var(--s5); }
  .markdown ol { list-style: decimal; padding-left: var(--s5); }
  .markdown code { font-family: var(--mono); background: var(--surface-2); padding: 0 0.25em; border-radius: 3px; }
  .markdown pre { background: var(--surface-2); padding: var(--s3); border-radius: var(--radius-sm); overflow-x: auto; }
  .markdown pre code { background: none; padding: 0; }
  .markdown blockquote { border-left: 3px solid var(--border); padding-left: var(--s3); color: var(--muted); margin-left: 0; }
}

@layer utilities {
  .muted { color: var(--muted); }
  .small { font-size: var(--text-sm); }
  .tiny { font-size: var(--text-xs); }
  .grow { flex: 1; min-width: 0; }
}

@media (max-width: 700px) {
  .board { grid-template-columns: repeat(4, 80vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .fields { grid-template-columns: 1fr; }
  .page, .board-page { padding-inline: var(--s4); }
}
