:root {
  color-scheme: light;
  --bg: #f7f9fd;
  --ink: #202b3d;
  --muted: #697489;
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(95, 111, 135, 0.14);
  --accent: #7b61ff;
  --accent-2: #7b61ff;
  --slot: #243047;
  --tile-a: #ffffff;
  --tile-b: #f7f8fb;
  --tile-ink: #202b3d;
  --gap: clamp(6px, 1vw, 10px);
  --size: 4;
  --solve-progress: 0;
  --solve-bg: 0;
  --solve-glow: 0.08;
  --solve-border: 0.12;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  user-select: none;
  background:
    radial-gradient(circle at 12% 8%, rgba(123, 97, 255, 0.08), transparent 28rem),
    radial-gradient(circle at 86% 74%, rgba(123, 97, 255, 0.07), transparent 24rem),
    linear-gradient(135deg, #f5f8fd, #ffffff 56%, #f4f7fb),
    var(--bg);
}

.app-shell,
.settings-page {
  position: relative;
  z-index: 1;
}

body.bg-black {
  --bg: #05070d;
  --ink: #f5f7fb;
  --muted: #aeb8c8;
  --panel: rgba(13, 17, 29, 0.84);
  --line: rgba(255, 255, 255, 0.14);
  --tile-a: #151a27;
  --tile-b: #0d1220;
  --tile-ink: #f7f8fb;
  --slot: #050713;
  background:
    radial-gradient(circle at 12% 8%, rgba(123, 97, 255, 0.16), transparent 28rem),
    radial-gradient(circle at 86% 74%, rgba(74, 128, 255, 0.14), transparent 24rem),
    linear-gradient(135deg, #090d18, #03050a 56%, #0b1020),
    var(--bg);
}

body.bg-black .game-panel,
body.bg-black .side-panel,
body.bg-black .settings-panel {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

body.bg-black .stat,
body.bg-black .status-strip,
body.bg-black .preview,
body.bg-black .segmented,
body.bg-black .settings-row,
body.bg-black .icon-button {
  background: rgba(255, 255, 255, 0.06);
}

body.bg-black .tile,
body.bg-black .mini-tile {
  border-color: rgba(255, 255, 255, 0.1);
}

button {
  font: inherit;
}

a {
  text-decoration: none;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.button-icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.picture-icon {
  position: relative;
  width: 20px;
  height: 20px;
  display: inline-block;
  flex: 0 0 auto;
}

.picture-icon::before,
.picture-icon::after {
  content: "";
  position: absolute;
  display: block;
}

.grid-picture {
  border-radius: 5px;
  background: linear-gradient(135deg, #c9f7df, #35c986);
  box-shadow:
    inset 0 0 0 1px rgba(20, 119, 73, 0.16),
    0 4px 8px rgba(53, 201, 134, 0.18);
}

.grid-picture::before {
  inset: 4px;
  border-radius: 2px;
  background:
    linear-gradient(90deg, transparent calc(33% - 1px), rgba(99, 65, 18, 0.35) 33% calc(33% + 1px), transparent calc(33% + 1px) calc(66% - 1px), rgba(99, 65, 18, 0.35) 66% calc(66% + 1px), transparent calc(66% + 1px)),
    linear-gradient(0deg, transparent calc(33% - 1px), rgba(99, 65, 18, 0.35) 33% calc(33% + 1px), transparent calc(33% + 1px) calc(66% - 1px), rgba(99, 65, 18, 0.35) 66% calc(66% + 1px), transparent calc(66% + 1px));
}

.grid-4 {
  background: linear-gradient(135deg, #dff7ff, #78c9ff);
}

.grid-5 {
  background: linear-gradient(135deg, #efe7ff, #9c7cff);
}

.table-picture {
  border-radius: 5px;
  background: linear-gradient(135deg, #b98bff, #6f55ef);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.42),
    0 5px 12px rgba(123, 97, 255, 0.18);
}

.table-picture::before {
  inset: 4px;
  border-radius: 3px;
  background: linear-gradient(135deg, #ffffff, #edf0ff);
}

.table-picture.wood {
  background: linear-gradient(135deg, #d8994c, #8f5526);
}

.table-picture.dark {
  background: linear-gradient(135deg, #26344e, #080d19);
}

.image-picture {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: url("assets/puzzle-image-button.png") center / 136% no-repeat;
  filter: drop-shadow(0 5px 8px rgba(77, 168, 255, 0.22));
}

.sound-picture {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: url("assets/sound-on.png") center / 136% no-repeat;
  filter: drop-shadow(0 5px 8px rgba(77, 168, 255, 0.22));
}

.sound-picture.muted {
  background-image: url("assets/sound-off.png");
  filter: drop-shadow(0 5px 8px rgba(255, 72, 72, 0.2));
}

.pause-picture {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: url("assets/play-pause.png") center / 136% no-repeat;
  filter: drop-shadow(0 5px 8px rgba(255, 174, 69, 0.22));
}

.hint-button {
  background: linear-gradient(135deg, #ffffff, #dceeff);
  border-color: rgba(77, 128, 255, 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 10px 24px rgba(77, 128, 255, 0.18);
}

.hint-picture {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: url("assets/hint-lightbulb.png") center / 136% no-repeat;
  filter: drop-shadow(0 5px 8px rgba(77, 168, 255, 0.22));
}

.time-penalty {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  z-index: 10;
  width: max-content;
  padding: 7px 10px;
  border-radius: 999px;
  color: white;
  background: linear-gradient(135deg, #ff8a65, #f05252);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 12px 24px rgba(240, 82, 82, 0.28);
  font-size: 0.78rem;
  font-weight: 900;
  pointer-events: none;
  transform: translate(-50%, 16px) scale(0.7) rotate(-8deg);
  animation: time-penalty-fly 1050ms cubic-bezier(0.16, 0.9, 0.2, 1) forwards;
}

@keyframes time-penalty-fly {
  0% {
    opacity: 0;
    transform: translate(-50%, 16px) scale(0.7) rotate(-8deg);
  }

  24% {
    opacity: 1;
    transform: translate(-50%, -10px) scale(1.08) rotate(3deg);
  }

  68% {
    opacity: 1;
    transform: translate(-50%, -28px) scale(1) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -54px) scale(0.86) rotate(8deg);
  }
}

.settings-picture {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: url("assets/settings-gear-clean.png") center / 136% no-repeat;
  filter: drop-shadow(0 5px 8px rgba(77, 128, 255, 0.2));
}

.leaderboard-picture {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: url("assets/leaderboard-button.png") center / 136% no-repeat;
  filter: drop-shadow(0 5px 8px rgba(255, 198, 64, 0.24));
}

.shuffle-picture {
  width: 22px;
  height: 20px;
  border-radius: 6px;
  background: linear-gradient(135deg, #ffffff, rgba(255, 255, 255, 0.72));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.shuffle-picture::before,
.shuffle-picture::after {
  left: 4px;
  width: 14px;
  height: 5px;
  border: 2px solid #7b61ff;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0 8px 0 0;
}

.shuffle-picture::before {
  top: 5px;
  transform: skewX(-18deg);
}

.shuffle-picture::after {
  bottom: 5px;
  transform: rotate(180deg) skewX(-18deg);
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 300px);
  gap: clamp(20px, 4vw, 36px);
  align-items: center;
  padding: clamp(18px, 4vw, 48px) 0;
}

.game-panel,
.side-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow:
    0 28px 90px rgba(46, 56, 76, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.game-panel {
  padding: clamp(22px, 3vw, 34px);
}

.topbar,
.controls,
.status-strip,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1;
}

h1 {
  font-size: clamp(2.2rem, 5vw, 4rem);
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
  gap: 8px;
}

.stat,
.status-strip,
.preview {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  border-radius: 8px;
}

.stat {
  min-height: 72px;
  padding: 12px 14px;
}

.stat span,
.status-strip,
.win-dialog p {
  color: var(--muted);
}

.stat span {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(1.35rem, 3vw, 1.9rem);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.controls {
  margin: clamp(22px, 3vw, 30px) 0;
  flex-wrap: wrap;
}

.progress-panel {
  margin: -8px 0 18px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.62);
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.progress-copy strong {
  color: var(--accent);
  font-size: 0.88rem;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(95, 111, 135, 0.15);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.1);
}

.progress-track span {
  width: 0;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, #7b61ff, #4d80ff, #5ee0a3);
  box-shadow: 0 0 16px rgba(94, 224, 163, 0.3);
  transition: width 220ms ease;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(56px, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
}

.segment,
.icon-button,
.secondary-button,
.primary-button,
.dialog-actions button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
}

.segment {
  padding: 6px 13px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  font-weight: 800;
}

.difficulty-label {
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1;
  opacity: 0.78;
  text-transform: uppercase;
}

.size-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  line-height: 1;
}

.segment.locked {
  opacity: 0.42;
  filter: blur(1px) saturate(0.45);
  cursor: not-allowed;
  pointer-events: none;
}

.segment .button-icon,
.segment .picture-icon {
  width: 16px;
  height: 16px;
}

.segment.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 22px rgba(123, 97, 255, 0.24);
}

.segment[data-size="3"].active {
  background: linear-gradient(135deg, #5ee0a3, #25b879);
  color: white;
  box-shadow: 0 10px 22px rgba(37, 184, 121, 0.24);
}

.segment[data-size="4"].active {
  background: linear-gradient(135deg, #ffe680, #f6bf3c);
  color: #4b3511;
  box-shadow: 0 10px 22px rgba(246, 191, 60, 0.24);
}

.segment[data-size="5"].active {
  background: linear-gradient(135deg, #ff9a6c, #f05252);
  color: white;
  box-shadow: 0 10px 22px rgba(240, 82, 82, 0.24);
}

.actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 64px;
  min-height: 64px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  font-size: 1rem;
  box-shadow: 0 8px 22px rgba(42, 52, 70, 0.06);
}

.icon-button .picture-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
}

.icon-button.disabled,
.icon-button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.secondary-button,
.primary-button {
  padding: 0 18px;
  font-weight: 900;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, #8d72ff, #7657f3);
  box-shadow: 0 12px 25px rgba(123, 97, 255, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.board-wrap {
  display: grid;
  place-items: center;
}

.settings-page {
  width: min(760px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  align-content: center;
  padding: clamp(18px, 4vw, 48px) 0;
}

.settings-panel {
  padding: clamp(22px, 4vw, 36px);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow:
    0 28px 90px rgba(46, 56, 76, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.settings-list {
  display: grid;
  gap: 12px;
}

.settings-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

.settings-row {
  min-height: 82px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.settings-row h2 {
  font-size: 1.1rem;
  margin-bottom: 5px;
}

.settings-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.background-options,
.setting-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 8px;
}

.settings-choice {
  min-width: 112px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 7px;
  color: white;
  background: linear-gradient(135deg, #8d72ff, #7657f3);
  box-shadow: 0 12px 25px rgba(123, 97, 255, 0.2);
  cursor: pointer;
  font-weight: 900;
}

.settings-choice.easy {
  background: linear-gradient(135deg, #5ee0a3, #25b879);
  box-shadow: 0 12px 25px rgba(37, 184, 121, 0.22);
}

.settings-choice.normal {
  color: #4b3511;
  background: linear-gradient(135deg, #ffe680, #f6bf3c);
  box-shadow: 0 12px 25px rgba(246, 191, 60, 0.24);
}

.settings-choice.hard {
  background: linear-gradient(135deg, #ff9a6c, #f05252);
  box-shadow: 0 12px 25px rgba(240, 82, 82, 0.22);
}

.settings-choice.white {
  color: #202b3d;
  background: linear-gradient(135deg, #ffffff, #e9edf5);
  box-shadow: 0 12px 25px rgba(95, 111, 135, 0.14);
}

.settings-choice.black {
  color: white;
  background: linear-gradient(135deg, #2d3447, #05070d);
  box-shadow: 0 12px 25px rgba(5, 7, 13, 0.28);
}

.settings-choice:not(.active) {
  opacity: 0.58;
  box-shadow: none;
}

.settings-choice.active {
  outline: 3px solid rgba(123, 97, 255, 0.28);
  outline-offset: 3px;
}

.switch-toggle {
  width: 64px;
  min-width: 64px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.switch-rail {
  position: relative;
  width: 64px;
  height: 38px;
  border-radius: 999px;
  background: #d8dde6;
  box-shadow:
    inset 0 0 0 1px rgba(95, 111, 135, 0.16),
    0 6px 14px rgba(42, 52, 70, 0.1);
  transition:
    background 180ms ease,
    box-shadow 180ms ease;
}

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.22),
    0 1px 2px rgba(0, 0, 0, 0.12);
  transition:
    left 160ms ease,
    transform 160ms ease;
}

.switch-toggle.active .switch-rail {
  background: #34c759;
  box-shadow:
    inset 0 0 0 1px rgba(25, 140, 75, 0.14),
    0 8px 18px rgba(52, 199, 89, 0.25);
}

.switch-toggle.active .switch-knob {
  left: 29px;
}

.switch-toggle:active .switch-knob {
  transform: scaleX(1.12);
}

body.bg-black .switch-rail {
  background: #505867;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 6px 14px rgba(0, 0, 0, 0.18);
}

.puzzle-frame {
  width: min(60vh, 100%);
  max-width: 650px;
  aspect-ratio: 1;
  padding: clamp(20px, 3vw, 34px);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(94, 224, 163, var(--solve-bg)), transparent 62%),
    rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(94, 224, 163, var(--solve-border));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    0 18px 46px rgba(46, 56, 76, 0.08),
    0 0 calc(14px + var(--solve-progress) * 38px) rgba(94, 224, 163, var(--solve-glow));
  transition:
    border-color 220ms ease,
    box-shadow 220ms ease,
    background 220ms ease;
}

.puzzle-board,
.mini-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  gap: var(--gap);
  padding: var(--gap);
  border-radius: 7px;
  background: transparent;
  overflow: hidden;
  touch-action: none;
}

.tile,
.mini-tile {
  position: relative;
  border-radius: clamp(5px, 1vw, 8px);
  display: grid;
  place-items: center;
  user-select: none;
}

.tile {
  position: absolute;
  width: calc((100% - (var(--gap) * (var(--size) + 1))) / var(--size));
  height: calc((100% - (var(--gap) * (var(--size) + 1))) / var(--size));
  left: calc(var(--gap) + (var(--col) * (100% - var(--gap)) / var(--size)));
  top: calc(var(--gap) + (var(--row) * (100% - var(--gap)) / var(--size)));
  border: 1px solid rgba(95, 111, 135, 0.12);
  color: var(--tile-ink);
  background: linear-gradient(145deg, var(--tile-a), var(--tile-b));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 8px 16px rgba(46, 56, 76, 0.12);
  cursor: pointer;
  font-family: inherit;
  font-size: clamp(1.6rem, calc(13rem / var(--size)), 4.4rem);
  font-weight: 800;
  line-height: 1;
  transition:
    left 180ms ease,
    top 180ms ease,
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

body.reduce-motion .tile,
body.reduce-motion .empty-cell {
  transition: none;
}

body.reduce-motion .tile:hover {
  transform: none;
}

.image-board .tile,
.image-board .mini-tile {
  color: transparent;
  background-color: #eef3fa;
  background-position: var(--image-x) var(--image-y);
  background-size: var(--image-size) var(--image-size);
  background-repeat: no-repeat;
}

.image-board .tile {
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 8px 16px rgba(46, 56, 76, 0.14);
}

.image-board .tile::after,
.image-board .mini-tile:not(.mini-empty)::after {
  content: none;
}

.tile.movable {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 12px 24px rgba(123, 97, 255, 0.16);
}

.tile.hinted {
  transform: translateY(-3px) scale(1.03);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 0 0 4px rgba(77, 168, 255, 0.34),
    0 18px 32px rgba(77, 128, 255, 0.28);
}

.tile.hinted::before {
  content: "";
  position: absolute;
  z-index: 2;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: linear-gradient(135deg, var(--accent), #4d80ff);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.34),
    0 8px 18px rgba(77, 128, 255, 0.32);
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1;
}

.tile.hint-up::before {
  content: "↑";
  top: 10px;
  left: calc(50% - 17px);
}

.tile.hint-down::before {
  content: "↓";
  bottom: 10px;
  left: calc(50% - 17px);
}

.tile.hint-left::before {
  content: "←";
  top: calc(50% - 17px);
  left: 10px;
}

.tile.hint-right::before {
  content: "→";
  top: calc(50% - 17px);
  right: 10px;
}

.tile:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(123, 97, 255, 0.32);
  outline-offset: 3px;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile.dragging {
  transition: none;
  transform: scale(1.03);
  z-index: 5;
}

.empty-cell {
  position: absolute;
  width: calc((100% - (var(--gap) * (var(--size) + 1))) / var(--size));
  height: calc((100% - (var(--gap) * (var(--size) + 1))) / var(--size));
  left: calc(var(--gap) + (var(--col) * (100% - var(--gap)) / var(--size)));
  top: calc(var(--gap) + (var(--row) * (100% - var(--gap)) / var(--size)));
  border-radius: 7px;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.08), transparent 38%),
    linear-gradient(145deg, #2f3b52, var(--slot));
  box-shadow:
    inset 0 12px 24px rgba(0, 0, 0, 0.12),
    inset 0 0 0 1px rgba(32, 43, 61, 0.12);
  transition:
    left 180ms ease,
    top 180ms ease;
}

.side-panel {
  display: grid;
  gap: 12px;
  padding: 18px;
  background:
    radial-gradient(circle at 80% 18%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 8rem),
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(245, 248, 255, 0.78));
}

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

.side-header .kicker {
  margin-bottom: 4px;
}

.side-header h2 {
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  line-height: 1.05;
}

.side-pill {
  min-width: 54px;
  padding: 8px 10px;
  border-radius: 999px;
  color: white;
  background: linear-gradient(135deg, var(--accent), #4d80ff);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 10px 22px color-mix(in srgb, var(--accent) 28%, transparent);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.preview {
  padding: 14px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.82), rgba(240, 245, 255, 0.68));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.88),
    0 14px 34px rgba(46, 56, 76, 0.08);
}

.mini-board {
  --gap: 5px;
  border: 1px solid rgba(95, 111, 135, 0.12);
  padding: 9px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 84% 18%, color-mix(in srgb, var(--accent) 11%, transparent), transparent 5rem),
    rgba(250, 251, 254, 0.94);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.76),
    0 8px 20px rgba(46, 56, 76, 0.06);
}

.mini-tile {
  min-width: 0;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(95, 111, 135, 0.09);
  color: var(--accent);
  font-size: clamp(0.72rem, 2.2vw, 1rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 10px rgba(46, 56, 76, 0.04);
}

.mini-empty {
  background: linear-gradient(145deg, rgba(123, 97, 255, 0.1), rgba(123, 97, 255, 0.02));
}

.status-strip {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.3fr);
  gap: 8px;
  margin-top: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-weight: 800;
  font-size: 0.92rem;
}

.status-chip,
.best-chip {
  min-height: 46px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.status-chip {
  justify-content: flex-start;
  color: var(--accent);
}

.best-chip {
  justify-content: flex-end;
  color: var(--muted);
  text-align: right;
}

body.bg-black .side-panel {
  background:
    radial-gradient(circle at 80% 18%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 8rem),
    linear-gradient(145deg, rgba(17, 23, 38, 0.9), rgba(10, 14, 25, 0.82));
}

body.bg-black .preview,
body.bg-black .mini-board {
  background:
    radial-gradient(circle at 82% 18%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 5rem),
    rgba(20, 29, 47, 0.82);
}

body.bg-black .status-strip {
  background: transparent;
}

body.bg-black .status-chip,
body.bg-black .best-chip {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.win-dialog {
  width: min(460px, calc(100vw - 34px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 12%, rgba(123, 97, 255, 0.14), transparent 9rem),
    linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(247, 250, 255, 0.92));
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.92);
  overflow: hidden;
}

.win-dialog::backdrop {
  background: rgba(5, 9, 18, 0.58);
  backdrop-filter: blur(8px);
}

.win-dialog form {
  position: relative;
  padding: 34px;
}

.win-badge {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 50%;
  color: white;
  background: linear-gradient(135deg, #5ee0a3, #25b879);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 16px 30px rgba(37, 184, 121, 0.28);
  font-size: 1.85rem;
  font-weight: 900;
}

.loss-dialog .win-badge {
  background: linear-gradient(135deg, #ffb86b, #f05252);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.38),
    0 16px 30px rgba(240, 82, 82, 0.28);
  font-size: 2rem;
}

.loss-dialog .kicker {
  color: #f05252;
}

.win-dialog h2 {
  font-size: clamp(2rem, 6vw, 3rem);
}

.fly-title {
  display: flex;
  flex-wrap: wrap;
  gap: 0.02em;
  perspective: 500px;
}

.fly-letter {
  display: inline-block;
  opacity: 0;
  transform: translate3d(var(--x), var(--y), 0) rotate(var(--r)) scale(0.4);
  animation: letter-land 620ms cubic-bezier(0.2, 0.9, 0.22, 1.25) forwards;
  animation-delay: var(--delay);
  text-shadow: 0 14px 34px rgba(240, 82, 82, 0.24);
}

@keyframes letter-land {
  58% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1.16);
  }

  78% {
    transform: translate3d(0, -7px, 0) rotate(0deg) scale(0.96);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  }
}

.win-dialog p {
  margin: 10px 0 0;
}

.win-score {
  width: fit-content;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-weight: 800;
}

.account-dialog,
.leaderboard-dialog {
  width: min(560px, calc(100vw - 34px));
}

.auth-note {
  max-width: 34rem;
  font-weight: 800;
}

.field-row {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.field-row input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  font: inherit;
  font-weight: 800;
  outline: 0;
}

.field-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 97, 255, 0.18);
}

.form-message {
  min-height: 1.3rem;
  color: #f05252;
  font-weight: 900;
}

.text-button {
  margin-top: 16px;
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 48px 82px 56px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.leaderboard-row strong {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #4b3511;
  background: linear-gradient(135deg, #ffe680, #f6bf3c);
}

.leaderboard-row span:nth-child(2) {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-leaderboard {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  font-weight: 900;
}

.dialog-actions {
  margin-top: 24px;
  justify-content: flex-start;
}

.dialog-actions button {
  min-width: 116px;
  padding: 0 18px;
  font-weight: 900;
}

.dialog-actions .secondary-button {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
}

.guest-button {
  color: #4b3511;
  background: linear-gradient(135deg, #ffe680, #f6bf3c);
  border: 0;
}

body.bg-black .win-dialog {
  background:
    radial-gradient(circle at 88% 12%, rgba(123, 97, 255, 0.2), transparent 9rem),
    linear-gradient(145deg, rgba(24, 29, 44, 0.98), rgba(12, 17, 29, 0.96));
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

body.bg-black .win-score,
body.bg-black .dialog-actions .secondary-button,
body.bg-black .field-row input,
body.bg-black .leaderboard-row,
body.bg-black .empty-leaderboard {
  background: rgba(255, 255, 255, 0.07);
}

body.table-wood .puzzle-frame {
  background:
    radial-gradient(circle at 50% 50%, rgba(94, 224, 163, var(--solve-bg)), transparent 62%),
    radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.22), transparent 28%),
    repeating-linear-gradient(96deg, rgba(87, 45, 18, 0.12) 0 7px, transparent 7px 18px),
    linear-gradient(135deg, #c28a4d, #8d5527 58%, #6f3f1b);
  border-color: rgba(94, 224, 163, var(--solve-border));
  box-shadow:
    inset 0 0 0 3px rgba(255, 235, 190, 0.14),
    inset 0 0 28px rgba(61, 33, 14, 0.18),
    0 22px 54px rgba(71, 45, 23, 0.18),
    0 0 calc(14px + var(--solve-progress) * 38px) rgba(94, 224, 163, var(--solve-glow));
}

body.table-wood .puzzle-board {
  background: rgba(67, 38, 19, 0.18);
}

body.table-wood .empty-cell {
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 223, 171, 0.1), transparent 36%),
    linear-gradient(145deg, #4c2e18, #2d1b10);
}

body.table-dark .puzzle-frame {
  background:
    radial-gradient(circle at 50% 50%, rgba(94, 224, 163, var(--solve-bg)), transparent 62%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 38%),
    linear-gradient(135deg, #162033, #0e1423);
  border-color: rgba(94, 224, 163, var(--solve-border));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 24px 60px rgba(20, 26, 44, 0.24),
    0 0 calc(14px + var(--solve-progress) * 38px) rgba(94, 224, 163, var(--solve-glow));
}

body.table-dark .puzzle-board {
  background: rgba(0, 0, 0, 0.14);
}

body.table-dark .empty-cell {
  background:
    radial-gradient(circle at 28% 22%, rgba(123, 97, 255, 0.24), transparent 38%),
    linear-gradient(145deg, #11192a, #050816);
  box-shadow:
    inset 0 14px 26px rgba(0, 0, 0, 0.22),
    0 0 24px rgba(123, 97, 255, 0.12);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .side-header,
  .preview {
    display: none;
  }

  .status-strip {
    margin-top: 0;
  }
}

@media (max-width: 560px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body {
    min-height: 100dvh;
    background: linear-gradient(135deg, #f5f8fd, #ffffff 56%, #f4f7fb), var(--bg);
  }

  body.bg-black {
    background: linear-gradient(135deg, #090d18, #03050a 56%, #0b1020), var(--bg);
  }

  .app-shell {
    width: 100%;
    min-height: auto;
    gap: 12px;
    padding: 8px 8px 18px;
    align-items: start;
  }

  .game-panel,
  .side-panel,
  .settings-panel {
    width: 100%;
    min-width: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .game-panel {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  h1 {
    font-size: clamp(2rem, 11vw, 2.7rem);
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat {
    min-height: 70px;
  }

  .stats,
  .segmented,
  .actions,
  .primary-button {
    width: 100%;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .icon-button {
    width: 100%;
    min-height: 58px;
    min-width: 0;
  }

  .icon-button .picture-icon {
    width: 36px;
    height: 36px;
  }

  .actions .primary-button {
    grid-column: 1 / -1;
  }

  .leaderboard-row {
    grid-template-columns: 30px minmax(0, 1fr) 44px;
  }

  .leaderboard-row span:nth-child(4),
  .leaderboard-row span:nth-child(5) {
    display: none;
  }

  .segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .segment {
    min-width: 0;
    padding: 6px 4px;
    gap: 3px;
    font-size: 0.95rem;
  }

  .difficulty-label {
    font-size: 0.58rem;
  }

  .size-label {
    gap: 4px;
  }

  .segment .picture-icon {
    width: 14px;
    height: 14px;
  }

  .puzzle-frame {
    width: 100%;
    padding: clamp(10px, 4vw, 18px);
    box-shadow: none;
  }

  .tile {
    font-size: clamp(1.25rem, calc(11rem / var(--size)), 3.4rem);
    transition:
      left 120ms ease,
      top 120ms ease,
      transform 120ms ease;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.42),
      0 4px 8px rgba(0, 0, 0, 0.12);
  }

  .tile:hover {
    transform: none;
  }

  .icon-button,
  .primary-button,
  .stat,
  .status-strip {
    box-shadow: none;
  }

  .settings-header,
  .settings-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-choice {
    width: 100%;
  }

  .switch-toggle {
    width: 64px;
    align-self: flex-end;
  }
}
