:root {
  --ps-cols: 6;
  --ps-rows: 8;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #0f172a 0%, #05070d 50%, #000 100%);
  color: #e5e7eb;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

#puzzlesync {
    margin-top:36px;
}

.ps-page {
  height: 100vh;
  padding: 14px 14px 18px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ps-header {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
}

.ps-title h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.ps-title p {
  margin: 4px 0 0;
  opacity: 0.8;
  font-size: 13px;
}

.ps-main {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}

@media (max-width: 960px) {
  .ps-main {
    place-items: center;
  }
}

.ps-board {
  --cols: var(--ps-cols);
  --rows: var(--ps-rows);
  position: relative;
  width: min(96vw, calc((100vh - 92px) * var(--cols) / var(--rows)));
  height: min(calc(100vh - 92px), calc(96vw * var(--rows) / var(--cols)));
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
}

.ps-tile {
  position: absolute;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-sizing: border-box;
  background-image: var(--ps-image, url("/puzzlesync/images/puzzle01.jpg"));
  background-size: calc(var(--cols) * 100%) calc(var(--rows) * 100%);
  background-position: var(--bgx) var(--bgy);
  display: grid;
  place-items: center;
  user-select: none;
}

.ps-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  box-sizing: border-box;
  background-image: var(--ps-image, url("/puzzlesync/images/puzzle01.jpg"));
  background-size: cover;
  background-position: center;
  z-index: 3;
}

.ps-overlay.is-visible {
  display: grid;
}

.ps-overlay-card {
    width: min(300px, 80%);
    padding: 4px 16px 14px;
    border-radius: 24px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(1px);
    text-align: center;
    margin-top: 550px;
}

.ps-overlay-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.ps-overlay-card p {
  margin: 0;
  opacity: 0.9;
}

.ps-overlay-card button {
  margin-top: 12px;
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 800;
  color: #04151c;
  background: rgba(34, 211, 182, 0.95);
}

.ps-overlay-card button:active {
  transform: translateY(1px);
}

.ps-tile.ps-occupied {
  /* Keep the image but darken it so players are still visible on the picture. */
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.62)),
    var(--ps-image, url("/puzzlesync/images/puzzle01.jpg"));
  border-color: rgba(255, 255, 255, 0.14);
}

.ps-tile.ps-mine {
  outline: 2px solid rgba(34, 211, 182, 0.85);
  outline-offset: -2px;
}

.ps-tile button {
  all: unset;
  cursor: pointer;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.ps-label {
  font-weight: 800;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  max-width: 92%;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ps-tile:not(.ps-occupied) .ps-label {
  display: none;
}

.ps-num {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.92);
}
