/* Starplace tokens: dark mode only changes these values. Regions use soft pastels, one per region. */
:root {
  --g-starplace: #e0864a;
  --sp-line: #1f1f1f;
  --sp-grid: rgb(0 0 0 / 0.14);
  --sp-star: #262626;
  --sp-dot: rgb(0 0 0 / 0.55);
  --sp-r0: #f7c9c3;
  --sp-r1: #fbe2a8;
  --sp-r2: #c9e8c0;
  --sp-r3: #bfdcf5;
  --sp-r4: #dccdf3;
  --sp-r5: #f8cde3;
  --sp-r6: #c3ece6;
  --sp-r7: #e9dcc4;
  --sp-r8: #dbe9ae;
  --sp-r9: #f3d1b0;
  --sp-r10: #cfd6e6;
  --sp-r11: #e6c9d6;
}
:root[data-theme='dark'] {
  --g-starplace: #f0a06a;
  --sp-line: #ececec;
  --sp-grid: rgb(255 255 255 / 0.14);
  --sp-star: #ffe08a;
  --sp-dot: rgb(255 255 255 / 0.6);
  --sp-r0: #6b3c37;
  --sp-r1: #6a5a2c;
  --sp-r2: #3d5e38;
  --sp-r3: #34506b;
  --sp-r4: #4f4270;
  --sp-r5: #6b3a55;
  --sp-r6: #2f5f58;
  --sp-r7: #5c4f3a;
  --sp-r8: #4e5f2a;
  --sp-r9: #6b4b2e;
  --sp-r10: #434b5e;
  --sp-r11: #5e4150;
}

.starplace-shell {
  --game-accent: var(--g-starplace);
}
.starplace-shell .shell-stage {
  gap: var(--space-3);
  padding: 0 var(--space-4);
}
.starplace-shell .shell-board-area {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.sp-board-wrap {
  width: min(540px, calc(100vw - 32px), calc(100dvh - 300px));
  min-width: 240px;
  margin: 0 auto;
}
.sp-board {
  position: relative;
  display: grid;
  overflow: hidden;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--cols), minmax(0, 1fr));
  aspect-ratio: 1;
  border: 3px solid var(--sp-line);
  border-radius: 8px;
  isolation: isolate;
  /* Drags paint ×: they must not scroll or zoom the page. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.sp-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--region);
  color: var(--sp-star);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
/* The keyboard focus ring is dashed in the game colour so it never reads as a region border. */
.sp-cell:focus-visible {
  z-index: 3;
  outline: 3px dashed var(--g-starplace);
  outline-offset: -5px;
}
.sp-star {
  width: 66%;
  height: 66%;
  fill: currentColor;
}
.sp-dot {
  color: var(--sp-dot);
  font: 700 clamp(13px, 4.6vw, 22px) / 1 var(--font-app);
}
/* Rule problems: touching stars and over-full or blocked lines turn red. */
.sp-cell.bad-unit::before {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    135deg,
    color-mix(in srgb, var(--danger) 22%, transparent) 0 4px,
    transparent 4px 9px
  );
  content: '';
}
.sp-cell.bad {
  color: var(--danger);
}
.sp-cell.hint-context::after,
.sp-cell.hint-focus::after,
.sp-cell.hint-target::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  content: '';
}
.sp-cell.hint-context::after {
  background: color-mix(in srgb, var(--hint-context) 20%, transparent);
}
.sp-cell.hint-focus::after {
  box-shadow: inset 0 0 0 2px var(--hint-context);
}
.sp-cell.hint-target::after {
  box-shadow: inset 0 0 0 3px var(--hint-target);
  background: color-mix(in srgb, var(--hint-target) 22%, transparent);
}
.sp-cell.hint-target.hint-empty::after,
.sp-cell.hint-target.hint-clear::after {
  box-shadow: inset 0 0 0 3px var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
}
.sp-lines {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  pointer-events: none;
}
.sp-grid-lines {
  stroke: var(--sp-grid);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.sp-region-lines {
  stroke: var(--sp-line);
  stroke-width: 3;
  stroke-linecap: square;
  vector-effect: non-scaling-stroke;
}
.sp-board.solved .sp-cell.star .sp-star {
  animation: sp-pop 700ms ease-out both;
  animation-delay: calc(var(--i) * 30ms);
}
@keyframes sp-pop {
  40% {
    transform: scale(1.3);
  }
}
@media (prefers-reduced-motion: reduce) {
  .sp-board.solved .sp-cell.star .sp-star {
    animation: none;
  }
}

.sp-under {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2) var(--space-4);
}
.sp-modes {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
}
.sp-mode {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: 600 14px / 1 var(--font-app);
  cursor: pointer;
}
.sp-mode.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}
.sp-status {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}
.sp-status b {
  color: var(--text);
}

/* Picture rules: the 4 × 4 demo board fills the stage; the ✓ or ✗ sits on the wrapper because the board clips. */
.sp-demo {
  position: relative;
  width: 100%;
}
.sp-demo .sp-board {
  touch-action: auto;
}
.sp-demo .sp-cell {
  cursor: default;
}
.sp-demo .sp-dot {
  font-size: 24px;
}
.sp-demo .sp-cell.demo-dim::after {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  content: '';
}
