:root {
  color-scheme: light;
  --paper: #f3eee3;
  --card: #fffdf8;
  --ink: #1d2823;
  --muted: #55625b;
  --line: #d9d1c0;
  --line-strong: #b9ae97;
  --accent: #1f5c4a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe3;
  --focus: #0b57d0;

  --todo-fg: #38495a;   --todo-bg: #e3e9ef;
  --prog-fg: #124f94;   --prog-bg: #dce9f8;
  --block-fg: #9a2f1a;  --block-bg: #f8e0d9;
  --done-fg: #1d6b40;   --done-bg: #dcefe2;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, 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-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: rgba(31, 92, 74, .15);
}

body.lock { overflow: hidden; }

button, input, select { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }

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

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

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  padding: 28px 18px 24px;
  border-right: 1px solid var(--line);
  background: #ebe5d6;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand-name {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--ink);
}

.views-title {
  margin: 0 0 8px 10px;
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.views-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.view-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  text-align: left;
  transition: background-color .15s, color .15s;
}
.view-btn:hover { background: rgba(31, 92, 74, .12); }
.view-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.view-btn .n { font-variant-numeric: tabular-nums; font-size: .875rem; opacity: .85; }

.sidebar-note { margin: auto 0 0; font-size: .8125rem; color: var(--muted); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}
.workspace.has-detail { grid-template-columns: minmax(0, 1fr) 440px; }

.main { padding: 36px 36px 80px; min-width: 0; outline: none; }

.page-head h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.4rem;
  line-height: 1.1;
  letter-spacing: -.02em;
  text-wrap: balance;
}
.page-sub { margin: 6px 0 0; color: var(--muted); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 14px; margin: 26px 0 10px; flex-wrap: wrap; }
.field { display: grid; gap: 4px; min-width: 0; }
.field.grow { flex: 1 1 260px; }
.field label { font-size: .8125rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .status-select {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background-color: var(--card);
  color: var(--ink);
  width: 100%;
}
.field select { min-width: 190px; }
.field input:hover, .field select:hover, .status-select:hover { border-color: var(--accent); }
.field input:focus-visible, .field select:focus-visible, .status-select:focus-visible { outline-offset: 0; border-color: var(--focus); }

.count { margin: 14px 2px 10px; font-size: .875rem; color: var(--muted); min-height: 1.3em; }

/* ---------- List ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.task {
  position: relative;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto auto;
  grid-template-areas: "av main due status";
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.task:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(29, 40, 35, .08); }
.task.is-open { border-color: var(--accent); background: #f4faf6; box-shadow: inset 4px 0 0 var(--accent); }

.avatar {
  grid-area: av;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: .85rem;
  letter-spacing: .02em;
}

.task-main { grid-area: main; min-width: 0; }
.open-item {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-family: var(--serif);
  font-size: 1.1875rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}
.open-item::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.open-item:focus-visible { outline: none; }
.open-item:focus-visible::after { outline: 3px solid var(--focus); outline-offset: 2px; }

.task-meta {
  margin: 3px 0 0;
  font-size: .875rem;
  color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 2px 14px;
}
.task-meta span { white-space: nowrap; }
.prio { display: inline-flex; align-items: center; gap: 6px; }
.prio::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.prio-high { color: var(--block-fg); }
.prio-medium { color: #8a5a00; }
.prio-low { color: var(--muted); }

.due { grid-area: due; font-size: .875rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill {
  grid-area: status;
  justify-self: end;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; background: currentColor; flex: none; }
.pill[data-status="todo"] { background: var(--todo-bg); color: var(--todo-fg); }
.pill[data-status="todo"]::before { border-radius: 50%; background: transparent; border: 2px solid currentColor; }
.pill[data-status="in-progress"] { background: var(--prog-bg); color: var(--prog-fg); }
.pill[data-status="in-progress"]::before { border-radius: 50%; background: linear-gradient(90deg, currentColor 50%, transparent 50%); border: 2px solid currentColor; }
.pill[data-status="blocked"] { background: var(--block-bg); color: var(--block-fg); }
.pill[data-status="blocked"]::before { transform: rotate(45deg); }
.pill[data-status="done"] { background: var(--done-bg); color: var(--done-fg); }
.pill[data-status="done"]::before { border-radius: 50%; }

.workspace.has-detail .due { display: none; }

/* ---------- Empty ---------- */
.empty {
  margin-top: 8px;
  padding: 48px 24px;
  text-align: center;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .6);
}
.empty h2 { margin: 0 0 6px; font-family: var(--serif); font-size: 1.5rem; }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 40ch; overflow-wrap: anywhere; }

