:root {
  --bg: #e8e9ed;
  --bar: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e2e4e9;
  --hover: #f1f2f5;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --bad: #dc2626;
  --bar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- pasek narzędzi ---------- */
#toolbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .05);
  z-index: 10;
  overflow-x: auto;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

.group { display: flex; align-items: center; gap: 4px; flex: none; }
.group.middle { gap: 8px; }
.sep { width: 1px; height: 28px; background: var(--line); margin: 0 4px; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

#toolbar button {
  height: 44px;
  min-width: 44px;
  padding: 0 10px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
#toolbar a.toolbtn {
  height: 44px;
  min-width: 40px;
  padding: 0 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}
#toolbar a.toolbtn[hidden] { display: none; }
#toolbar button:hover, #toolbar a.toolbtn:hover { background: var(--hover); }
#toolbar a.toolbtn svg,
#toolbar button svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
#toolbar button.active,
#toolbar button.toggle[aria-pressed="true"] {
  background: #e7eefc;
  color: var(--accent);
}

.cluster { display: flex; align-items: center; gap: 2px; }
#toolbar .cluster button { min-width: 38px; padding: 0 7px; }

.size span {
  border-radius: 50%;
  background: var(--c, #000);
}
#toolbar .size.active { background: var(--hover); box-shadow: inset 0 0 0 2px var(--line); }

.swatch span {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--c, #000);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
}
#toolbar .swatch.active { background: var(--hover); }
.swatch.active span { box-shadow: 0 0 0 3px var(--bar), 0 0 0 5px var(--c, #000); }

button.primary,
#toolbar button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
#toolbar button.primary:hover { background: #1d4fd8; }

#pageInfo { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 74px; }

#peers { display: flex; gap: 6px; }
.peer {
  height: 30px;
  padding: 0 10px;
  border-radius: 15px;
  background: #ecfdf3;
  color: #166534;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.peer::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

#conn { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); margin-left: 6px; flex: none; }
#conn.on { background: var(--ok); }

/* ---------- obszar stron ---------- */
#viewer {
  position: fixed;
  inset: calc(var(--bar-h) + env(safe-area-inset-top)) 0 0 0;
  overflow: auto;
  touch-action: none;           /* przewijanie palcem obsługuje app.js, rysik zawsze pisze */
  overscroll-behavior: contain;
}

#pages { padding: 16px 0 40px; margin: 0 auto; }

.page {
  position: relative;
  margin: 0 auto 16px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 4px 16px rgba(0, 0, 0, .06);
  cursor: crosshair;
}
.page::before {
  content: attr(data-n);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c4c7ce;
  font-size: 28px;
  font-weight: 600;
}
.page canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#pages.erasing .page { cursor: cell; }

#empty, #loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  touch-action: manipulation;
}
#empty[hidden], #loading[hidden] { display: none; }
#empty h1 { margin: 0 0 8px; font-size: 28px; }
#empty p { margin: 0 0 20px; color: var(--muted); max-width: 420px; }
#empty .hint { margin-top: 18px; font-size: 14px; }
button.big { height: 52px; padding: 0 26px; border-radius: 14px; font-size: 17px; }
#loading { color: var(--muted); font-weight: 600; }

#uploadDialog {
  border: 0;
  border-radius: 16px;
  padding: 22px;
  width: min(380px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  color: var(--ink);
  background: var(--bar);
}
#uploadDialog::backdrop { background: rgba(15, 18, 25, .45); }
#uploadDialog h2 { margin: 0 0 16px; font-size: 18px; }
#uploadDialog form { display: flex; flex-direction: column; }
#uploadDialog button {
  height: 48px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
}
#uploadDialog button.danger { background: #fef2f2; color: var(--bad); }
#uploadDialog button.plain { color: var(--muted); margin-top: 4px; }
#uploadDialog p { margin: 6px 4px 14px; font-size: 13px; color: var(--muted); }

#colorInput { position: fixed; left: 12px; top: 12px; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #1f2328;
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* iPad pionowo: powiększanie zostaje pod gestem dwóch palców */
@media (max-width: 1060px) {
  .zoomctl { display: none !important; }
  #share span { display: none; }
  #toolbar { gap: 4px; padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .group { gap: 0; }
  .group.middle { gap: 6px; }
  #toolbar button { min-width: 40px; padding: 0 8px; }
  #toolbar .cluster button { min-width: 34px; padding: 0 5px; }
  #toolbar #pageInfo { min-width: 0; padding: 0 6px; }
  .sep { margin: 0 2px; }
}

@media (max-width: 640px) {
  #share span { display: none; }
  #pageInfo { min-width: 0; }
}
