:root {
  --bg: #f1efff;
  --bg-2: #e4e0ff;
  --paper: #fffefb;
  --ink: #1e1b4b;
  --outline: #1e1b4b;
  --muted: #6c689a;
  --accent: #4a3aff;
  --accent-ink: #ffffff;
  --pink: #ff8fc0;
  --btn: #ffffff;
  --pop: 3px 3px 0 var(--outline);
  --pop-lg: 5px 5px 0 var(--outline);
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --current: #1e1b4b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15132e;
    --bg-2: #221f45;
    --ink: #eeebff;
    --outline: #07061a;
    --muted: #a19dcc;
    --accent: #6f62ff;
    --btn: #2a2752;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { height: 100%; }
body {
  background-color: var(--bg);
  /* a few soft ink splotches in the background */
  background-image:
    radial-gradient(circle at 8% 14%, color-mix(in srgb, var(--accent) 10%, transparent) 0 70px, transparent 71px),
    radial-gradient(circle at 94% 8%, color-mix(in srgb, var(--pink) 16%, transparent) 0 46px, transparent 47px),
    radial-gradient(circle at 90% 88%, color-mix(in srgb, var(--accent) 8%, transparent) 0 90px, transparent 91px),
    radial-gradient(circle at 4% 92%, color-mix(in srgb, var(--pink) 12%, transparent) 0 36px, transparent 37px);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
img { display: block; }

/* ---------- mascot ---------- */
@keyframes squish {
  0%, 82%, 100% { transform: scale(1, 1); }
  88% { transform: scale(1.08, .9); }
  94% { transform: scale(.95, 1.06); }
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-6px) rotate(3deg); }
}
.mascot { transform-origin: 50% 90%; animation: squish 4.5s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .mascot, .hint img, .lost-mascot { animation: none !important; }
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  padding: 10px 16px 2px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -.5px;
  line-height: 1;
}

/* ---------- draw page ---------- */
.draw-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 10px 18px 12px 16px;
}
.paper {
  position: relative;
  border-radius: 20px;
  border: 2.5px solid var(--outline);
  box-shadow: var(--pop-lg);
  background: var(--paper);
  overflow: hidden;
}
.paper canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#ink { touch-action: none; cursor: crosshair; }
.hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #8f8ac0;
  font-size: clamp(20px, 4.5vw, 28px);
  font-weight: 500;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.hint img { opacity: .9; animation: bob 3s ease-in-out infinite; }
.hint.gone { opacity: 0; transform: scale(.9); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 14px;
  padding: 6px 12px calc(12px + env(safe-area-inset-bottom));
}
.group { display: flex; align-items: center; gap: 4px; }
.group.dim { opacity: .4; }

.swatch, .size, .tool {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 0;
  display: grid; place-items: center;
  background: transparent;
  padding: 0;
  transition: transform .12s, background .12s;
}
/* colour swatches are little ink drops */
.swatch::after {
  content: '';
  width: 22px; height: 22px;
  background: var(--c);
  border-radius: 0 50% 50% 50%;
  transform: rotate(45deg) translate(2px, 2px);
  box-shadow: inset -3px -3px 0 rgba(0,0,0,.14), inset 2px 2px 0 rgba(255,255,255,.3);
  transition: transform .15s;
}
.swatch.active { background: var(--btn); box-shadow: 0 0 0 2.5px var(--outline), var(--pop); }
.swatch.active::after { transform: rotate(45deg) translate(2px, 2px) scale(1.18); }

.size i {
  display: block;
  width: var(--d); height: var(--d);
  border-radius: 50%;
  background: var(--current);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--ink) 25%, transparent);
}
@media (prefers-color-scheme: dark) {
  /* keep the dark "ink" colour visible on a dark background */
  .size i { box-shadow: 0 0 0 2px color-mix(in srgb, var(--ink) 55%, transparent); }
  .swatch::after { filter: drop-shadow(0 0 1.5px rgba(238,235,255,.7)); }
}
.size.active, .tool.active { background: var(--btn); box-shadow: 0 0 0 2.5px var(--outline), var(--pop); }
.tool svg { width: 22px; height: 22px; fill: currentColor; }
.tool:disabled { opacity: .3; }
.tool.active { color: var(--accent); }
/* smoothing level shown as one or two little dots under the icon */
.smooth { position: relative; }
.smooth::after { content: ''; position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); height: 4px; border-radius: 2px; background: currentColor; }
.smooth[data-level="1"]::after { width: 4px; }
.smooth[data-level="2"]::after { width: 4px; transform: translateX(calc(-50% - 3.5px)); box-shadow: 7px 0 0 currentColor; }
.smooth[data-level="3"]::after { width: 4px; box-shadow: -6px 0 0 currentColor, 6px 0 0 currentColor; }

.swatch:active, .size:active, .tool:not(:disabled):active { transform: scale(.9); }

