:root {
  --bg: #f5f5f6;
  --panel: #fff;
  --ink: #18181b;
  --muted: #6b6b74;
  --line: #e3e3e7;
  --accent: #2f6bff;
  --accent-ink: #fff;
  --danger: #d92d20;
  --ok: #12925a;
  --canvas: #e6e6ea;
  --radius: 8px;
  --top: 52px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; left: 7px; top: 5px; width: 5px; height: 9px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
#who a { color: var(--ink); font-weight: 500; }
#who { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); min-width: 0; }
#who .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #c9c9d0; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 28px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; }
.link.muted { color: var(--muted); }
input[type=text], input[type=email], input[type=number], select, textarea { height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); width: 100%; }
select { padding-right: 28px; }
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
label.field { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
label.field > input, label.field > select { margin-top: 6px; font-weight: 400; font-size: 15px; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* pages */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* auth */
.auth { max-width: 400px; margin: 8vh auto; padding: 32px; }
.auth h1 { font-size: 22px; margin-bottom: 6px; }
.auth p.lead { color: var(--muted); margin: 0 0 22px; }
.auth .btn { width: 100%; height: 40px; }
.code-input { font-size: 24px !important; letter-spacing: 8px; text-align: center; height: 52px !important; }

/* project list */
.new-project { padding: 16px; margin-bottom: 20px; }
.np-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.np-row > input { flex: 1 1 200px; width: auto; }
.np-row > select { width: auto; }
.np-row > label { display: flex; align-items: center; gap: 6px; margin-right: 10px; }
.np-team { margin-top: 12px; font-size: 14px; }
.np-team summary { cursor: pointer; color: var(--muted); }
.picks { display: grid; gap: 6px; margin: 10px 0; }
.pick { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pick > label:first-child { min-width: 160px; }
.pick label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.pick select, .members select, .tteam select { width: auto; height: 30px; font-size: 13px; }
.tteam { width: 100%; border-collapse: collapse; font-size: 14px; }
.tteam th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tteam td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.addmate { padding: 16px; margin-top: 20px; display: grid; gap: 12px; }
.addmate h2 { margin: 0; }
.addmate .np-row > select { flex: none; }
.plist { display: grid; gap: 10px; }
.prow { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; }
.prow .title { font-weight: 600; font-size: 16px; color: var(--ink); }
.prow .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.prow.archived { opacity: .6; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; }
.badge.grey { background: #e4e4e7; color: var(--muted); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }

/* screen grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.scard { overflow: hidden; display: flex; flex-direction: column; }
.scard .thumb { display: block; height: 200px; background: var(--canvas); overflow: hidden; border-bottom: 1px solid var(--line); position: relative; }
.scard .thumb img { width: 100%; display: block; }
.scard .thumb .badge { position: absolute; top: 10px; right: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.scard .body { padding: 10px 12px; display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.scard .title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.scard .meta { font-size: 12px; color: var(--muted); }
.scard .tools { display: flex; gap: 4px; flex-wrap: wrap; padding: 0 12px 12px; }
.dropping { outline: 3px dashed var(--accent); outline-offset: -8px; }
.uploadbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 18px; }
.uploadbar select { width: auto; }
.uploadbar label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.members { margin-top: 36px; padding: 16px; }
.members table { width: 100%; border-collapse: collapse; font-size: 14px; }
.members td { padding: 8px 6px; border-top: 1px solid var(--line); }
.sharebox { display: flex; gap: 8px; align-items: center; padding: 12px 14px; margin-bottom: 18px; }
.sharebox input { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* viewer */
body.viewing { overflow: hidden; }
.viewer { height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); display: flex; flex-direction: column; }
.vbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.vbar .grow { flex: 1; }
.vbar select { width: auto; max-width: 260px; height: 30px; font-size: 14px; }
.vbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); height: 28px; padding: 0 10px; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--ink); color: #fff; }
.vbar .scale { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vmain { flex: 1; display: flex; min-height: 0; }
.canvas { flex: 1; overflow: auto; background: var(--canvas); position: relative; }
.stage-wrap { padding: 24px; display: flex; justify-content: center; min-width: min-content; }
.stage { position: relative; flex: none; box-shadow: 0 1px 4px rgba(0,0,0,.12); background: #fff; cursor: crosshair; }
.stage.readonly { cursor: default; }
.stage img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.banner { padding: 8px 14px; background: #fff7e0; border-bottom: 1px solid #f1dfa5; font-size: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.pin { position: absolute; width: 28px; height: 28px; margin: -28px 0 0 0; border-radius: 50% 50% 50% 0; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); cursor: pointer; z-index: 2; padding: 0; transform-origin: 0 100%; }
.pin.team { background: var(--ink); }
.pin.resolved { background: var(--ok); opacity: .8; }
.pin.active { transform: scale(1.18); z-index: 4; }
.pin.draft { background: var(--accent); }

.pop { position: absolute; z-index: 5; width: 320px; max-width: calc(100vw - 32px); background: var(--panel); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.22); border: 1px solid var(--line); cursor: default; font-size: 14px; }
.pop-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.pop-head .grow { flex: 1; font-weight: 600; }
.pop-body { max-height: 320px; overflow: auto; padding: 4px 12px; }
.pop-foot { padding: 10px 12px; border-top: 1px solid var(--line); }
.pop-foot textarea { min-height: 64px; margin-bottom: 8px; }
.pop-foot .row { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.pop-foot .hint { flex: 1; font-size: 12px; color: var(--muted); }
.cmt { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cmt:last-child { border-bottom: 0; }
.cmt .who { display: flex; gap: 6px; align-items: baseline; font-size: 13px; }
.cmt .who b { font-weight: 600; }
.cmt .who .tag { font-size: 11px; padding: 0 5px; border-radius: 4px; background: #eef2ff; color: var(--accent); }
.cmt .who .when { color: var(--muted); font-size: 12px; margin-left: auto; }
.cmt .text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 3px; }
.cmt .del { font-size: 12px; }

.side { width: 320px; flex: none; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.side-head .row { display: flex; justify-content: space-between; align-items: center; }
.side-list { overflow: auto; flex: 1; }
.titem { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.titem:hover, .titem.active { background: #f6f7fb; }
.titem .num { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.titem.team .num { background: var(--ink); }
.titem.resolved .num { background: var(--ok); }
.titem .ex { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.titem .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.side-empty { padding: 24px 16px; color: var(--muted); font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
#toast.err { background: var(--danger); }

@media (max-width: 860px) {
  .vmain { flex-direction: column; }
  .side { width: auto; height: 38vh; border-left: 0; border-top: 1px solid var(--line); }
  .stage-wrap { padding: 12px; }
  .vbar .hide-sm { display: none; }
  .top { padding: 0 14px; }
  #who .name { max-width: 120px; }
}
.addmate > .btn { justify-self: start; }
