:root {
  color-scheme: light;
  --ink: #22313f;
  --muted: #64727f;
  --panel: rgba(248, 253, 249, 0.88);
  --panel-solid: #f8fdf9;
  --aqua: #4bc3bd;
  --aqua-deep: #168a89;
  --leaf: #a8dd83;
  --lemon: #ffe07a;
  --sky: #8fd3ff;
  --coral: #ff9478;
  --shadow: 0 22px 55px rgba(41, 112, 116, 0.18);
  --puzzle-aspect: 2 / 3;
  --puzzle-ratio: 0.6667;
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(75, 195, 189, 0.18), transparent 34%),
    linear-gradient(220deg, rgba(255, 224, 122, 0.28), transparent 38%),
    linear-gradient(0deg, #f1ffe8, #f8fffb 48%, #eef8ff);
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 26px 0;
  display: grid;
  place-items: center;
}

.game-panel {
  width: 100%;
  padding: clamp(16px, 3vw, 30px);
  border: 2px solid rgba(75, 195, 189, 0.42);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar,
.brand-lockup,
.actions,
.controls,
.stats,
.play-area {
  display: flex;
}

.topbar {
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand-lockup {
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border: 3px solid #fff;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--aqua-deep), var(--leaf) 58%, var(--lemon));
  box-shadow: 0 10px 22px rgba(41, 112, 116, 0.22);
  font-weight: 900;
  font-size: 1.25rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 4vw, 2.55rem);
  line-height: 1;
  letter-spacing: 0;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-weight: 650;
}

.actions {
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.icon-button,
.primary-button,
.segment {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease,
    background 160ms ease;
}

.icon-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  color: #fff;
  background: var(--aqua-deep);
  box-shadow: 0 10px 20px rgba(22, 138, 137, 0.22);
  font-weight: 850;
}

.icon-button:hover,
.primary-button:hover,
.segment:hover {
  transform: translateY(-2px);
  filter: saturate(1.05);
}

.icon-button:focus-visible,
.primary-button:focus-visible,
.segment:focus-visible,
select:focus-visible,
.tile:focus-visible {
  outline: 4px solid rgba(155, 220, 255, 0.72);
  outline-offset: 3px;
}

.controls {
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.control-group {
  display: grid;
  gap: 7px;
}

.control-label,
.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(68px, 1fr));
  gap: 6px;
  padding: 4px;
  border: 2px solid rgba(75, 195, 189, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.segment {
  padding: 0 12px;
  color: var(--ink);
  background: transparent;
  font-weight: 850;
}

.segment.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--aqua-deep), var(--leaf));
  box-shadow: 0 8px 16px rgba(22, 138, 137, 0.22);
}

select {
  min-height: 44px;
  min-width: min(320px, calc(100vw - 60px));
  padding: 0 38px 0 12px;
  border: 2px solid rgba(75, 195, 189, 0.24);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  font-weight: 760;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stats > div {
  min-width: 0;
  padding: 12px;
  border: 2px solid rgba(75, 195, 189, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.stats strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  line-height: 1.05;
}

.play-area {
  align-items: start;
  justify-content: center;
  gap: clamp(14px, 3vw, 26px);
}

.preview-panel {
  width: min(255px, 28vw);
  min-width: 180px;
  padding: 12px;
  border: 2px solid rgba(75, 195, 189, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 12px 24px rgba(41, 112, 116, 0.12);
}

.preview-label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.preview-panel img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--puzzle-aspect);
  border: 3px solid #fff;
  border-radius: 6px;
  object-fit: contain;
  background: #eef4f0;
  box-shadow: 0 10px 20px rgba(41, 112, 116, 0.14);
}

.puzzle-wrap {
  width: min(680px, 100%);
  display: grid;
  place-items: start center;
}

.puzzle-board {
  width: min(100%, calc(74vh * var(--puzzle-ratio)));
  aspect-ratio: var(--puzzle-aspect);
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  gap: clamp(4px, 1vw, 8px);
  padding: clamp(6px, 1vw, 10px);
  border: 2px solid rgba(75, 195, 189, 0.38);
  border-radius: 8px;
  background: rgba(250, 255, 248, 0.72);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.42);
}

.tile,
.empty-tile {
  width: 100%;
  height: 100%;
  border-radius: 6px;
}

.tile {
  position: relative;
  border: 0;
  padding: 0;
  overflow: hidden;
  background-image: var(--image);
  background-size: calc(var(--size) * 100%) calc(var(--size) * 100%);
  background-position: var(--x) var(--y);
  box-shadow: 0 9px 18px rgba(41, 112, 116, 0.16);
  cursor: pointer;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: inherit;
  pointer-events: none;
}

.tile.can-move {
  box-shadow:
    0 9px 18px rgba(41, 112, 116, 0.16),
    0 0 0 4px rgba(255, 224, 122, 0.46);
}

.tile:active {
  transform: scale(0.98);
}

.empty-tile {
  border: 2px dashed rgba(22, 138, 137, 0.28);
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.7) 0 12%, transparent 13%),
    rgba(232, 255, 240, 0.78);
}

.win-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 28px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #f8fdf9;
  box-shadow: var(--shadow);
  text-align: center;
}

.win-dialog::backdrop {
  background: rgba(34, 49, 63, 0.24);
  backdrop-filter: blur(4px);
}

.win-dialog img {
  display: block;
  width: min(210px, 70vw);
  height: auto;
  aspect-ratio: 3 / 4;
  margin: 0 auto 14px;
  border: 3px solid #fff;
  border-radius: 8px;
  object-fit: cover;
  background: #eef4f0;
  box-shadow: 0 12px 26px rgba(70, 50, 73, 0.16);
}

.win-dialog h2 {
  font-size: 1.8rem;
  letter-spacing: 0;
}

.win-dialog p {
  margin: 9px 0 20px;
  color: var(--muted);
  font-weight: 700;
}

.primary-button {
  width: 100%;
  padding: 13px 18px;
  font-weight: 900;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 18px, 660px);
    padding: 10px 0;
    align-items: start;
  }

  .topbar,
  .play-area {
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
  }

  .actions {
    width: 100%;
  }

  .icon-button {
    width: 100%;
  }

  .controls {
    align-items: stretch;
  }

  .control-group,
  select {
    width: 100%;
  }

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

  .preview-panel {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(86px, 120px) 1fr;
    align-items: center;
    gap: 12px;
  }

  .preview-label {
    margin: 0;
  }

  .puzzle-wrap {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .game-panel {
    padding: 12px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    grid-template-columns: 1fr;
  }

  .preview-label {
    margin-bottom: 9px;
  }

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

.utility-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.utility-link {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  text-decoration: none;
  color: var(--aqua-deep);
  background: rgba(255, 255, 255, 0.82);
  border: 2px solid rgba(75, 195, 189, 0.22);
  font-size: 0.82rem;
  font-weight: 800;
}

.utility-link-secondary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.68);
}

.utility-link:hover,
.utility-link:focus-visible {
  transform: translateY(-1px);
  outline: 4px solid rgba(155, 220, 255, 0.72);
  outline-offset: 3px;
}
