/* Design tokens. Redefined for dark mode below rather than scattered inline. */
:root {
  --bg: #f4f5f7;
  --canvas: #eceef1;
  --grid: #d8dce2;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #d3d8e0;
  --text: #16191d;
  --text-dim: #5c6572;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --todo: #8b93a1;
  --doing: #2f7fe0;
  --blocked: #d9534f;
  --done: #1f9d61;
  --shadow: 0 1px 2px rgba(16, 20, 28, .08), 0 4px 12px rgba(16, 20, 28, .06);
  --radius: 10px;
  --node-w: 208px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b;
    --canvas: #101216;
    --grid: #22262e;
    --surface: #1b1e24;
    --surface-2: #22262e;
    --border: #2f3540;
    --text: #e7eaef;
    --text-dim: #99a2b0;
    --accent: #7c7cf0;
    --todo: #78808e;
    --doing: #4a93ec;
    --blocked: #e2655f;
    --done: #2bb673;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --canvas: #101216; --grid: #22262e; --surface: #1b1e24;
  --surface-2: #22262e; --border: #2f3540; --text: #e7eaef; --text-dim: #99a2b0;
  --accent: #7c7cf0; --todo: #78808e; --doing: #4a93ec; --blocked: #e2655f; --done: #2bb673;
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is `[hidden] { display: none }`, which a class
   selector like `.gate { display: grid }` outranks. Without this, toggling the
   hidden attribute silently does nothing and the login overlay stays on top of
   the app. Applies to .gate, .app, .inspector and .empty-hint. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------- login gate ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 50; }
.gate__card { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow); }
.gate__title { margin: 0; font-size: 20px; }
.gate__hint { margin: 0; color: var(--text-dim); font-size: 13px; }
.gate__input { padding: 10px 12px; font-size: 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.gate__error { margin: 0; min-height: 1.3em; color: var(--blocked); font-size: 13px; }

/* ---------- buttons ---------- */
.btn { font: inherit; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--danger { color: var(--blocked); }
.btn--quiet { background: transparent; border-color: transparent; color: var(--text-dim); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar__brand { font-weight: 650; margin-right: 4px; }
.toolbar__spacer { flex: 1; }
.toolbar__status { color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.toolbar__counts { color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums;
  padding-left: 4px; }
.toolbar__toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px;
  color: var(--text-dim); cursor: pointer; user-select: none; }

.viewport { position: relative; overflow: hidden; background-color: var(--canvas);
  background-image: radial-gradient(var(--grid) 1px, transparent 1px);
  background-size: 22px 22px; touch-action: none; cursor: grab; }
.viewport:active { cursor: grabbing; }
.viewport:focus { outline: none; }
.world { position: absolute; inset: 0; transform-origin: 0 0; }

.edges { position: absolute; overflow: visible; pointer-events: none;
  left: -20000px; top: -20000px; width: 40000px; height: 40000px; }
.nodes { position: absolute; inset: 0; }

/* Edges are drawn in a layer translated by 20000px, so stroke coordinates are
   offset to match. Kept in one place: EDGE_OFFSET in app.js. */
.edge { fill: none; stroke: var(--todo); stroke-width: 2; pointer-events: stroke;
  cursor: pointer; marker-end: url(#arrow); }
.edge:hover { stroke: var(--blocked); stroke-width: 3; }
.edge--draft { stroke: var(--accent); stroke-dasharray: 5 4; pointer-events: none; }
.edges__arrow { fill: var(--todo); }

/* ---------- nodes ---------- */
.node { position: absolute; width: var(--node-w); background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--todo);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 9px 11px;
  cursor: grab; touch-action: none; user-select: none; }
.node:active { cursor: grabbing; }
.node--selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.node--todo    { border-left-color: var(--todo); }
.node--doing   { border-left-color: var(--doing); }
.node--blocked { border-left-color: var(--blocked); }
.node--done    { border-left-color: var(--done); }
.node--done .node__title { text-decoration: line-through; color: var(--text-dim); }
.node--dim { opacity: .45; }

.node__head { display: flex; align-items: flex-start; gap: 7px; }
.node__title { font-weight: 550; word-break: break-word; flex: 1; min-width: 0; }

/* Completion checkbox. A real <button> so it is keyboard reachable and
   announces its pressed state, styled to read as a checkbox. */
.node__check { flex: 0 0 auto; width: 17px; height: 17px; margin-top: 1px; padding: 0;
  display: grid; place-items: center; cursor: pointer; font-size: 11px; line-height: 1;
  border-radius: 5px; border: 1.5px solid var(--border);
  background: var(--surface-2); color: var(--accent-text); }
.node__check[aria-pressed="true"] { background: var(--done); border-color: var(--done); }
.node__check:hover { border-color: var(--done); }
.node__check:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.node__pill { margin-top: 7px; padding: 1px 8px; font: inherit; font-size: 11px;
  border-radius: 999px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-dim); }
.node__pill:hover { filter: brightness(1.06); }
.node__pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.node__pill--doing   { border-color: var(--doing);   color: var(--doing); }
.node__pill--blocked { border-color: var(--blocked); color: var(--blocked); }
.node__pill--done    { border-color: var(--done);    color: var(--done); }
.node__when { display: block; margin-top: 4px; font-size: 11px; color: var(--text-dim); }
.node__meta { display: flex; align-items: center; gap: 6px; margin-top: 6px;
  color: var(--text-dim); font-size: 11.5px; }
.node__bar { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-2);
  border: 1px solid var(--border); overflow: hidden; }
.node__bar-fill { height: 100%; background: var(--done); }

/* Drag handle for creating a link. */
.node__port { position: absolute; right: -7px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--surface); cursor: crosshair; }
.node__collapse { position: absolute; left: -9px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; line-height: 1; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); }

.empty-hint { position: absolute; inset: 0; display: grid; place-items: center;
  margin: 0; color: var(--text-dim); pointer-events: none; }

/* ---------- inspector ---------- */
.inspector { position: absolute; right: 12px; top: 60px; width: 288px; max-height: calc(100% - 76px);
  overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }
.field__input { font: inherit; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); width: 100%; }
.field__input--area { resize: vertical; min-height: 80px; }
.inspector__actions { display: flex; gap: 8px; }
.inspector__tip { margin: 0; color: var(--text-dim); font-size: 11.5px; }
.inspector__tip kbd { font: inherit; font-size: 10.5px; padding: 1px 4px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface-2); }
.inspector__completed { margin: 0; font-size: 12px; color: var(--done); }
.parent-chip { display: inline-flex; align-items: center; gap: 5px; margin: 2px 4px 2px 0;
  padding: 2px 7px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 11.5px; }
.parent-chip button { border: 0; background: none; cursor: pointer; color: var(--text-dim);
  font-size: 13px; line-height: 1; padding: 0; }

@media (max-width: 720px) {
  .inspector { right: 8px; left: 8px; width: auto; top: auto; bottom: 8px; max-height: 50%; }
}
