:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #edf1f4;
  --ink: #19232d;
  --muted: #61707c;
  --line: #d9e0e6;
  --accent: #e4572e;
  --accent-dark: #b73d1d;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(24, 39, 52, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); }
body:has(.card-dialog[open]) { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
[hidden] { display: none !important; }

.center-stage { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.login-card { width: min(100%, 430px); padding: 2.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.7rem, 3vw, 2.2rem); letter-spacing: -.04em; }
h2 { margin-bottom: .35rem; font-size: 1.15rem; }
h3 { margin-bottom: .65rem; font-size: .95rem; }
.eyebrow { margin-bottom: .45rem; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.5; }
.stack-form { display: grid; gap: 1rem; }
label { display: grid; gap: .4rem; color: var(--muted); font-size: .82rem; font-weight: 700; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); padding: .7rem .75rem; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 3px solid rgba(228, 87, 46, .25); outline-offset: 2px; border-color: var(--accent); }
.button, .primary, .subtle, .icon-button { border: 1px solid var(--line); border-radius: 9px; padding: .62rem .85rem; background: var(--surface); color: var(--ink); font-weight: 750; }
.button:hover, .subtle:hover { border-color: #aebac5; background: var(--surface-muted); }
.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.full-width { width: 100%; }
.error { margin: 0; color: var(--danger); font-size: .85rem; line-height: 1.4; }
.page-error { max-width: 1400px; margin: 0 auto 1rem; padding: 0 1.25rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.25rem max(1.25rem, calc((100vw - 1400px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar h1 { margin-bottom: 0; font-size: 1.45rem; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.user-badge { color: var(--muted); font-size: .86rem; font-weight: 700; }
.board-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 1rem; max-width: 1400px; margin: 0 auto; padding: 2rem 1.25rem 1.25rem; }
.board-toolbar h2 { font-size: 1.4rem; }
.board-toolbar p { margin-bottom: 0; }
.board { display: flex; align-items: flex-start; gap: 1rem; max-width: 1400px; margin: 0 auto; padding: 0 1.25rem 2rem; overflow-x: auto; }
.column {
  --column-bg: oklch(97% .018 245);
  --column-header-bg: oklch(91.5% .055 245);
  --column-border: oklch(82% .06 245);
  flex: 0 0 min(330px, calc(100vw - 2.5rem));
  min-height: 180px;
  padding: .75rem;
  background: var(--column-bg);
  border: 1px solid var(--column-border);
  border-radius: 14px;
}
.column:nth-child(10n + 2) { --column-bg: oklch(97.5% .025 90); --column-header-bg: oklch(92.5% .07 90); --column-border: oklch(83% .075 90); }
.column:nth-child(10n + 3) { --column-bg: oklch(97% .022 155); --column-header-bg: oklch(92% .065 155); --column-border: oklch(82% .07 155); }
.column:nth-child(10n + 4) { --column-bg: oklch(97% .02 305); --column-header-bg: oklch(92% .06 305); --column-border: oklch(82% .065 305); }
.column:nth-child(10n + 5) { --column-bg: oklch(97% .024 35); --column-header-bg: oklch(92% .07 35); --column-border: oklch(82% .075 35); }
.column:nth-child(10n + 6) { --column-bg: oklch(97% .02 195); --column-header-bg: oklch(92% .06 195); --column-border: oklch(82% .065 195); }
.column:nth-child(10n + 7) { --column-bg: oklch(97% .019 270); --column-header-bg: oklch(92% .058 270); --column-border: oklch(82% .064 270); }
.column:nth-child(10n + 8) { --column-bg: oklch(97.5% .024 125); --column-header-bg: oklch(92.5% .068 125); --column-border: oklch(83% .072 125); }
.column:nth-child(10n + 9) { --column-bg: oklch(97% .021 340); --column-header-bg: oklch(92% .063 340); --column-border: oklch(82% .068 340); }
.column:nth-child(10n + 10) { --column-bg: oklch(97.5% .024 65); --column-header-bg: oklch(92.5% .068 65); --column-border: oklch(83% .072 65); }
.column.drop-target { border-color: var(--accent); background: oklch(96% .035 35); }
.column-header {
  display: flex;
  align-items: center;
  gap: .4rem;
  min-height: 3rem;
  margin: -.75rem -.75rem .75rem;
  padding: .6rem .75rem;
  background: var(--column-header-bg);
  border-bottom: 1px solid var(--column-border);
  border-radius: 13px 13px 0 0;
}
.column-name { flex: 1; min-width: 0; margin: 0; color: var(--ink); font-size: 1.08rem; font-weight: 800; letter-spacing: -.015em; line-height: 1.2; overflow-wrap: anywhere; }
.column-count { min-width: 1.65rem; padding: .18rem .42rem; border: 1px solid color-mix(in oklch, var(--column-border) 70%, transparent); border-radius: 999px; background: color-mix(in oklch, var(--surface) 74%, transparent); color: var(--ink); font-size: .75rem; font-weight: 800; text-align: center; }
.column-actions { display: flex; gap: .15rem; }
.icon-button { display: inline-grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; line-height: 1; }
.icon-button:hover { background: color-mix(in oklch, var(--surface) 60%, transparent); color: var(--ink); }
.column-body { display: grid; gap: .65rem; min-height: 110px; }
.card { padding: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 4px rgba(24,39,52,.04); cursor: grab; }
.card:active { cursor: grabbing; }
.card:hover { border-color: #b9c5ce; }
.card-title { margin-bottom: .45rem; font-size: .94rem; font-weight: 750; overflow-wrap: anywhere; }
.card-description { margin-bottom: .65rem; color: var(--muted); font-size: .82rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: .35rem; color: var(--muted); font-size: .73rem; }
.card-meta span { padding: .2rem .4rem; background: var(--surface-muted); border-radius: 5px; }
.card-updated { margin-top: .6rem; color: var(--muted); font-size: .7rem; }
.add-card { width: 100%; border: 1px dashed #b9c5ce; border-radius: 8px; padding: .55rem; background: transparent; color: var(--muted); font-weight: 700; }
.add-card:hover { border-color: var(--accent); color: var(--accent); background: rgba(228,87,46,.05); }

.card-dialog {
  width: min(720px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
}
.card-dialog::backdrop { background: rgba(15, 24, 32, .56); }
.dialog-scroll {
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-padding-block: 5rem 1rem;
}
#card-form { gap: 1.1rem; padding: 1.5rem; }
.dialog-heading {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  margin: -1.5rem -1.5rem 0;
  padding: 1.2rem 1.5rem .95rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.dialog-heading h2 { margin-bottom: 0; font-size: 1.35rem; }
.dialog-heading .eyebrow { margin-bottom: .3rem; }
.dialog-heading .icon-button { background: var(--surface-muted); }
#card-description { min-height: 8rem; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.dialog-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .9rem;
  margin: .15rem -1.5rem -1.5rem;
  padding: .95rem 1.5rem 1.1rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.dialog-actions .primary { min-width: 8.5rem; }
.danger-link { margin-left: auto; border: 0; padding: .55rem 0; background: transparent; color: var(--danger); font-weight: 700; }
.comments { display: grid; gap: .9rem; margin: 0; padding: 1.35rem 1.5rem 1.5rem; border-top: 1px solid var(--line); background: color-mix(in oklch, var(--surface-muted) 42%, var(--surface)); }
.comments h3 { margin: 0; font-size: 1.05rem; }
#comments-list { display: grid; gap: .65rem; }
.comment { padding: .8rem; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.comment p { margin-bottom: .4rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-meta { color: var(--muted); font-size: .72rem; }
.comment-form { display: grid; gap: .65rem; }
.comment-form textarea { min-height: 5.5rem; }
.comment-form .button { justify-self: start; }

@media (max-width: 640px) {
  .login-card { padding: 1.5rem; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 1rem; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .board-toolbar { align-items: stretch; flex-direction: column; padding: 1.5rem 1rem 1rem; }
  .page-error { padding: 0 1rem; }
  .board { padding: 0 1rem 1.5rem; }
  .column { flex-basis: calc(100vw - 2rem); }
  .card-dialog {
    width: calc(100% - .75rem);
    max-height: calc(100vh - .75rem);
    max-height: calc(100dvh - .75rem);
    border-radius: 14px;
  }
  .dialog-scroll {
    max-height: calc(100vh - .75rem);
    max-height: calc(100dvh - .75rem);
  }
  #card-form { gap: .95rem; padding: 1rem; }
  .dialog-heading { margin: -1rem -1rem 0; padding: 1rem 1rem .8rem; }
  .dialog-heading h2 { font-size: 1.22rem; }
  .form-grid { grid-template-columns: 1fr; gap: .95rem; }
  .dialog-actions { margin: .1rem -1rem -1rem; padding: .85rem 1rem max(.95rem, env(safe-area-inset-bottom)); }
  .dialog-actions .primary { min-width: 0; }
  .comments { padding: 1.1rem 1rem max(1rem, env(safe-area-inset-bottom)); }
}