.save {
  height: 48px;
  padding: 0 26px;
  margin-left: 4px;
  border: 2.5px solid var(--outline);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 18px;
  box-shadow: var(--pop);
  transition: transform .1s, box-shadow .1s, opacity .2s;
}
.save:not(:disabled):active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--outline); }
.save:disabled { opacity: .4; }
.save.busy { opacity: .75; }

@media (max-width: 560px) {
  .toolbar { gap: 6px 2px; }
  .colors, .sizes { gap: 0; }
  .swatch, .size, .tool { width: 40px; height: 40px; border-radius: 12px; }
  .actions { width: 100%; justify-content: space-between; padding: 0 4px; }
  .save { flex: 1; margin-left: 10px; }
}

@media (hover: hover) {
  .tool:not(:disabled):hover, .size:hover, .swatch:hover { background: var(--bg-2); }
  .size.active:hover, .swatch.active:hover, .tool.active:hover { background: var(--btn); }
  .save:not(:disabled):hover, .big:hover { filter: brightness(1.06); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(124px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- share page ---------- */
.view-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}
.view-page .topbar { width: 100%; max-width: 760px; padding-left: 0; padding-right: 0; }
.view {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin-top: 10px;
}
.framed {
  max-width: calc(100% - 5px);
  max-height: 66dvh;
  width: auto;
  height: auto;
  border-radius: 20px;
  border: 2.5px solid var(--outline);
  box-shadow: var(--pop-lg);
  background: var(--paper);
}
.share-actions {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: 12px;
  padding-right: 3px;
}
.big {
  flex: 1;
  height: 56px;
  padding: 0 24px;
  border-radius: 999px;
  border: 2.5px solid var(--outline);
  font-size: 18px;
  font-weight: 600;
  box-shadow: var(--pop);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: transform .1s, box-shadow .1s;
}
.big:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--outline); }
.big.primary { background: var(--accent); color: var(--accent-ink); }
.big.secondary { background: var(--btn); color: var(--ink); }
.big[hidden] { display: none; }

.link-text {
  width: 100%;
  max-width: 520px;
  margin-top: -4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 14px var(--font);
  text-align: center;
  text-overflow: ellipsis;
  outline: none;
}

.quiet-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 16px; font-weight: 500; }
.quiet-row a { color: var(--muted); text-decoration: none; padding: 8px 4px; }
.quiet-row a:hover { color: var(--ink); }

