@font-face {
  font-family: "DM Sans";
  src: url("assets/dm-sans.ttf") format("truetype");
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f1f4f2;
  --surface: #fafcfb;
  --surface-2: #e6ebe8;
  --ink: #16201d;
  --muted: #4f5e58;
  --line: #d3dad6;
  --line-strong: #8d9a94;
  --accent: #0b6b57;
  --accent-ink: #ffffff;
  --accent-wash: #dcefe9;
  --focus: #0b6b57;
  --shadow: 0 10px 30px rgb(22 48 40 / 0.14);

  --radius: 8px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --side-w: 460px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #151b19;
    --surface-2: #202926;
    --ink: #e7edea;
    --muted: #9eada6;
    --line: #28322e;
    --line-strong: #5d6d66;
    --accent: #52c4a3;
    --accent-ink: #07130f;
    --accent-wash: #16322a;
    --focus: #52c4a3;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.sheet-open { overflow: hidden; }

h1, h2, h3, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button, select, input { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 0.8125rem; letter-spacing: 0; }

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

.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
  z-index: 40;
  transition: top 0.15s;
}
.skip:focus { top: 12px; }

/* ---------- layout ---------- */
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  max-width: 1600px;
  margin: 0 auto;
  min-height: 100dvh;
}
.primary { min-width: 0; padding: 0 clamp(20px, 3.4vw, 52px) 80px; }

.brandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius);
}
.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  grid-template-rows: repeat(2, 9px);
  gap: 3px;
}
.brand-mark i {
  border: 2px solid var(--ink);
  border-radius: 2px;
}
.brand-mark i:nth-child(2) { background: var(--accent); border-color: var(--accent); }
.brand-name { font-weight: 700; font-size: 1.125rem; letter-spacing: -0.01em; }
.brand-note { color: var(--muted); font-size: 0.9375rem; text-align: right; }

