:root {
  --outside: #e9e6df;
  --bar: rgba(255, 255, 255, 0.9);
  --bar-border: rgba(0, 0, 0, 0.08);
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --hover: rgba(0, 0, 0, 0.06);
  --accent: #2f6bff;
  --accent-ink: #fff;
  --danger: #d93025;
  --dot-ring: rgba(0, 0, 0, 0.18);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.08);
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --outside: #1b1c1f;
    --bar: rgba(40, 41, 46, 0.92);
    --bar-border: rgba(255, 255, 255, 0.08);
    --ink: #f2f2f4;
    --muted: #a0a0a8;
    --hover: rgba(255, 255, 255, 0.08);
    --accent: #5b8cff;
    --danger: #ff6b5e;
    --dot-ring: rgba(255, 255, 255, 0.45);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--outside);
  color: var(--ink);
  font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

#board {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
#board.c-none { cursor: none; }
#board.c-grab { cursor: grab; }
#board.c-grabbing { cursor: grabbing; }
#board.c-pick { cursor: pointer; }
#board.c-off { cursor: not-allowed; }

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- floating chrome ---- */

.brand, .pill, .admin-btn, .toolbar, .pop, .zoom, .toast {
  background: var(--bar);
  border: 1px solid var(--bar-border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.brand {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: max(var(--gutter), env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 11px;
  border-radius: 999px;
  font-weight: 650;
  letter-spacing: -0.01em;
  pointer-events: none;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.pill {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 550;
  pointer-events: none;
}
#status { top: calc(max(var(--gutter), env(safe-area-inset-top)) + 44px); color: var(--muted); }

.admin-btn {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  right: max(var(--gutter), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}
.admin-btn svg { width: 18px; height: 18px; color: var(--accent); }

.menu {
  position: fixed;
  z-index: 5;
  min-width: 240px;
  padding: 6px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
}
.menu[hidden] { display: none; }
#adminMenu {
  top: calc(max(var(--gutter), env(safe-area-inset-top)) + 46px);
  right: max(var(--gutter), env(safe-area-inset-right));
}
.menu button {
  text-align: left;
  padding: 11px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button.danger { color: var(--danger); }
.menu button.on::after { content: "  ✓"; color: var(--accent); font-weight: 700; }
.menu hr { border: 0; border-top: 1px solid var(--bar-border); margin: 4px 6px; }
.menu-title { padding: 8px 12px 4px; font-size: 12px; color: var(--muted); }

/* ---- bottom dock ---- */

.dock {
  position: fixed;
  left: 50%;
  bottom: max(var(--gutter), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 2 * var(--gutter));
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border-radius: 18px;
}
.tb {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 13px;
  background: none;
  cursor: pointer;
  flex: none;
}
.tb:hover { background: var(--hover); }
.tb[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tb:disabled { opacity: 0.35; cursor: not-allowed; }
.tb[hidden] { display: none; }
.sep { width: 1px; height: 26px; margin: 0 4px; background: var(--bar-border); flex: none; }

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--dot-ring), 0 0 0 2px var(--bar), 0 0 0 3px var(--bar-border);
}
.size-dot {
  border-radius: 50%;
  background: currentColor;
}

.pop { border-radius: 16px; }
.pop[hidden] { display: none; }

.swatches {
  display: grid;
  grid-template-columns: repeat(7, 36px);
  gap: 6px;
  padding: 10px;
}
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}
.swatch.on { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16), 0 0 0 2px var(--bar), 0 0 0 4px var(--accent); }
.swatch.custom {
  position: relative;
  overflow: hidden;
  background: conic-gradient(#e53935, #fdd835, #43a047, #1e88e5, #5e35b1, #e53935);
}
.swatch.custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.sizes {
  display: flex;
  gap: 4px;
  padding: 6px;
}
.size {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
}
.size:hover { background: var(--hover); }
.size.on { background: var(--hover); box-shadow: inset 0 0 0 2px var(--accent); }
.size span { border-radius: 50%; background: currentColor; }

/* ---- zoom ---- */

.zoom {
  position: fixed;
  right: max(var(--gutter), env(safe-area-inset-right));
  bottom: max(var(--gutter), env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 14px;
}
.zoom button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
}
.zoom button:hover { background: var(--hover); }
.zoom svg { width: 18px; height: 18px; }
#zoomLabel { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(var(--gutter), env(safe-area-inset-bottom)) + 70px);
  transform: translate(-50%, 8px);
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 550;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- login ---- */

dialog {
  width: min(340px, calc(100vw - 2 * var(--gutter)));
  padding: 22px;
  border: 1px solid var(--bar-border);
  border-radius: 18px;
  background: var(--bar);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* stops iOS zooming into the field */
  color: inherit;
  background: var(--hover);
  border: 1px solid var(--bar-border);
  border-radius: 11px;
  -webkit-user-select: text;
  user-select: text;
}
dialog input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error { margin: 10px 0 0; color: var(--danger); }
.login-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.login-actions button {
  padding: 10px 16px;
  border: 0;
  border-radius: 11px;
  background: var(--hover);
  font-weight: 600;
  cursor: pointer;
}
.login-actions .primary { background: var(--accent); color: var(--accent-ink); }

/* ---- small screens ---- */

@media (max-width: 640px) {
  .zoom { display: none; }
  .brand { padding: 7px 12px 7px 10px; font-size: 13px; }
  .tb { width: 42px; height: 42px; }
  .sep { margin: 0 2px; }
  .swatches { grid-template-columns: repeat(7, 34px); gap: 5px; }
  .swatch { width: 34px; height: 34px; }
  .pill { top: calc(max(var(--gutter), env(safe-area-inset-top)) + 46px); }
  #status { top: calc(max(var(--gutter), env(safe-area-inset-top)) + 90px); }
}
@media (max-width: 380px) {
  .tb { width: 38px; height: 38px; }
  .swatches { grid-template-columns: repeat(7, 30px); }
  .swatch { width: 30px; height: 30px; }
}
