* {
  box-sizing: border-box;
}
:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--background);
}
body {
  margin: 0;
  min-width: 280px;
  -webkit-tap-highlight-color: transparent;
}
button,
select,
input {
  font: inherit;
}
button,
select {
  color: inherit;
}
button {
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled {
  opacity: 0.42;
  cursor: default;
}
button,
img,
.board {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button:focus-visible,
select:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--selection);
  outline-offset: 4px;
}
a {
  color: var(--accent);
  text-underline-offset: 4px;
}
h1,
h2,
h3,
p {
  margin-top: 0;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}
.ui-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.muted {
  color: var(--muted);
}
.home-shell {
  max-width: 1320px;
  margin: auto;
  padding: 0 44px;
}
.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 32px 0;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand img {
  border-radius: 12px;
}
.brand-title {
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.7px;
}
.brand-caption {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 0;
}
.home-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.home-controls .button {
  padding: 10px 12px;
}
.icon-control {
  padding: 10px 12px;
}
.home-controls .icon-control span {
  display: none;
}
.language-picker {
  display: flex;
  gap: 2px;
  margin-right: 8px;
}
.language-button {
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 10px 7px;
  min-height: 44px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 650;
}
.language-button[aria-pressed="true"] {
  background: var(--selected);
  color: var(--text);
}
.collection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 44px 0 28px;
  gap: 24px;
}
.eyebrow {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 650;
  margin-bottom: 15px;
}
.collection-heading h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 46px);
  font-weight: 400;
  letter-spacing: -1.4px;
  margin: 0 0 12px;
  line-height: 1.1;
}
.collection-copy {
  font-size: 14px;
  line-height: 1.65;
  margin: 0;
  max-width: 520px;
}
.collection-count {
  min-width: 120px;
  display: grid;
  gap: 4px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}
.collection-count strong {
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 44px;
  font-weight: 400;
}
.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 3px 22px;
  scrollbar-width: thin;
}
.category-tab {
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  padding: 10px 19px;
  font-size: 12px;
  min-height: 44px;
}
.category-tab:hover {
  background: var(--hover);
}
.category-tab[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.picture-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 25px;
  padding: 2px 0 40px;
}
.picture-card {
  padding: 0;
  text-align: left;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}
