:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --board-bg: #6c4cff;
  --ink: #2b2d42;
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--board-bg);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  font-family: var(--round);
  color: var(--ink);
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  overflow: hidden;
  cursor: pointer;
}

#stage canvas, #layers .layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#layers { position: absolute; inset: 0; }
#fx { pointer-events: none; }

/* ---- hidden long-press corner -------------------------------------------- */
#corner {
  position: fixed;
  top: 0;
  left: 0;
  width: calc(76px + var(--sal));
  height: calc(76px + var(--sat));
  z-index: 50;
  touch-action: none;
  padding: calc(14px + var(--sat)) 0 0 calc(14px + var(--sal));
}
#corner svg {
  width: 48px;
  height: 48px;
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
  transition: opacity 0.3s, transform 0.3s;
}
#corner circle { fill: none; stroke-width: 10; stroke-linecap: round; }
#corner .track { stroke: rgba(255, 255, 255, 0.35); }
#corner .bar { stroke: #fff; stroke-dasharray: 252; stroke-dashoffset: 252; }
#corner.holding svg { opacity: 1; transform: rotate(-90deg) scale(1); transition-delay: 0.4s; }
#corner.holding .bar { animation: hold 1.6s linear 0.4s forwards; }
@keyframes hold { to { stroke-dashoffset: 0; } }

/* ---- board change curtain -------------------------------------------------- */
#curtain {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, var(--c1, #ff5fa2), var(--c0, #6c4cff));
  clip-path: circle(0% at 50% 50%);
}
#curtain.closing { animation: iris-in 0.42s cubic-bezier(.6, 0, .4, 1) forwards; pointer-events: auto; }
#curtain.opening { clip-path: circle(150% at 50% 50%); animation: iris-out 0.5s cubic-bezier(.6, 0, .4, 1) forwards; }
@keyframes iris-in { from { clip-path: circle(0% at 50% 50%); } to { clip-path: circle(150% at 50% 50%); } }
@keyframes iris-out { from { clip-path: circle(150% at 50% 50%); } to { clip-path: circle(0% at 50% 50%); } }

/* ---- splash ---------------------------------------------------------------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: radial-gradient(circle at 30% 20%, #8f7bff, #6c4cff 45%, #e84fa0);
  transition: opacity 0.6s, transform 0.6s;
}
#splash img { width: min(42vmin, 260px); animation: bob 1.4s ease-in-out infinite; filter: drop-shadow(0 12px 20px rgba(0,0,0,.25)); }
#splash .splash-word { font: 900 min(12vmin, 72px)/1 var(--round); color: #fff; letter-spacing: 0.02em; text-shadow: 0 4px 0 rgba(0,0,0,.15); }
#splash .splash-error { display: none; color: #fff; font-size: 18px; }
#splash.error .splash-error { display: block; }
#splash.gone { opacity: 0; transform: scale(1.08); pointer-events: none; }
@keyframes bob { 50% { transform: translateY(-4%) rotate(4deg); } }

/* ---- parent menu ------------------------------------------------------------ */
.pm {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 16, 48, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.25s;
  display: grid;
  place-items: center;
  padding: calc(12px + var(--sat)) calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal));
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}
.pm[hidden] { display: none; }
.pm.open { opacity: 1; }
.pm-sheet {
  width: min(1100px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: #fffaf3;
  border-radius: 28px;
  padding: clamp(16px, 3vw, 32px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  transform: translateY(20px) scale(0.98);
  transition: transform 0.25s;
}
.pm.open .pm-sheet { transform: none; }
.pm-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.pm-head > div { flex: 1 1 200px; }
.pm-logo { width: 64px; height: 64px; }
.pm h1 { margin: 0; font-size: clamp(22px, 3.2vw, 32px); }
.pm h2 { margin: 18px 0 10px; font-size: 18px; text-transform: uppercase; letter-spacing: 0.08em; color: #6c4cff; }
.pm p { margin: 4px 0; }
.pm-boards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pm-board {
  appearance: none;
  border: 0;
  border-radius: 20px;
  padding: 14px 12px 12px;
  min-height: 128px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  color: #fff;
  font: inherit;
  cursor: pointer;
  background: linear-gradient(rgba(20, 10, 60, 0.06), rgba(20, 10, 60, 0.28)), linear-gradient(140deg, var(--c0), var(--c1));
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.15s;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(0, 0, 0, 0.2);
}
.pm-board:active { transform: translateY(3px) scale(0.98); }
.pm-board.current { outline: 5px solid #2b2d42; outline-offset: 3px; }
.pm-emoji { font-size: 44px; line-height: 1.1; }
.pm-name { font-weight: 800; font-size: 17px; text-align: center; }
.pm-tech { font-size: 11px; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.06em; }
.pm-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 8px; }
.pm-card { background: #fff; border-radius: 20px; padding: 6px 18px 16px; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.pm-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0ebe3; }
.pm-row:last-child { border-bottom: 0; }
.pm-row b { display: block; }
.pm-row small, .pm-small { display: block; color: #6b6f80; font-size: 13px; }
.pm-row input[type="checkbox"] { width: 28px; height: 28px; accent-color: #6c4cff; flex: none; }
.pm select { font: inherit; padding: 8px 10px; border-radius: 12px; border: 2px solid #e5ddff; background: #fff; }
.pm-btn {
  appearance: none;
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  padding: 10px 16px;
  background: #efeaff;
  color: #3d2a99;
  cursor: pointer;
  white-space: nowrap;
}
.pm-btn.primary { background: #6c4cff; color: #fff; box-shadow: 0 4px 0 #4a2fd1; }
.pm-btn:disabled { opacity: 0.5; }
.pm-btn[hidden] { display: none; }
.pm-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.pm-update { font-weight: 700; }
