:root {
  --bg: #f6f7f9; --fg: #1f2328; --muted: #6b7280; --card: #fff; --border: rgba(15,23,42,.10);
  --accent: #5b5bd6; --accent-soft: rgba(91,91,214,.12); --ok: #30a46c; --warn: #f5a524; --bad: #e5484d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111215; --fg: #e6e8eb; --muted: #9aa0a6; --card: #1c1d22; --border: rgba(255,255,255,.10); --accent: #8d8dff; --accent-soft: rgba(141,141,255,.16); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}
button, select, input { font: inherit; color: inherit; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px 6px; flex-wrap: wrap; }
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: #fff; flex: none; }
.title { font-weight: 650; font-size: 15px; }
.variant { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }
.share { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.share a { color: var(--accent); font-weight: 600; text-decoration: none; }
.presence { display: flex; align-items: center; gap: 10px; }
.peers { display: flex; align-items: center; }
.peer { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; border: 2px solid var(--bg); margin-left: -6px; }
.peers .count { margin-left: 8px; color: var(--muted); font-size: 12.5px; }
.status { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.status[data-status="connecting"] .dot { background: var(--warn); animation: pulse 1s infinite; }
.status[data-status="connected"] .dot { background: var(--warn); }
.status[data-status="synced"] .dot { background: var(--ok); }
@keyframes pulse { 50% { opacity: .3; } }
.tabs { display: flex; gap: 4px; padding: 0 16px; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; cursor: pointer; min-height: 40px; }
.tab.active { color: var(--fg); background: var(--card); box-shadow: 0 -1px 0 var(--border) inset; }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--card); border-top: 1px solid var(--border); }
.tab-panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab-panel.active { display: flex; }
.controls { display: flex; gap: 6px; align-items: center; padding: 8px 12px; overflow-x: auto; flex: none; scrollbar-width: thin; }
.controls > * { flex: none; }
.controls button, .file-btn, .controls select {
  min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 550; font-size: 13px;
}
.controls button:hover, .file-btn:hover { border-color: var(--accent); }
.controls button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.controls button.accent { background: var(--accent); color: #fff; border-color: transparent; }
.file-btn input { display: none; }
.check, .select { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 550; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.sep { width: 1px; align-self: stretch; background: var(--border); margin: 4px 4px; }
.badge { padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 12px; white-space: nowrap; }
.mini { border: 1px solid var(--border); background: var(--card); border-radius: 7px; padding: 2px 8px; font-size: 12px; cursor: pointer; min-height: 28px; }
ink-canvas { flex: 1; min-height: 0; aspect-ratio: auto; }
#ink { margin: 0 8px 8px; border-radius: 12px; }
.hint { margin: 10px 16px 0; color: var(--muted); font-size: 13px; }
.headless-row { flex: 1; min-height: 0; display: flex; gap: 8px; padding: 0 8px 8px; }
.headless-row ink-canvas { border-radius: 12px; }
.api-log { width: 260px; flex: none; border: 1px solid var(--border); border-radius: 12px; padding: 8px; overflow: auto; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.api-log ol { margin: 0; padding-left: 18px; }
.log-title { font-weight: 700; margin-bottom: 4px; font-family: ui-sans-serif, system-ui, sans-serif; }
.swatch-btn { width: 40px; padding: 0 !important; justify-content: center; }
.swatch-btn::before { content: ""; width: 20px; height: 20px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.svg-out { max-height: 30vh; overflow: auto; margin: 0 8px 8px; padding: 8px; border: 1px solid var(--border); border-radius: 12px; font: 11px ui-monospace, monospace; white-space: pre-wrap; word-break: break-all; }
@media (max-width: 760px) { .api-log { display: none; } .share-label { display: none; } .variant { display: none; } }

.debug {
  position: fixed; right: 12px; bottom: 12px; z-index: 10;
  width: min(560px, calc(100vw - 24px)); max-height: min(70dvh, 640px);
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px; border-radius: 16px; background: color-mix(in srgb, var(--card) 94%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--border); box-shadow: 0 12px 40px rgba(15,23,42,.22);
  font-size: 12.5px;
}
.debug[hidden] { display: none; }
.debug-head { cursor: move; touch-action: none; user-select: none; -webkit-user-select: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.debug-head b { font-size: 14px; margin-right: auto; }
.debug-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { background: var(--bg); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat span { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b { font-variant-numeric: tabular-nums; font-size: 13px; }
@media (max-width: 520px) { .debug-grid { grid-template-columns: repeat(2, 1fr); } }
.features { display: flex; flex-wrap: wrap; gap: 4px; }
.feat { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; background: rgba(229,72,77,.12); color: var(--bad); }
.feat.on { background: rgba(48,164,108,.14); color: var(--ok); }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.toggles .check { min-height: 28px; font-size: 12px; }
.counts { color: var(--muted); font-size: 12px; }
.table-wrap { overflow: auto; flex: 1; min-height: 80px; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
th, td { padding: 3px 6px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { position: sticky; top: 0; background: var(--card); font-weight: 700; }
td.ok { color: var(--ok); } td.no { color: var(--bad); }
td.reason { white-space: normal; min-width: 140px; }
.foot { color: var(--muted); font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2328; color: #fff; padding: 8px 14px; border-radius: 10px; font-weight: 600; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.debug.min > :not(.debug-head) { display: none; }
.debug.min { width: auto; }

.fill-dbg { margin-top: 8px; border-top: 1px solid rgba(127,127,127,.25); padding-top: 6px; }
.fill-dbg .log-title { font-weight: 700; margin-bottom: 4px; }
.fill-params { font-size: 11px; opacity: .75; margin-top: 4px; line-height: 1.35; }