.picture-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px #0002;
}
.card-image {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--table);
}
.card-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.4s;
}
.picture-card:hover img {
  transform: scale(1.025);
}
.card-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  font-size: 12px;
  color: var(--text);
  gap: 12px;
}
.card-caption .ui-icon {
  width: 15px;
  height: 15px;
  color: var(--accent);
}
.picture-badge {
  position: absolute;
  bottom: 12px;
  left: 12px;
  border: 1px solid #ffffff35;
  border-radius: 99px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 650;
  background: #142b24db;
  color: #fff;
}
.home-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
  padding: 22px 0;
  font-size: 12px;
  color: var(--muted);
}
.offline-state::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 8px 1px 0;
  border-radius: 50%;
  background: var(--muted);
}
.offline-ready::before {
  background: var(--accent);
}
dialog {
  width: min(540px, calc(100vw - 28px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 20px 90px #0005;
}
dialog::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(5px);
}
dialog h2 {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: 29px;
  letter-spacing: -0.7px;
  padding-right: 20px;
  margin-bottom: 18px;
}
dialog p,
.rules {
  font-size: 14px;
  line-height: 1.65;
  color: var(--muted);
}
.dialog-close {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  font-size: 24px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.dialog-close:hover {
  background: var(--hover);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}
.dialog-actions .primary {
  flex-grow: 1;
}
.setup-image {
  display: block;
  max-height: 255px;
  width: 100%;
  object-fit: contain;
  background: var(--table);
  border-radius: 10px;
}
.size-options {
  margin: 22px 0 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.size-options legend {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.size-choice {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 8px;
  cursor: pointer;
  text-align: center;
}
.size-choice:has(input:checked) {
  background: var(--selected);
  border-color: var(--accent);
}
.size-choice:has(input:focus-visible) {
  outline: 3px solid var(--selection);
  outline-offset: 3px;
}
.size-choice input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.size-choice span {
  display: grid;
  gap: 6px;
  font-size: 12px;
}
.size-choice small {
  color: var(--muted);
  font-size: 11px;
}
.size-choice .saved-label {
  color: var(--accent);
  font-weight: 650;
}
.rules {
  padding-left: 20px;
}
.rules li {
  margin-bottom: 14px;
  padding-left: 5px;
}
.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.settings-section h3 {
  font-size: 14px;
  margin-bottom: 8px;
}
.settings-section p {
  font-size: 13px;
  margin-bottom: 12px;
}
.theme-picker {
  font-size: 13px;
  justify-content: space-between;
  width: 100%;
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 13px;
  cursor: pointer;
}
.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.update-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.update-controls p {
  width: 100%;
  margin-bottom: 0;
}
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 14px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 30px #0003;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  font-size: 13px;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.save-warning {
  padding: 12px 18px;
  border: 1px solid var(--danger-line);
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  margin: 12px 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.game-shell {
  margin: auto;
  height: 100dvh;
  min-height: 320px;
  padding: 0 16px 12px;
  display: grid;
  grid-template-areas: "header" "warning" "board" "stats" "controls" "caption";
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
}
.game-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 0;
}
.game-shell .save-warning {
  grid-area: warning;
}
.game-title {
  flex-grow: 1;
  text-align: center;
}
.game-title h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 5px;
}
.game-title span {
  font-size: 11px;
}
.play-area {
  grid-area: board;
  container-type: size;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  min-width: 0;
  padding: 12px;
  background: radial-gradient(ellipse at 50% 35%, var(--surface), var(--table));
  border: 1px solid var(--line);
  border-radius: 18px;
}
.board-frame {
  position: relative;
  width: min(100cqw, calc(100cqh * var(--picture-ratio)));
  border-radius: 6px;
  box-shadow:
    0 12px 50px #0005,
    0 0 0 7px var(--background),
    0 0 0 8px var(--line);
}
.board {
  position: relative;
  width: 100%;
  touch-action: none;
}
.tile,
.move-ghost {
  position: absolute;
  padding: 0;
  border: 0;
  outline: none;
  background-repeat: no-repeat;
  border-radius: 0;
  cursor: grab;
  box-shadow:
    inset 1px 0 var(--edge-left),
    inset -1px 0 var(--edge-right),
    inset 0 1px var(--edge-top),
    inset 0 -1px var(--edge-bottom);
}
.move-ghost {
  z-index: 4;
  pointer-events: none;
}
.tile.selected {
  z-index: 2;
  filter: brightness(1.12);
  outline: 2px solid var(--selection);
  outline-offset: -3px;
}
.tile:focus-visible {
  outline: 3px solid var(--selection);
  outline-offset: -4px;
  z-index: 3;
}
.tile.dragging {
  z-index: 6;
  cursor: grabbing;
  filter: drop-shadow(0 12px 10px #0007) brightness(1.08);
  outline: 1px solid #ffffff70;
  outline-offset: -1px;
}
.tile span:not(:empty) {
  position: absolute;
  bottom: 6px;
  left: 6px;
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 3px;
  border-radius: 5px;
  background: #142b24de;
  color: white;
  font-size: 11px;
  pointer-events: none;
}
.drop-target {
  position: absolute;
  z-index: 5;
  border: 3px solid var(--selection);
  background: #ffffff20;
  pointer-events: none;
}
.full-picture {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: 4px;
  background: var(--table);
}
.board.complete .tile {
  cursor: default;
}
.game-stats {
  grid-area: stats;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 0;
  font-size: 12px;
  color: var(--muted);
}
.puzzle-progress {
  width: 100px;
  height: 4px;
  accent-color: var(--accent);
  border: 0;
  border-radius: 9px;
  overflow: hidden;
}
.puzzle-progress::-webkit-progress-bar {
  background: var(--line);
}
.puzzle-progress::-webkit-progress-value {
  background: var(--accent);
}
.game-toolbar {
  grid-area: controls;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.game-toolbar .button {
  font-size: 12px;
  padding: 11px 15px;
}
.game-toolbar [aria-pressed="true"] {
  background: var(--selected);
  border-color: var(--accent);
}
.game-caption {
  grid-area: caption;
  font-size: 11px;
  text-align: center;
  margin: 10px 0 0;
}
[hidden] {
  display: none !important;
}
@media (max-width: 1000px) {
  .home-shell {
    padding: 0 26px;
  }
  .home-header {
    flex-wrap: wrap;
    gap: 18px;
    padding: 24px 0;
  }
  .home-controls {
    margin-left: auto;
  }
  .picture-grid {
    gap: 18px;
  }
}
@media (max-width: 720px) {
  .home-shell {
    padding: 0 18px;
  }
  .home-header {
    gap: 16px;
    padding: 22px 0;
  }
  .brand-title {
    font-size: 22px;
  }
  .brand-caption {
    font-size: 11px;
  }
  .home-controls {
    width: 100%;
    margin-left: 0;
    gap: 8px;
    justify-content: space-between;
  }
  .language-picker {
    margin: 0;
  }
  .home-controls .button {
    font-size: 12px;
  }
  .collection-heading {
    padding: 30px 0 20px;
    gap: 14px;
  }
  .collection-count {
    min-width: 70px;
    font-size: 10px;
  }
  .collection-count strong {
    font-size: 36px;
  }
  .collection-copy {
    font-size: 12px;
  }
  .picture-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
  .card-caption {
    padding: 13px 11px;
    font-size: 11px;
  }
  .card-caption .ui-icon {
    width: 12px;
  }
  .home-footer {
    display: block;
    line-height: 1.6;
  }
  .home-footer p {
    margin-bottom: 10px;
  }
  .game-shell {
    padding: 0 10px 10px;
  }
  .game-header {
    gap: 10px;
    padding: 10px 0;
  }
  .game-header .button {
    padding: 10px 12px;
  }
  .game-header .button span {
    display: none;
  }
  .game-title h1 {
    font-size: 13px;
  }
  .play-area {
    border-radius: 13px;
  }
  .game-toolbar {
    gap: 7px;
  }
  .game-toolbar .button {
    padding: 10px 12px;
  }
  .game-toolbar .button span {
    display: none;
  }
  .game-toolbar .mode-button {
    font-size: 11px;
  }
  .game-stats {
    gap: 12px;
    font-size: 11px;
  }
  .puzzle-progress {
    width: 50px;
  }
  .game-caption {
    max-width: 280px;
    justify-self: center;
    margin-top: 10px;
    line-height: 1.5;
  }
  dialog {
    padding: 25px 20px;
  }
  dialog h2 {
    font-size: 25px;
  }
  .picture-badge {
    font-size: 10px;
    padding: 5px 8px;
    bottom: 8px;
    left: 8px;
  }
}
@media (max-width: 360px) {
  .home-shell {
    padding: 0 12px;
  }
  .language-button {
    padding: 9px 5px;
  }
  .home-controls {
    gap: 4px;
  }
  .collection-count {
    display: none;
  }
  .picture-grid {
    gap: 10px;
  }
  .card-caption {
    font-size: 10px;
  }
  .game-toolbar .button {
    padding: 10px;
  }
}
@media (max-height: 500px) and (min-width: 600px) {
  .game-shell {
    grid-template-columns: minmax(0, 1fr) 150px;
    grid-template-areas: "header header" "warning warning" "board controls" "board stats";
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 0 12px;
    padding-bottom: 10px;
  }
  .game-header {
    padding: 8px 0;
  }
  .game-toolbar {
    flex-direction: column;
  }
  .game-toolbar .button {
    min-height: 38px;
    padding: 8px;
  }
  .game-stats {
    flex-wrap: wrap;
    padding: 10px 0;
    gap: 6px 12px;
  }
  .game-caption {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
