/* ---------- Theme tokens ----------
   Defaults (Graphite). The active theme overwrites these inline on <html> from app.js. */
:root {
  --bg: #1f1f1f;
  --ink: #e6e6e6;
  --head: #f2f2f2;
  --heading: #f2f2f2;
  --rule: #8c8c8c;
  --title-line: transparent;
  --done: #9b9b9b;
  --muted: #9b9b9b;
  --ring: #8c8c8c;
  --check: #8c3fd6;
  --check-ink: #ffffff;
  --dot: rgba(255, 255, 255, 0.06);
  --ui: #2b2b2b;
  --ui-ink: #e6e6e6;
  --ui-line: #404040;
  --accent: #9b5de5;
  --accent-ink: #ffffff;
  --head-font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --body-font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --head-weight: 400;
  --head-case: none;
  --head-stretch: normal;
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body-font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
svg { display: block; }
[hidden] { display: none !important; }

/* ---------- Canvas ---------- */
#viewport {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: grab;
  background-image: radial-gradient(circle, var(--dot) 1.2px, transparent 1.6px);
  background-size: var(--g, 24px) var(--g, 24px);
  background-position: var(--gx, 0) var(--gy, 0);
}
#viewport.panning { cursor: grabbing; }
#world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.card {
  position: absolute;
  padding: 4px 10px 8px 6px;
  border-radius: 8px;
  outline: 1px solid transparent;
  transition: outline-color 0.15s;
  cursor: auto;
}
.card:hover,
.card:focus-within,
.card.dragging { outline-color: var(--ui-line); }
.card.dragging { z-index: 5; }

.bar {
  display: flex;
  align-items: flex-start;
  gap: 2px;
}
.grip {
  flex: none;
  width: 22px;
  height: 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
  opacity: 0.25;
  cursor: grab;
  touch-action: none;
  border-radius: 4px;
  transition: opacity 0.15s;
}
.card:hover .grip,
.card:focus-within .grip { opacity: 0.85; }
@media (hover: none) { .grip { opacity: 0.55; } }
.dragging .grip { cursor: grabbing; }

.title {
  flex: 1;
  min-width: 0;
  font-family: var(--head-font);
  font-weight: var(--head-weight);
  text-transform: var(--head-case);
  font-stretch: var(--head-stretch);
  color: var(--head);
  font-size: 22px;
  line-height: 1.25;
  padding: 2px 2px 4px;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  letter-spacing: 0.01em;
}
.heading .title {
  font-size: 30px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  margin-top: 6px;
}
.heading .grip { margin-top: 16px; }
.list .title { border-bottom: 1px solid transparent; }
.list .title { border-bottom-color: var(--title-line); }
.heading .title { color: var(--heading); }

.items { padding-left: 22px; padding-top: 2px; }
.item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding-left: calc(var(--i, 0) * 22px);
  min-height: 22px;
}
.box {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2.5px;
  border-radius: 50%;
  border: 1.5px solid var(--ring);
  display: grid;
  place-items: center;
  color: transparent;
}
.box svg { width: 11px; height: 11px; }
.done > .box { background: var(--check); border-color: var(--check); color: var(--check-ink); }
.dot {
  flex: none;
  width: 16px;
  text-align: center;
  line-height: 21px;
  color: var(--muted);
}
.nomark { flex: none; width: 0; margin-left: -7px; }
.text {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  line-height: 21px;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 3px;
}
.done > .text { color: var(--done); }
.item.active > .text { background: color-mix(in srgb, var(--ink) 7%, transparent); }

[contenteditable]:empty::before {
  content: attr(data-ph);
  color: var(--muted);
  opacity: 0.55;
  pointer-events: none;
}

.resize {
  position: absolute;
  top: 8px;
  right: -6px;
  bottom: 8px;
  width: 12px;
  cursor: ew-resize;
  touch-action: none;
}
.resize::after {
  content: "";
  position: absolute;
  right: 5px;
  top: 50%;
  height: 26px;
  width: 3px;
  margin-top: -13px;
  border-radius: 2px;
  background: var(--ui-line);
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .resize::after,
.card:focus-within .resize::after { opacity: 1; }

/* ---------- Chrome ---------- */
.chip {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--ui);
  color: var(--ui-ink);
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  padding: 3px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  z-index: 20;
  font-family: var(--body-font);
}
.icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
}
.icon:hover { background: color-mix(in srgb, var(--ui-ink) 10%, transparent); }
.icon svg { width: 19px; height: 19px; }

#boardbar {
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  max-width: calc(100vw - 190px);
  padding: 3px 12px 3px 10px;
  gap: 9px;
}
#status {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
#status[data-s="synced"] { background: #4caf7a; }
#status[data-s="syncing"],
#status[data-s="pending"] { background: #e0a83a; }
#status[data-s="offline"],
#status[data-s="error"] { background: #d9534f; }
#status[data-s="local"] { background: var(--muted); }
#boardTitle {
  font-family: var(--head-font);
  font-weight: var(--head-weight);
  font-size: 17px;
  line-height: 32px;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 60px;
}

#actions {
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
}
#zoombar {
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
}
#zoomLabel {
  min-width: 48px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#fab {
  position: fixed;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(68px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  z-index: 20;
}
#fab svg { width: 24px; height: 24px; }