/* ---------- paper picker ---------- */
.paper-tray {
  position: fixed;
  left: 50%;
  bottom: calc(118px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--btn);
  border: 2.5px solid var(--outline);
  border-radius: 20px;
  box-shadow: var(--pop-lg);
}
.paper-tray[hidden] { display: none; }
.tray-row { display: flex; gap: 8px; justify-content: center; }
.pattern-opt, .paper-opt {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 2px solid color-mix(in srgb, var(--ink) 20%, transparent);
  padding: 0;
  display: grid; place-items: center;
  transition: transform .12s;
}
.pattern-opt { background: #fffefb; }
.tool-opt { width: 52px; height: 52px; border-radius: 14px; border: 2px solid color-mix(in srgb, var(--ink) 20%, transparent); background: var(--bg); color: var(--ink); display: grid; place-items: center; padding: 0; transition: transform .12s; }
.tool-opt svg { width: 24px; height: 24px; fill: currentColor; }
.tool-opt[aria-pressed="true"] { border-color: var(--outline); box-shadow: 0 0 0 2px var(--accent); color: var(--accent); background: var(--btn); }
.tool-opt:active { transform: scale(.92); }
.group.dim-sizes .sizes, .sizes.dim { opacity: .4; }
.paper-opt { background: var(--pc); border-radius: 50%; }
.pattern-opt[aria-pressed="true"], .paper-opt[aria-pressed="true"] { border-color: var(--outline); box-shadow: 0 0 0 2px var(--accent); }
.pattern-opt:active, .paper-opt:active { transform: scale(.92); }
.pattern-opt i { width: 26px; height: 26px; border-radius: 4px; }
.pat-dots { background: radial-gradient(circle, rgba(79,70,229,.55) 1.4px, transparent 1.6px) 0 0 / 8.66px 8.66px; }
.pat-lines { background: repeating-linear-gradient(to bottom, transparent 0 6px, rgba(79,70,229,.45) 6px 7.5px); }
@media (max-width: 560px) {
  .paper-tray { bottom: calc(104px + env(safe-area-inset-bottom)); }
}

/* ---------- small links ---------- */
.header-link { margin-left: auto; color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none; padding: 8px 2px; }
.header-link:hover { color: var(--ink); }
.linklike { background: none; border: 0; padding: 8px 4px; color: var(--muted); font: inherit; }
.linklike:hover:not(:disabled) { color: var(--ink); }
.linklike:disabled { cursor: default; }
.expires { margin: -14px 0 0; color: var(--muted); font-size: 13px; }
.legal { margin-top: auto; padding-top: 20px; display: flex; gap: 8px; color: var(--muted); font-size: 13px; }
.legal a { color: var(--muted); text-decoration: none; }
.legal a:hover { color: var(--ink); }

/* ---------- text pages (terms, privacy) ---------- */
.doc { width: 100%; max-width: 640px; margin: 12px 0 32px; background: var(--paper); color: #1e1b4b; border: 2.5px solid var(--outline); border-radius: 20px; box-shadow: var(--pop-lg); padding: 24px 22px; line-height: 1.55; font-size: 16px; }
.doc h1 { font-size: 28px; margin: 0 0 4px; }
.doc h1.section { margin-top: 36px; padding-top: 28px; border-top: 2px dashed #d9d5f5; scroll-margin-top: 16px; }
.doc h2 { font-size: 18px; margin: 22px 0 4px; }
.doc p, .doc ul { margin: 0 0 10px; }
.doc .updated { color: #6c689a; font-size: 14px; margin-bottom: 16px; }
.doc a { color: #4a3aff; }

/* ---------- admin login ---------- */
.login { margin-top: 22vh; width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.login input {
  width: 100%;
  height: 52px;
  padding: 0 20px;
  border: 2.5px solid var(--outline);
  border-radius: 999px;
  background: var(--btn);
  color: var(--ink);
  font: 500 17px var(--font);
  box-shadow: var(--pop);
  outline: none;
}
.login input:focus { box-shadow: var(--pop), 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent); }
.login-error { margin: 0; color: #e0306e; font-weight: 500; }
form.header-link { padding: 0; }

/* ---------- 404 ---------- */
.lost {
  text-align: center;
  margin-top: 16vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lost-mascot { animation: bob 3.5s ease-in-out infinite; margin-bottom: 12px; }
.lost h1 { font-weight: 700; font-size: 32px; margin: 0 0 6px; }
.lost p { color: var(--muted); margin: 0 0 26px; font-size: 17px; }
.lost .big { flex: none; }

/* ---------- Inky Space ---------- */
.space-page {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
.join {
  height: 100dvh;
  overflow-y: auto;
  max-width: 380px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 20px 28px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.join[hidden], .room[hidden] { display: none; }
.join .logo { align-self: center; margin-top: 6vh; }
.join-sub { text-align: center; color: var(--muted); margin: 0 0 10px; font-size: 16px; }
.join-label { font-weight: 600; font-size: 15px; margin-top: 6px; }
.join-name {
  height: 52px;
  padding: 0 20px;
  border: 2.5px solid var(--outline);
  border-radius: 999px;
  background: var(--btn);
  color: var(--ink);
  font: 500 17px var(--font);
  box-shadow: var(--pop);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.join-name:focus { box-shadow: var(--pop), 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent); }
.avatar-pad {
  align-self: center;
  width: 180px; height: 180px;
  border: 2.5px solid var(--outline);
  border-radius: 24px;
  box-shadow: var(--pop-lg);
  background: #fffefb;
  overflow: hidden;
}
.avatar-pad canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.avatar-tools { display: flex; justify-content: center; gap: 2px; margin-top: 4px; }
.join-warn {
  margin: 14px 0 0;
  padding: 12px 14px 12px 32px;
  background: color-mix(in srgb, var(--accent) 8%, var(--btn));
  border: 2px solid color-mix(in srgb, var(--outline) 30%, transparent);
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
}
.join-warn li + li { margin-top: 4px; }
.join-terms { align-self: center; color: var(--muted); font-size: 13px; }
.join-go { flex: none; margin-top: 8px; }
.join-note { text-align: center; color: #e0306e; margin: 0; min-height: 20px; font-weight: 500; }

.room { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.room-bar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; }
.room-bar .logo { font-size: 26px; }
.room-meta { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.who { display: flex; align-items: center; }
.who .avatar { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--outline); margin-left: -6px; background: #fffefb; }
.who .avatar:first-child { margin-left: 0; }
.who span { margin-left: 8px; font-weight: 600; font-size: 14px; }
.wipe { color: var(--muted); font-size: 12px; }

.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  background: var(--bg-2);
  border-top: 2px solid color-mix(in srgb, var(--outline) 25%, transparent);
  border-bottom: 2px solid color-mix(in srgb, var(--outline) 25%, transparent);
}
.world {
  position: absolute;
  left: 0; top: 0;
  transform-origin: 0 0;
  background-color: #fffefb;
  background-image: radial-gradient(circle, rgba(79, 70, 229, .22) 2.2px, transparent 2.7px);
  background-size: 40px 40px;
  background-position: -20px -20px;
  box-shadow: 0 0 0 3px var(--outline), 10px 10px 0 var(--outline);
}
.world canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cursor {
  position: absolute;
  left: 0; top: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: transform 80ms linear;
  will-change: transform;
}
.cursor::before {
  content: '';
  position: absolute;
  left: -5px; top: -5px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px #fff;
}
.cursor .avatar { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--outline); margin: 12px 0 0 10px; background: #fffefb; }
.cursor span {
  margin-top: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.zoom { position: absolute; right: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.zoom .tool { background: var(--btn); box-shadow: 0 0 0 2px var(--outline), var(--pop); font-size: 22px; font-weight: 600; line-height: 1; }
.space-page .toolbar { padding-top: 8px; }