.main { padding-top: 36px; }
.page-title {
  font-size: clamp(1.875rem, 1.4rem + 1.6vw, 2.75rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  font-weight: 700;
}

/* ---------- status tally ---------- */
.tally {
  display: flex;
  gap: 4px;
  margin: 28px 0 24px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tally::-webkit-scrollbar { display: none; }
.tally button {
  flex: 0 0 auto;
  min-width: 108px;
  padding: 10px 16px 12px 0;
  margin-right: 12px;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  text-align: left;
  cursor: pointer;
  color: var(--muted);
}
.tally .num {
  display: block;
  font-size: 1.75rem;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.tally .lbl { display: block; font-size: 0.875rem; }
.tally button:hover .lbl { color: var(--ink); }
.tally button[aria-pressed="true"] { border-bottom-color: var(--accent); }
.tally button[aria-pressed="true"] .lbl { color: var(--ink); font-weight: 600; }

/* ---------- toolbar ---------- */
.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) repeat(3, minmax(130px, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.field input::placeholder { color: var(--muted); opacity: 1; }
.field select { padding-right: 8px; }
.field input:hover, .field select:hover { border-color: var(--ink); }
.field input:focus-visible, .field select:focus-visible {
  outline-offset: 0;
  border-color: var(--focus);
}

.resultbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin: 22px 0 6px;
  color: var(--muted);
  font-size: 0.9375rem;
}
.linkish {
  background: none;
  border: 0;
  padding: 6px 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-weight: 600;
}
@media (prefers-color-scheme: dark) { .linkish { color: var(--accent); } }

/* ---------- task rows ---------- */
.tasks > li {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 20px;
  row-gap: 8px;
  padding: 18px 14px 18px 16px;
  margin: 0 -14px 0 -16px;
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s;
}
.tasks > li:hover { background: var(--surface-2); }
.tasks > li[aria-current="true"] {
  background: var(--surface);
  box-shadow: inset 3px 0 0 var(--accent);
}
.open-item {
  display: block;
  padding: 0;
  background: none;
  border: 0;
  text-align: left;
  font-weight: 600;
  font-size: 1.0625rem;
  line-height: 1.35;
  letter-spacing: -0.005em;
  cursor: pointer;
  border-radius: 4px;
}
.tasks > li[data-status="done"] .open-item { color: var(--muted); font-weight: 500; }
.row-meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 20px;
  color: var(--muted);
  font-size: 0.9375rem;
}
.who { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.prio-high { color: var(--ink); font-weight: 600; }

/* status badge: shape and fill carry meaning, not hue alone */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: transparent;
  align-self: start;
}
.badge[data-status="in-progress"] {
  background: var(--accent-wash);
  border-color: var(--accent);
}
.badge[data-status="blocked"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.badge[data-status="done"] {
  background: var(--surface-2);
  border-style: dashed;
  color: var(--muted);
}

.flash { animation: none; }
@media (prefers-reduced-motion: no-preference) {
  .flash { animation: flash 1.2s ease-out; }
  @keyframes flash {
    0% { background-color: var(--accent-wash); }
    100% { background-color: transparent; }
  }
}

/* ---------- empty ---------- */
.empty {
  padding: 56px 0 24px;
  max-width: 46ch;
}
.empty h2 { font-size: 1.5rem; letter-spacing: -0.015em; }
.empty p { margin: 8px 0 20px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn-quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-quiet:hover { border-color: var(--ink); }

/* ---------- side panel ---------- */
.side {
  position: sticky;
  top: 0;
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: hidden;
}
.idle { padding: 36px 32px; }
.idle h2 { font-size: 1.25rem; letter-spacing: -0.01em; }
.idle p { margin-top: 6px; color: var(--muted); max-width: 34ch; }
.idle-blocked { margin-top: 32px; }
.idle-blocked h3 { font-size: 0.9375rem; margin-bottom: 4px; }
.idle-blocked button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-weight: 500;
}
.idle-blocked button:hover { color: var(--accent); }
.idle-blocked small { display: block; color: var(--muted); font-size: 0.875rem; font-weight: 400; }

.detail { display: flex; flex-direction: column; height: 100%; background: var(--surface); }
.detail-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.detail-id { color: var(--muted); }
.detail-scroll { flex: 1; overflow-y: auto; padding: 28px 32px 48px; overscroll-behavior: contain; }
.detail-title {
  font-size: 1.625rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.detail-title:focus-visible { outline-offset: 4px; border-radius: 4px; }

.status-block { margin-top: 24px; display: flex; flex-direction: column; gap: 6px; }
.status-block label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.status-block select {
  height: 48px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-weight: 600;
}
.status-block select:hover { border-color: var(--ink); }
.status-block select:focus-visible { outline-offset: 0; border-color: var(--focus); }
.saved { min-height: 1.5em; font-size: 0.9375rem; color: var(--muted); }
.saved.is-changed { color: var(--ink); }
.saved.is-changed::before { content: "Saved. "; font-weight: 700; color: var(--accent); }

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 20px;
  margin-top: 24px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.facts dt { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.facts dd { margin-top: 2px; }
.facts .who { color: inherit; }

.sub { margin-top: 28px; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.body {
  margin-top: 8px;
  white-space: pre-line;
  max-width: 62ch;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tags li {
  padding: 3px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 0.875rem;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(520px, calc(100vw - 48px));
  padding: 10px 10px 10px 18px;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toast p { font-size: 0.9375rem; }
.toast .btn {
  min-height: 40px;
  color: var(--bg);
  border-color: color-mix(in srgb, var(--bg) 55%, transparent);
}
.toast .btn:hover { border-color: var(--bg); }
.toast :focus-visible { outline-color: var(--bg); }
@media (prefers-reduced-motion: no-preference) {
  .toast:not([hidden]) { animation: rise 0.22s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
  .detail:not([hidden]) { animation: fade 0.18s ease-out; }
  @keyframes fade { from { opacity: 0; } }
}

/* ---------- narrow screens: detail becomes a full-screen sheet ---------- */
@media (max-width: 899px) {
  .shell { display: block; }
  .primary { padding: 0 16px 72px; }
  .brandbar { height: 60px; }
  .brand-note { display: none; }
  .main { padding-top: 24px; }

  .tally { margin: 20px -16px 20px; padding-left: 16px; }
  .tally button { min-width: 96px; }

  .toolbar { grid-template-columns: 1fr 1fr; gap: 12px; }
  .field-search { grid-column: 1 / -1; }
  .toolbar .field:nth-child(4) { grid-column: 1 / -1; }

  .tasks > li { margin: 0 -8px; padding: 16px 8px; }
  .tasks > li[aria-current="true"] { box-shadow: none; background: transparent; }
  .row-meta { gap: 6px 14px; font-size: 0.875rem; }

  .side { position: static; height: auto; border: 0; background: transparent; overflow: visible; }
  .idle { display: none; }
  .detail {
    position: fixed;
    inset: 0;
    z-index: 20;
    height: 100dvh;
  }
  .detail-bar { padding: 10px 16px; }
  .detail-scroll { padding: 22px 16px 40px; }
  .detail-title { font-size: 1.5rem; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
    z-index: 50;
  }
}