#edittools {
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 30;
}
#edittools .sep { width: 1px; height: 24px; background: var(--ui-line); margin: 0 2px; }
@media (max-width: 760px) {
  body.editing #zoombar,
  body.editing #fab { display: none; }
}
@media (max-width: 520px) {
  #edittools .icon { width: 36px; }
  #edittools .opt { display: none; }
}

/* ---------- Menus, dialogs, toast ---------- */
.menu {
  position: fixed;
  z-index: 40;
  min-width: 190px;
  background: var(--ui);
  color: var(--ui-ink);
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  padding: 5px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  font-size: 14px;
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
}
.menu button svg { width: 17px; height: 17px; opacity: 0.8; }
.menu button:hover { background: color-mix(in srgb, var(--ui-ink) 10%, transparent); }
.menu .danger { color: #e26d5a; }
.menu hr { border: 0; border-top: 1px solid var(--ui-line); margin: 4px 6px; }

dialog {
  background: var(--ui);
  color: var(--ui-ink);
  border: 1px solid var(--ui-line);
  border-radius: 16px;
  padding: 18px;
  width: min(440px, calc(100vw - 24px));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  font-family: var(--body-font);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 {
  margin: 0 0 12px;
  font-family: var(--head-font);
  font-weight: var(--head-weight);
  font-size: 20px;
}
dialog p { font-size: 13.5px; line-height: 1.5; color: color-mix(in srgb, var(--ui-ink) 80%, transparent); margin: 0 0 12px; }
dialog .row { display: flex; gap: 8px; margin-bottom: 12px; }
dialog input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13.5px;
  color: inherit;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px solid var(--ui-line);
  border-radius: 9px;
  padding: 9px 10px;
}
.btn {
  flex: none;
  padding: 9px 14px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13.5px;
  font-weight: 600;
}
.btn.ghost { background: transparent; border: 1px solid var(--ui-line); color: inherit; font-weight: 500; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
dialog h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin: 16px 0 8px; opacity: 0.7; font-weight: 600; }
.boards button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
}
.boards button:hover { background: color-mix(in srgb, var(--ui-ink) 10%, transparent); }
.boards .cur { opacity: 0.6; font-size: 12px; }

/* Theme panel: non-modal so the canvas stays visible as a live preview */
#themeDlg[open] {
  position: fixed;
  inset: calc(64px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) auto;
  margin: 0;
  width: min(380px, calc(100vw - 20px));
  height: auto;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 35;
  padding: 14px 14px 0;
}
@media (max-width: 600px) {
  #themeDlg[open] {
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 58dvh;
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}
.tp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.tp-head h2 { flex: 1; margin: 0 0 0 4px; }
.tp-head .icon { flex: none; }
.tp-name {
  flex: 1;
  font-family: var(--head-font) !important;
  font-size: 17px !important;
  font-weight: 600;
}
.tp-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 12px 0 14px;
  margin-top: 8px;
  background: var(--ui);
  border-top: 1px solid var(--ui-line);
}
.tp-foot .spacer { flex: 1; }

.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme-opt {
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--ui-line);
  text-align: left;
}
.theme-opt[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.theme-opt .sw { display: flex; height: 14px; }
.theme-opt .sw span { flex: 1; }
.theme-opt .pv { padding: 10px 10px 9px; }
.theme-opt .nm { font-size: 13.5px; font-weight: 700; display: block; margin-bottom: 7px; }
.theme-opt .ln { display: flex; align-items: center; gap: 6px; font-size: 11.5px; margin-top: 3px; }
.theme-opt .ln i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid; flex: none; }
.theme-opt .tag { font-size: 10.5px; opacity: 0.7; font-weight: 500; margin-left: 4px; }

.pal { display: flex; flex-wrap: wrap; gap: 8px; }
.pal .sw-btn,
.pal .add {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--ui-line);
  position: relative;
}
.pal .sw-btn[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ui), 0 0 0 4px var(--ui-ink); }
.pal .add { display: grid; place-items: center; border-style: dashed; }
.pal .add svg { width: 16px; height: 16px; }
.sw-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ui-ink) 6%, transparent);
  font-size: 12.5px;
}
.sw-edit input[type="color"] {
  flex: none;
  width: 40px;
  height: 34px;
  padding: 2px;
  border-radius: 8px;
  cursor: pointer;
}
.sw-edit .hex { flex: none; width: 92px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.sw-edit .used { flex: 1; opacity: 0.75; }
.sw-edit .btn { padding: 7px 10px; }
.btn:disabled { opacity: 0.4; cursor: default; }

.role { padding: 8px 0; border-bottom: 1px solid color-mix(in srgb, var(--ui-line) 60%, transparent); }
.role-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 7px; }
.cr {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ui-ink) 9%, transparent);
}
.cr.bad { background: #b8433033; color: #ff8a73; }
.role-dots { display: flex; flex-wrap: wrap; gap: 6px; }
.rd {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--ui-ink) 25%, transparent);
}
.rd[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ui), 0 0 0 4px var(--ui-ink); }
.tog { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 12px 0 4px; cursor: pointer; }
.tog input { width: 18px; height: 18px; accent-color: var(--accent); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ui);
  color: var(--ui-ink);
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}
#toast button { color: var(--accent); font-weight: 700; }
