.playground {
  position: fixed;
  z-index: 30;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.65rem;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}

.playground[hidden] { display: none; }
.playground-actions { display: flex; align-items: center; gap: 0.5rem; }
.playground-close { display: none; }

.playground-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 48px;
  padding: 0.65rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-0);
  box-shadow: var(--shadow);
  color: var(--text);
  font: 0.87rem varela-round, sans-serif;
  cursor: pointer;
  pointer-events: auto;
  transition: border-color 180ms ease, background 180ms ease;
}

.playground-switch:hover { background: var(--bg-1); }
.playground-switch:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 4px; }
.playground-switch[aria-pressed="true"] { border-color: var(--accent); }
.playground-switch[aria-pressed="true"] svg { color: var(--accent-2); }
.playground-count { min-width: 1.8em; color: var(--text-muted); font-size: 0.72rem; }
.playground-switch[aria-pressed="true"] .playground-count { color: var(--text); }

.playground-hint {
  margin: 0;
  max-width: min(310px, calc(100vw - 2rem));
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  color: var(--text);
  background: var(--bg-0);
  font: 0.8rem/1.5 varela-round, sans-serif;
  box-shadow: var(--shadow);
}

.playground-hint:empty { display: none; }
.playground-stage { position: fixed; inset: 0; z-index: 15; pointer-events: none; overflow: hidden; }
.playground-canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
.playground-stage[data-effect="water"] { mix-blend-mode: screen; }

.playground-chip {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--accent);
  border-radius: 1rem;
  background: var(--bg-0);
  box-shadow: 0 6px 24px var(--surface-strong);
  color: var(--text);
  font: 0.8rem varela-round, sans-serif;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.playground-chip.is-grabbed { cursor: grabbing; border-color: var(--accent-2); }

.playground-pet-target {
  position: absolute;
  top: 0;
  left: 0;
  width: 88px;
  height: 104px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
}

.playground-pet-target:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 3px;
}

@media (max-width: 920px) {
  .playground {
    right: max(0.75rem, env(safe-area-inset-right));
    left: max(0.75rem, env(safe-area-inset-left));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    max-width: none;
    gap: 0.4rem;
  }

  .playground-hint {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    padding: 0.45rem 0.7rem;
    border-radius: 0.8rem;
    font-size: 0.74rem;
    line-height: 1.35;
  }

  .playground-is-active .playground-actions { width: 100%; }
  .playground-is-active .playground-switch { flex: 1; min-width: 0; justify-content: center; }
  .playground-is-active .playground-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 48px;
    height: 48px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text);
    background: var(--bg-0);
    pointer-events: auto;
    cursor: pointer;
  }

  .playground-close:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }
  .playground-is-active .maintenance-main {
    min-height: 100svh;
    padding-top: 0.75rem;
    padding-bottom: 8rem;
    align-items: start;
  }

  .playground-is-active .maintenance-image-wrap {
    grid-row: 1;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    height: clamp(220px, 56svh, 520px);
    min-height: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .playground-is-active .maintenance-image { min-height: 0; }
  .playground-is-active .maintenance-copy { grid-row: 2; }
}

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