:root {
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--text);
  background: var(--background);
  font-synthesis: none;
  --green: #204f48;
  --muted: #788278;
  --line: #e1e2d7;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button {
  font: inherit;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button:focus-visible {
  outline: 3px solid var(--selection);
  outline-offset: 4px;
}
button[hidden] {
  display: none;
}
button,
img,
canvas {
  -webkit-user-select: none;
  user-select: none;
}
img {
  -webkit-user-drag: none;
}
button {
  touch-action: manipulation;
}
.home-header {
  max-width: 1320px;
  margin: auto;
  padding: 30px 54px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: none;
  padding: 0;
  font-family: Georgia, serif;
  font-size: 36px;
  letter-spacing: -1.5px;
}
.brand-mark {
  display: grid;
  place-items: center;
  background: var(--green);
  color: var(--on-accent);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 38px;
  line-height: 1;
}
.brand-detail {
  font:
    9px/1.5 ui-sans-serif,
    system-ui;
  letter-spacing: 2px;
  margin: 8px 0 0 13px;
  max-width: 65px;
  text-align: left;
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}
.button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  transition:
    background 0.15s,
    transform 0.15s;
}
.button:hover:not(:disabled) {
  background: var(--hover);
}
.button.primary {
  background: var(--green);
  border-color: var(--green);
  color: var(--on-accent);
}
.button.primary:hover {
  background: var(--accent-hover);
}
.button.subtle {
  background: transparent;
}
.button.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-line);
}
.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  display: inline-grid;
  place-items: center;
}
.icon-button:hover {
  background: var(--hover);
}
.home-main {
  max-width: 1320px;
  margin: auto;
  padding: 0 54px;
}

.eyebrow {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 2.3px;
  color: var(--muted);
  margin: 0 0 19px;
}

.offline {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 11px;
  min-height: 30px;
  margin-bottom: 32px;
}
.status-dot {
  width: 6px;
  height: 6px;
  background: var(--progress);
  border-radius: 50%;
  flex-shrink: 0;
}
.collection {
  margin: 0 0 44px;
}
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 22px;
}
h2 {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: 26px;
  letter-spacing: -0.5px;
  margin: 0;
}
.subtle-label {
  font-size: 11px;
  color: var(--muted);
}
.categories {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.category-tab {
  border: 1px solid var(--line);
  background: transparent;
  padding: 9px 17px;
  border-radius: 24px;
  font-size: 12px;
}
.category-tab.active {
  color: var(--on-accent);
  background: var(--green);
  border-color: var(--green);
}
.category-heading {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 14px;
}
.category-section {
  margin-bottom: 30px;
}
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}
.puzzle-card {
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  min-width: 0;
  border-radius: 13px;
}
.card-image {
  height: auto;
  aspect-ratio: 3/2;
  overflow: hidden;
  border-radius: 13px;
  background: var(--table);
  position: relative;
  box-shadow: 0 4px 16px #213e2c08;
}
.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s;
}
.puzzle-card:hover img {
  transform: scale(1.035);
}
.card-play {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface);
  font-size: 20px;
  opacity: 0;
  transform: translateY(5px);
  transition: 0.2s;
}
.puzzle-card:hover .card-play,
.puzzle-card:focus-visible .card-play {
  opacity: 1;
  transform: none;
}
.card-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 14px 0 10px;
}
.progress-label {
  color: var(--muted);
}
.progress-track {
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--progress);
  transition: width 0.3s;
}
.home-footer {
  padding: 20px 0 34px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.playing {
  overflow: hidden;
}
.playing #app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 22px;
  gap: 20px;
  background: var(--background);
  z-index: 2;
  border-bottom: 1px solid var(--line);
}
.game-heading {
  display: flex;
  align-items: center;
  gap: 20px;
}
.game-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}
.game-detail strong {
  font-weight: 600;
}
.game-detail span {
  font-size: 11px;
  color: var(--muted);
}
.game-progress {
  width: 135px;
  flex-shrink: 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.game-progress .progress-track {
  margin-top: 8px;
}
.game-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}
.game-tools .button {
  padding: 10px 12px;
}
.workspace {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--table);
  overflow: hidden;
}
.puzzle-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}
.workspace-hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  background: var(--surface);
  padding: 7px 15px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
}
.tray-section {
  background: var(--background);
  border-top: 1px solid var(--line);
  padding: 4px 8px 2px;
  flex-shrink: 0;
}
.tray-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
}
.tray-heading strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.tray-instruction {
  margin-left: auto;
}
.piece-tray {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  padding: 2px 0 3px;
}
.tray-piece {
  width: 68px;
  height: 68px;
  flex: 0 0 68px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  touch-action: pan-x;
}
.tray-piece:hover {
  background: var(--hover);
}
.tray-piece.selected {
  background: var(--selected);
  border-color: var(--green);
}
.tray-piece canvas {
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.held {
  background: var(--selected) !important;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  padding: 32px;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 30px 100px #19382540;
}
dialog::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(5px);
}
dialog h2 {
  font-size: 34px;
}
.dialog-copy {
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
  margin: 15px 0 22px;
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 25px;
}
.install-instructions {
  font-size: 14px;
  line-height: 1.65;
}
.install-instructions h3 {
  font-size: 14px;
  margin: 0 0 14px;
}
.install-instructions ol {
  padding-left: 24px;
  margin: 0;
}
.install-instructions li {
  padding-left: 5px;
  margin-bottom: 12px;
}
.install-instructions li::marker {
  color: var(--green);
  font-weight: 700;
}
.install-note,
.install-help p {
  color: var(--muted);
  font-size: 12px;
}
.install-note {
  margin: 18px 0;
}
.install-help summary,
.install-help a {
  color: var(--green);
  cursor: pointer;
  font-size: 12px;
}
.install-help summary:focus-visible,
.install-help a:focus-visible {
  outline: 3px solid var(--selection);
  outline-offset: 3px;
}
.setup-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--table);
}
.piece-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-top: 18px;
}
.piece-option {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
}
.piece-option strong {
  font-size: 20px;
  font-weight: 500;
}
.piece-option span {
  font-size: 10px;
  color: var(--muted);
}
.piece-option.active {
  border-color: var(--green);
  background: var(--selected);
}
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 15px);
  max-width: calc(100vw - 30px);
  padding: 13px 20px;
  background: var(--green);
  color: var(--on-accent);
  border-radius: 12px;
  box-shadow: 0 5px 25px #0002;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  font-size: 13px;
  transition: 0.2s;
}
#toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (min-width: 1500px) {
  .puzzle-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
