/* Canvas core styles (S2). Kinds/tools/ui style their own pieces; use these variables. */

:root {
  --board-bg: #ffffff;          /* the "table": clean white (Brent asked for white over cream) */
  --board-dot: rgb(30 50 60 / 0.07);
  --fog: #ffffff;
  --select: #ff4f8b;
  --chip-bg: rgb(255 255 255 / 0.94);
  --chip-ink: #3a2a20;
  --hint-bg: rgb(40 28 20 / 0.86);
  --hint-ink: #fff;
  --shadow-rgb: 20 30 40;
}

html:has(.board), body:has(.board) {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.board {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;              /* board surface only */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--board-bg);
  background-image: radial-gradient(var(--board-dot) 1.2px, transparent 1.4px);
  background-size: 28px 28px;
  contain: strict;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.board.space-pan, .board.space-pan * { cursor: grab !important; }
.board.dragging { cursor: grabbing; }

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

.board .item {
  position: absolute;
  left: 0; top: 0;
  transform-origin: 50% 50%;
  /* depth → shadow (DESIGN: offset/blur ∝ depth) */
  filter: drop-shadow(0 calc(1px + var(--depth, 0) * 12px) calc(3px + var(--depth, 0) * 22px)
    rgb(var(--shadow-rgb) / calc(0.14 + var(--depth, 0) * 0.16)));
  contain: layout style;
}
/* multiply blend needs to reach what's underneath; animated strokes skip the costly filter */
.board .item:has([data-brush="highlighter"]),
.board .item:has(.stroke-fx, .stroke-sway) { filter: none; }
.board .item-body {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.board .item.mine { cursor: grab; }

/* placeholder for kinds whose module isn't loaded */
.kind-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  box-sizing: border-box;
  border: 2px dashed rgb(120 90 60 / 0.35);
  border-radius: 12px;
  background: rgb(255 255 255 / 0.7);
  font-size: 28px;
  overflow: hidden;
}
.kind-placeholder .ph-text { font-size: 14px; padding: 0 8px; text-align: center; color: #5a4636; }

/* edge fog: four gradients, opacity driven by camera (--fog-l/r/t/b) */
.board > .fog { position: absolute; inset: 0; pointer-events: none; --fog-l: 0; --fog-r: 0; --fog-t: 0; --fog-b: 0; }
.board > .fog > i { position: absolute; pointer-events: none; }
.board > .fog > .fog-l { left: 0; top: 0; bottom: 0; width: min(28vw, 220px); background: linear-gradient(to right, var(--fog), transparent); opacity: var(--fog-l); }
.board > .fog > .fog-r { right: 0; top: 0; bottom: 0; width: min(28vw, 220px); background: linear-gradient(to left, var(--fog), transparent); opacity: var(--fog-r); }
.board > .fog > .fog-t { left: 0; right: 0; top: 0; height: min(24vh, 200px); background: linear-gradient(to bottom, var(--fog), transparent); opacity: var(--fog-t); }
.board > .fog > .fog-b { left: 0; right: 0; bottom: 0; height: min(24vh, 200px); background: linear-gradient(to top, var(--fog), transparent); opacity: var(--fog-b); }

/* screen-space overlay for selection + tool UI */
.board > .overlay {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
.board > .overlay > * { pointer-events: none; }
.board > .overlay [data-handle], .board > .overlay [data-ui] { pointer-events: auto; }

.sel-box {
  position: absolute; left: 0; top: 0;
  transform-origin: 50% 50%;
  box-sizing: border-box;
  border: 2px solid var(--select);
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.8);
}
.sel-box.peek { border-style: dashed; border-color: rgb(120 90 60 / 0.5); }
.sel-h {
  position: absolute;
  width: 44px; height: 44px;          /* touch target */
  margin: 0; padding: 0; border: 0; background: none;
  touch-action: none;
  cursor: pointer;
  font: 600 15px/1 system-ui, sans-serif;
  color: #fff;
}
.sel-h::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 18px; height: 18px; translate: -50% -50%;
  border-radius: 50%; background: #fff; border: 2.5px solid var(--select);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.25);
}
.sel-scale { right: -22px; bottom: -22px; cursor: nwse-resize; }
.sel-rotate { left: 50%; top: -58px; translate: -50% 0; cursor: grab; }
.sel-rotate::after {
  content: ""; position: absolute; left: 50%; top: 31px; width: 2px; height: 27px;
  background: var(--select); translate: -50% 0;
}
.sel-delete { right: -22px; top: -22px; z-index: 1; display: grid; place-items: center; }
.sel-delete::before { width: 28px; height: 28px; background: var(--select); border-color: #fff; z-index: -1; }
.sel-h[hidden] { display: none; }

.owner-chip {
  position: absolute; left: 0; top: 0;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px 5px 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-ink);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.12);
}
.owner-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* default ui hooks (S4 replaces) */
.canvas-hint {
  position: absolute; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  translate: -50% 12px; opacity: 0; transition: opacity .25s, translate .25s;
  max-width: min(90vw, 420px);
  padding: 10px 16px; border-radius: 999px;
  background: var(--hint-bg); color: var(--hint-ink);
  font-size: 15px; text-align: center; pointer-events: none; z-index: 20;
}
.canvas-hint.show { opacity: 1; translate: -50% 0; }
.canvas-status {
  position: absolute; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  font-size: 13px; color: rgb(80 60 45 / 0.75); pointer-events: none; z-index: 20;
}
.canvas-status:empty { display: none; }
.canvas-identity {
  position: absolute; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgb(251 246 238 / 0.55);
  backdrop-filter: blur(3px);
}
.canvas-identity-card {
  display: grid; gap: 14px; width: min(88vw, 360px);
  padding: 24px; border-radius: 20px; background: #fff;
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.15);
}
.canvas-identity-card h1 { margin: 0; font-size: 24px; }
.canvas-identity-card input { font-size: 20px; padding: 12px 14px; border-radius: 12px; border: 2px solid #e6d9c8; }
.canvas-identity-card button { font-size: 20px; padding: 12px; border: 0; border-radius: 12px; background: var(--select); color: #fff; font-weight: 700; min-height: 48px; }
.canvas-identity-note { margin: 0; color: #6b5543; }

@media (prefers-reduced-motion: reduce) {
  .canvas-hint { transition: none; }
}