.btn {
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  transition: background-color .15s, color .15s;
}
.btn:hover { background: #17463a; }
.btn.secondary { background: transparent; color: var(--accent); }
.btn.secondary:hover { background: var(--accent-soft); }

/* ---------- Detail ---------- */
.detail-slot { min-width: 0; }
.detail {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.detail:focus { outline: none; }

.detail-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.detail-bar .kicker { font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.close-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  font-weight: 600;
  transition: background-color .15s, border-color .15s;
}
.close-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.close-btn .back { display: none; }

.detail-body { padding: 22px 24px 40px; display: grid; gap: 22px; }
.detail h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
.detail h2:focus { outline: none; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.tags li { padding: 2px 10px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: .8125rem; color: var(--muted); }

.body { white-space: pre-line; overflow-wrap: anywhere; font-size: 1.0625rem; line-height: 1.6; }

.status-box {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  display: grid; gap: 8px;
}
.status-box label { font-weight: 600; }
.status-select { background-color: #fff; }
.feedback { margin: 0; font-size: .9375rem; min-height: 1.4em; color: var(--done-fg); font-weight: 500; }
.feedback.note { color: var(--muted); }
.hint { margin: 0; font-size: .875rem; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 0);
  z-index: 60;
  max-width: min(520px, calc(100vw - 24px));
  pointer-events: none;
}
.toast-inner {
  pointer-events: auto;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 10px 10px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .2s ease-out;
}
.toast-inner span { overflow-wrap: anywhere; }
.toast-inner button {
  flex: none;
  min-height: 40px; padding: 6px 14px;
  background: transparent; color: #fff;
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 8px; font-weight: 600;
}
.toast-inner button:hover { background: rgba(255, 255, 255, .16); border-color: #fff; }
.toast-inner button:focus-visible { outline-color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Narrow desktop ---------- */
@media (max-width: 1180px) {
  .workspace.has-detail { grid-template-columns: minmax(0, 1fr) 400px; }
  .main { padding: 28px 24px 80px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .app { display: block; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px 10px;
    gap: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand-name { font-size: 1.25rem; }
  .views-title, .sidebar-note { display: none; }
  .views { margin: 0 -16px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
  .views::-webkit-scrollbar { display: none; }
  .views-list { display: flex; gap: 6px; padding-bottom: 4px; }
  .view-btn {
    width: auto; white-space: nowrap; min-height: 40px;
    border: 1px solid var(--line-strong); border-radius: 999px; padding: 6px 14px; gap: 10px;
  }
  .view-btn[aria-pressed="true"] { border-color: var(--accent); }

  .workspace.has-detail { grid-template-columns: minmax(0, 1fr); }
  .main { padding: 20px 16px 72px; }
  .page-head h1 { font-size: 1.9rem; }
  .toolbar { margin-top: 18px; gap: 10px; }
  .field select { min-width: 0; }
  .toolbar .field { flex: 1 1 100%; }

  .task {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "main main" "due status";
    gap: 10px 12px;
    padding: 14px;
  }
  .avatar { display: none; }
  .workspace.has-detail .due { display: block; }
  .due { align-self: center; }

  .detail {
    position: fixed;
    inset: 0;
    z-index: 50;
    height: auto;
    border-left: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .detail-bar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .close-btn .back { display: inline; }
  .close-btn .x { display: none; }
  .detail-body { padding: 18px 16px 40px; }
  .detail h2 { font-size: 1.5rem; }
  .facts { grid-template-columns: 1fr 1fr; }
}

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