@media (max-width: 900px) {
  .home-header {
    padding: 24px 30px;
  }
  .home-main {
    padding: 0 30px;
  }

  .puzzle-grid {
    gap: 16px;
  }
  .game-detail {
    display: none;
  }
}
@media (max-width: 600px) {
  .home-header {
    padding: 20px;
  }
  .home-main {
    padding: 0 20px;
  }
  .brand {
    font-size: 31px;
  }
  .brand-detail {
    font-size: 8px;
    letter-spacing: 1.5px;
  }
  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 32px;
  }

  .eyebrow {
    font-size: 9px;
    letter-spacing: 1.8px;
  }
  .offline {
    font-size: 10px;
    margin-bottom: 28px;
  }
  .section-heading {
    align-items: flex-start;
    gap: 8px;
  }
  .section-heading h2 {
    font-size: 22px;
  }
  .subtle-label {
    font-size: 10px;
    max-width: 75px;
    text-align: right;
    line-height: 1.6;
  }
  .puzzle-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
  .card-image {
    border-radius: 9px;
  }
  .category-tab {
    font-size: 11px;
    padding: 8px 12px;
  }
  .card-info {
    font-size: 11px;
  }
  .tray-instruction {
    font-size: 9px;
    max-width: 145px;
    text-align: right;
  }
  .workspace-hint {
    font-size: 9px;
    padding: 6px 10px;
    top: 10px;
  }
  dialog {
    padding: 25px;
  }
  dialog h2 {
    font-size: 29px;
  }
  .dialog-actions .button {
    font-size: 12px;
    padding: 11px 13px;
  }
  .setup-preview {
    max-height: 170px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

.image-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.image-controls label {
  font-size: 22px;
  line-height: 1;
}
.image-controls input {
  width: clamp(80px, 12vw, 160px);
  accent-color: var(--green);
  cursor: pointer;
  margin: 0;
}
.edge-filter {
  width: 68px;
  height: 68px;
  flex: 0 0 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  touch-action: pan-x;
}
.edge-filter svg {
  width: 28px;
  height: 28px;
}
.edge-filter[aria-pressed="true"] {
  background: var(--green);
  border-color: var(--green);
  color: var(--on-accent);
}
.tray-section {
  padding: 4px 8px 2px;
}
.piece-tray {
  min-height: 0;
}
.game-header {
  gap: 12px;
}
@media (min-width: 601px) and (max-width: 1100px) {
  .game-detail {
    display: none;
  }
}

/* One labelled layout at every width; only content overflow enables compact mode. */
.game-header {
  padding: 10px 10px;
  gap: 8px;
}
.game-heading {
  gap: 8px;
}
.game-progress {
  width: 90px;
  margin-left: 0;
}
.home-button {
  padding: 10px 10px;
}
.game-header .button {
  font-size: 13px;
  white-space: nowrap;
}
.game-tools {
  gap: 5px;
}
.game-tools .button {
  padding: 10px 8px;
}
.image-controls {
  margin-left: 0;
  gap: 8px;
}
.image-controls input {
  width: 90px;
}

.game-header {
  flex-wrap: nowrap;
}
.game-heading,
.game-tools {
  flex-shrink: 0;
}
.game-tools {
  width: auto;
  margin-left: auto;
}
.game-tools .button {
  flex: none;
}
.toolbar-icon + .toolbar-label {
  margin-left: 5px;
}
.game-header.toolbar-compact {
  padding: 8px 6px;
  gap: 4px;
}
.toolbar-compact .game-detail,
.toolbar-compact .toolbar-label {
  display: none;
}
.game-header.toolbar-compact .home-button,
.toolbar-compact .game-tools .button,
.toolbar-compact .game-tools .icon-button {
  width: 34px;
  height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 19px;
}
.toolbar-compact .game-progress {
  width: 46px;
  font-size: 9px;
  margin-left: 0;
}
.toolbar-compact .game-progress .progress-track {
  margin-top: 4px;
}
.toolbar-compact .image-controls {
  margin-left: 0;
  gap: 4px;
}
.toolbar-compact .image-controls label {
  font-size: 18px;
}
.toolbar-compact .image-controls input {
  width: clamp(40px, 10vw, 65px);
}
.toolbar-compact .game-tools {
  gap: 3px;
}

.home-header {
  flex-wrap: wrap;
  gap: 14px;
}
.header-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}
.theme-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.theme-picker select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 24px 10px 10px;
  cursor: pointer;
}
.theme-picker select:focus-visible {
  outline: 3px solid var(--selection);
  outline-offset: 3px;
}
@media (max-width: 480px) {
  .home-header .brand-detail {
    display: none;
  }
  .header-controls {
    gap: 8px;
  }
  .theme-picker {
    gap: 5px;
  }
}
