:root {
  --paper: #f3eee4;
  --surface: #fffdf8;
  --ink: #1e1a15;
  --muted: #5b5347;
  --line: #d9d0bf;
  --accent: #a92f16;
  --accent-ink: #fff;
  --side: #23201b;
  --side-ink: #f3eee4;
  --side-muted: #c4baa8;

  --todo: #38455a;       --todo-bg: #e3e8f0;
  --progress: #1b5a9e;   --progress-bg: #dce9f8;
  --blocked: #9e1f1c;    --blocked-bg: #fbe2df;
  --done: #1d6636;       --done-bg: #dcf0e2;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid #1b5a9e;
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px;
}
.skip:focus { top: 8px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 272px 1fr; min-height: 100vh; }

.side {
  background: var(--side);
  color: var(--side-ink);
  padding: 28px 20px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 32px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; color: #e0573a; flex: none; }
.brand-name { font: 700 1.5rem/1.1 var(--serif); letter-spacing: -0.01em; }
.brand-sub { color: var(--side-muted); font-size: 0.875rem; }

.side-label {
  font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--side-muted); margin-bottom: 10px; font-weight: 600;
}
.views { display: flex; flex-direction: column; gap: 4px; }
.view-btn {
  width: 100%; min-height: 44px;
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: var(--side-ink); padding: 8px 12px; text-align: left;
  transition: background-color .15s;
}
.view-btn:hover { background: rgba(255,255,255,.08); }
.view-btn[aria-pressed="true"] { background: #f3eee4; color: var(--ink); }
.view-btn .n {
  margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700;
}
.view-btn :focus-visible, .view-btn:focus-visible { outline-color: #8fc2ff; }
.view-btn[aria-pressed="true"]:focus-visible { outline-color: #8fc2ff; }

.progress-card {
  margin-top: auto; padding: 16px; border-radius: var(--radius);
  background: rgba(255,255,255,.07); font-size: 0.875rem; color: var(--side-muted);
}
.progress-card strong { color: var(--side-ink); font: 700 1.5rem/1 var(--serif); display: block; margin-bottom: 8px; }
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; background: #6fcf8f; border-radius: 99px; transition: width .3s; }

/* ---------- main ---------- */
.main { padding: 32px clamp(20px, 4vw, 56px) 64px; max-width: 1100px; width: 100%; }
.toolbar { display: grid; gap: 16px; margin-bottom: 20px; }
.title { font: 700 2.5rem/1.1 var(--serif); letter-spacing: -0.02em; }
.controls { display: grid; grid-template-columns: 1fr 220px; gap: 16px; }
.field label { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; margin-top: -9px; color: var(--muted); pointer-events: none; }
input[type="text"], select {
  width: 100%; min-height: 46px; padding: 8px 12px;
  background: var(--surface); border: 1.5px solid #8b8170; border-radius: 10px;
}
input[type="text"] { padding-left: 38px; }
input::placeholder { color: #6e6556; }
.count { color: var(--muted); font-size: 0.9375rem; }

.list { display: grid; gap: 10px; }
.list[hidden] { display: none; }
.item {
  position: relative;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 14px 20px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
  transition: box-shadow .15s, transform .15s, border-color .15s;
  cursor: pointer;
}
.item::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 5px; border-radius: 0 4px 4px 0;
  background: var(--bar, var(--line));
}
.item[data-status="todo"] { --bar: var(--todo); }
.item[data-status="in-progress"] { --bar: var(--progress); }
.item[data-status="blocked"] { --bar: var(--blocked); }
.item[data-status="done"] { --bar: var(--done); }
.item:hover { border-color: #a99d86; box-shadow: 0 4px 14px rgba(40,30,10,.1); }
.item.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #ffe9a8; } to { background: var(--surface); } }

.open-item {
  background: none; border: 0; padding: 4px 0; min-height: 44px; text-align: left;
  font: 600 1.125rem/1.3 var(--serif);
  color: var(--ink);
}
.open-item::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); } /* whole card is the hit area */
.open-item:focus-visible { outline: none; }
.item:has(.open-item:focus-visible) { outline: 3px solid #1b5a9e; outline-offset: 2px; }
.item[data-status="done"] .open-item { color: var(--muted); }

.meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 0.875rem; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.meta svg { width: 14px; height: 14px; }
.pri-high { color: var(--accent); font-weight: 700; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 4px 10px 4px 8px; border-radius: 99px; font-size: 0.8125rem; font-weight: 700;
  background: var(--c-bg); color: var(--c);
}
.chip svg { width: 14px; height: 14px; flex: none; }
.chip[data-status="todo"] { --c: var(--todo); --c-bg: var(--todo-bg); }
.chip[data-status="in-progress"] { --c: var(--progress); --c-bg: var(--progress-bg); }
.chip[data-status="blocked"] { --c: var(--blocked); --c-bg: var(--blocked-bg); }
.chip[data-status="done"] { --c: var(--done); --c-bg: var(--done-bg); }

.empty {
  text-align: center; padding: 56px 20px; border: 2px dashed #a99d86; border-radius: var(--radius);
  background: var(--surface);
}
.empty[hidden] { display: none; }
.empty svg { width: 64px; height: 64px; color: var(--muted); }
.empty h2 { font: 700 1.5rem/1.2 var(--serif); margin: 8px 0 4px; }
.empty p { color: var(--muted); margin-bottom: 20px; }

.btn {
  min-height: 44px; padding: 8px 18px; border-radius: 10px;
  background: var(--ink); color: #fff; border: 0; font-weight: 600;
}
.btn:hover { background: #3a342b; }

/* ---------- detail dialog ---------- */
dialog.detail {
  margin: 0 0 0 auto; padding: 0; border: 0;
  width: min(560px, 100vw); height: 100dvh; max-height: 100dvh;
  background: var(--surface); color: var(--ink);
  box-shadow: -12px 0 40px rgba(20,15,5,.3);
  overflow-y: auto;
  animation: slide .22s ease-out;
}
dialog.detail::backdrop { background: rgba(30,24,14,.5); }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.d-head {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.d-id { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.close {
  min-height: 44px; min-width: 44px; padding: 8px 14px; border-radius: 10px;
  background: transparent; border: 1.5px solid #8b8170;
  display: inline-flex; align-items: center; gap: 8px; font-weight: 600;
}
.close:hover { background: var(--paper); }
.close svg { width: 16px; height: 16px; }
.d-body { padding: 24px 20px 40px; display: grid; gap: 24px; }
.d-title { font: 700 1.875rem/1.2 var(--serif); letter-spacing: -0.01em; overflow-wrap: anywhere; }

.status-box { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.status-box label { font-weight: 700; font-size: 0.9375rem; }
.feedback { min-height: 1.5em; font-size: 0.9375rem; font-weight: 600; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; color: var(--done); }
.feedback.idle { color: var(--muted); font-weight: 400; }
.feedback button {
  background: none; border: 0; padding: 8px 4px; min-height: 44px; text-decoration: underline; color: var(--accent); font-weight: 700;
}
.feedback .note { color: var(--muted); font-weight: 400; flex-basis: 100%; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 0.75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 2px 10px; border: 1px solid #8b8170; border-radius: 99px; font-size: 0.8125rem; }

.prose { display: grid; gap: 14px; font-size: 1.0625rem; line-height: 1.65; max-width: 62ch; }
.prose p.outcome { border-left: 4px solid var(--accent); padding: 4px 0 4px 14px; background: linear-gradient(90deg, #f9ece6, transparent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.3);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 16px 16px 12px; gap: 12px; overflow: visible; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-name { font-size: 1.25rem; }
  .overview .side-label, .progress-card { display: none; }
  .views { flex-direction: row; overflow-x: auto; gap: 8px; padding-bottom: 4px; scrollbar-width: thin; }
  .view-btn { width: auto; flex: none; border-color: rgba(255,255,255,.25); padding: 6px 12px; }
  .main { padding: 20px 16px 48px; }
  .title { font-size: 1.875rem; }
  .controls { grid-template-columns: 1fr; gap: 12px; }
  .item { grid-template-columns: 1fr; padding-right: 14px; }
  .item .chip { justify-self: start; grid-row: 2; }
  .meta { grid-row: 3; }
  dialog.detail { width: 100vw; animation-name: rise; }
  .d-title { font-size: 1.5rem; }
  .facts { grid-template-columns: 1fr 1fr; }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

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