:root {
  --bg: #F4F5F7;
  --dot: #C9CED8;
  --ink: #1C1F26;
  --ink-2: #5F6573;
  --line: #E6E8EC;
  --panel: #FFFFFF;
  --accent: #1F232B;
  --accent-ink: #FFFFFF;
  --sel: #3D62A8;
  --bar-h: 52px;
  --inv: 1;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

/* ---------- top bar ---------- */

.bar {
  position: fixed;
  z-index: 20;
  top: 0; left: 0; right: 0;
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.bar-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

.btn {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #C9CED8; }
.btn:focus-visible, .picker-list li:focus-visible, .board-label:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.btn.icon { width: 34px; padding: 0; justify-content: center; font-size: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.count { color: var(--ink-2); font-variant-numeric: tabular-nums; }

.zoom { display: inline-flex; align-items: center; gap: 4px; }
.zoom-val { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }

/* ---------- board picker ---------- */

.picker { position: relative; }
.picker-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: min(440px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
  overflow: hidden;
}
.picker-panel[hidden] { display: none; }
.picker-panel input {
  margin: 10px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font: inherit;
  outline: none;
}
.picker-panel input:focus { border-color: var(--sel); }
.picker-list { list-style: none; margin: 0; padding: 0 6px 8px; overflow: auto; }
.picker-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.picker-list li.active, .picker-list li:hover { background: #EEF1F6; }
.picker-list .pl-text { flex: 1; min-width: 0; }
.picker-list .pl-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-list .pl-id { display: block; font-size: 12px; color: var(--ink-2); }
.picker-list .pl-open {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
}
.picker-list .pl-open:hover { background: #E2E6EE; color: var(--ink); }
.picker-empty { padding: 12px; color: var(--ink-2); }

/* ---------- canvas ---------- */

.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1.2px);
  background-size: 24px 24px;
}
.viewport.panning { cursor: grabbing; }

.world {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.board {
  position: absolute;
  background: #FFFFFF;
  box-shadow: 0 0 0 1px rgba(16, 24, 40, .08), 0 2px 8px rgba(16, 24, 40, .06);
  contain: size layout style;
}
.board .ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8A909C;
  font-size: min(calc(14px * var(--inv)), 120px);
  background: repeating-linear-gradient(135deg, #FFFFFF 0 24px, #F7F8FA 24px 48px);
  overflow: hidden;
  text-align: center;
  padding: 0 4%;
}
.board iframe {
  position: absolute;
  left: 0; top: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.board iframe.loaded { opacity: 1; }
.board.has-frame .ph { display: none; }

.board-label {
  position: absolute;
  left: 0;
  bottom: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0 0 min(calc(6px * var(--inv)), 16px) 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-family: inherit;
  font-weight: 500;
  font-size: min(calc(13px * var(--inv)), 72px);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  text-align: left;
}
.board-label:hover { color: var(--sel); text-decoration: underline; }

.note {
  position: absolute;
  margin: 0;
  font-weight: 700;
  font-size: clamp(64px, calc(16px * var(--inv)), 120px);
  line-height: 1.15;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.hint {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(31, 35, 43, .86);
  color: #fff;
  font-size: 12px;
  text-align: center;
  pointer-events: none;
  transition: opacity .4s;
}
.hint.gone { opacity: 0; }

/* ---------- focus mode ---------- */

.focus {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.focus[hidden] { display: none; }
.focus-bar {
  flex: none;
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.focus-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.focus-meta { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.focus-body { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.focus-body.fill iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.focus-body.fixed { overflow: auto; }
.focus-body.fixed .stage { position: relative; margin: 0 auto; }
.focus-body.fixed iframe {
  position: absolute;
  left: 0; top: 0;
  border: 0;
  background: #fff;
  transform-origin: 0 0;
  box-shadow: 0 0 0 1px rgba(16, 24, 40, .08), 0 8px 24px rgba(16, 24, 40, .08);
}

.noscript { position: fixed; inset: 80px 16px auto; text-align: center; }

@media (max-width: 640px) {
  .bar-title, .hint { display: none; }
  .focus-meta, #focusOpen { display: none; }
  .btn { padding: 0 10px; }
}
