:root {
  --ink: #16181D;
  --sub: #6B7280;
  --line: #E5E7EB;
  --bg: #F4F5F7;
  --card: #FFFFFF;
  --accent: #4F46E5;
  --accent-d: #4338CA;
  --accent-soft: #EEF0FF;
  --danger: #DC2626;
  --ok: #15A34A;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px -12px rgba(16,24,40,.18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 22px;
  background: #15171C; color: #fff;
  border-bottom: 1px solid #000;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--accent);
  position: relative;
}
.logo::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 11px; height: 11px; border-radius: 50%; background: #fff;
}
.brand-text { min-width: 0; }
.tool-name { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: #9aa0ac; }
.proj-title { font-size: 16px; font-weight: 650; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 16px; }
.proj-switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #9aa0ac; }
.proj-switch select {
  font: inherit; font-size: 13px; color: #fff; background: #24262d;
  border: 1px solid #34373f; border-radius: 9px; padding: 7px 10px;
}
.who {
  font-size: 13px; color: #cbd0d9; max-width: 220px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.who .you-name { color: #fff; font-weight: 600; }

/* ---------- Mode banner ---------- */
.mode-banner {
  padding: 9px 22px; font-size: 13px;
  background: #FEF3C7; color: #92400E; border-bottom: 1px solid #FDE68A;
}
.mode-banner b { font-weight: 700; }

/* ---------- Board ---------- */
.board { padding: 26px 22px 80px; max-width: 1320px; margin: 0 auto; }
.loading { color: var(--sub); padding: 40px 0; }
.proj-head { margin: 4px 0 22px; }
.proj-head h1 { margin: 0; font-size: 22px; font-weight: 700; }
.proj-head p { margin: 6px 0 0; color: var(--sub); font-size: 14px; max-width: 60ch; }

.flow { margin: 0 0 38px; }
.flow-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 14px; }
.flow-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.flow-head .flow-note { color: var(--sub); font-size: 13px; }
.flow-head .flow-count {
  margin-left: auto; font-size: 12px; color: var(--sub);
  background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}

.row {
  display: flex; gap: 18px; align-items: flex-start;
  overflow-x: auto; padding: 4px 2px 14px;
  scroll-snap-type: x proximity;
}
.row::-webkit-scrollbar { height: 8px; }
.row::-webkit-scrollbar-thumb { background: #d4d7de; border-radius: 8px; }

.card {
  flex: none; width: 168px; scroll-snap-align: start;
  border: 0; background: transparent; padding: 0; text-align: left;
}
.card .frame {
  position: relative; width: 168px; aspect-ratio: 393 / 852;
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); overflow: hidden;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.card:hover .frame { transform: translateY(-3px); box-shadow: 0 12px 30px -14px rgba(16,24,40,.35); border-color: #d0d3da; }
.card:focus-visible .frame { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .step {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  font-size: 11px; font-weight: 700; color: #fff; background: rgba(22,24,29,.55);
  border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px);
}
.card .badge {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  display: none; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--accent);
  border-radius: 999px; padding: 3px 8px; box-shadow: 0 2px 6px rgba(79,70,229,.4);
}
.card .badge.has { display: inline-flex; }
.card .badge.all-resolved { background: var(--ok); }
.card .cap { margin: 10px 2px 0; }
.card .cap .cap-name { font-size: 13.5px; font-weight: 600; }
.card .cap .cap-sub { font-size: 12px; color: var(--sub); margin-top: 1px; }

/* connector arrows between screens in a flow */
.connector { flex: none; align-self: center; color: #c4c8d0; font-size: 20px; padding-top: 0; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16,18,24,.62); backdrop-filter: blur(3px); }
.modal-panel {
  position: relative; z-index: 1; width: min(1180px, 95vw); height: min(92vh, 920px);
  background: #fff; border-radius: 18px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.mh-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mh-title { min-width: 0; }
.mh-flow { font-size: 12px; color: var(--sub); text-transform: uppercase; letter-spacing: .04em; }
.mh-screen { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }
.mh-nav { display: flex; align-items: center; gap: 8px; }
.nav-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.nav-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.nav-btn:disabled { opacity: .35; cursor: default; }
.nav-count { font-size: 13px; color: var(--sub); min-width: 64px; text-align: center; }

.modal-body { flex: 1; display: flex; min-height: 0; }

/* stage with the device */
.stage {
  flex: 1; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 22px;
  background: radial-gradient(circle at 50% 30%, #fbfbfc 0%, #eef0f3 100%);
}
.device {
  position: relative; height: min(74vh, 720px); aspect-ratio: 393 / 852;
  border-radius: 30px; overflow: hidden; background: #fff;
  box-shadow: 0 2px 0 1px #d7d7d7, 0 30px 60px -28px rgba(16,24,40,.5), 0 0 0 9px #2a2d33, 0 0 0 11px #3a3e45;
}
.screen-img { width: 100%; height: 100%; display: block; user-select: none; }
.pin-layer { position: absolute; inset: 0; cursor: crosshair; }

/* pins */
.pin {
  position: absolute; transform: translate(-50%, -50%);
  width: 26px; height: 26px; border-radius: 50% 50% 50% 2px;
  background: var(--accent); color: #fff; border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(79,70,229,.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; cursor: pointer; z-index: 2;
  transition: transform .12s ease;
}
.pin:hover { transform: translate(-50%, -50%) scale(1.12); }
.pin.resolved { background: var(--ok); box-shadow: 0 3px 8px rgba(21,163,74,.45); }
.pin.active { transform: translate(-50%, -50%) scale(1.18); box-shadow: 0 0 0 4px rgba(79,70,229,.25), 0 3px 8px rgba(79,70,229,.5); }
.pin.draft { background: #fff; color: var(--accent); border: 2px dashed var(--accent); }

/* composer popover */
.composer {
  position: absolute; z-index: 5; width: 268px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 14px 40px -10px rgba(16,24,40,.4); padding: 12px;
}
.composer textarea {
  width: 100%; min-height: 78px; resize: vertical; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; color: var(--ink);
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .row-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.btn {
  font-size: 13px; font-weight: 600; border-radius: 9px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn.primary:disabled { opacity: .5; cursor: default; }

.stage-hint { margin: 0; font-size: 12.5px; color: var(--sub); }

/* thread panel */
.thread {
  width: 360px; flex: none; border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; background: #fff;
}
.thread-head {
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; justify-content: space-between;
}
.thread-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.thread-head .count { font-size: 12px; color: var(--sub); }
.thread-list { flex: 1; overflow-y: auto; padding: 8px 12px 20px; }
.thread-empty { color: var(--sub); font-size: 13px; padding: 24px 8px; text-align: center; line-height: 1.5; }

.cmt {
  display: flex; gap: 10px; padding: 11px 8px; border-radius: 10px;
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.cmt:hover { background: var(--bg); }
.cmt.active { background: var(--accent-soft); border-color: #d6d8fb; }
.cmt.resolved { opacity: .62; }
.cmt .num {
  flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.cmt.resolved .num { background: var(--ok); }
.cmt .body { min-width: 0; flex: 1; }
.cmt .meta { font-size: 12px; color: var(--sub); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cmt .meta .who-name { color: var(--ink); font-weight: 600; }
.cmt .text { font-size: 14px; line-height: 1.45; margin: 3px 0 0; white-space: pre-wrap; word-break: break-word; }
.cmt .acts { display: flex; gap: 12px; margin-top: 6px; }
.cmt .acts button { border: 0; background: none; padding: 0; font-size: 12px; font-weight: 600; color: var(--sub); }
.cmt .acts button:hover { color: var(--ink); }
.cmt .acts button.del:hover { color: var(--danger); }
.cmt .acts button.resolve.on { color: var(--ok); }

@media (max-width: 820px) {
  .modal-body { flex-direction: column; }
  .thread { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 38vh; }
  .device { height: 52vh; }
}
