.jigsaw-game {
  --jg-bg: #141c23; --jg-surface: #1d2832; --jg-line: #394852; --jg-text: #f1f5f4;
  --jg-muted: #acbdc3; --jg-accent: #84dbbd; --jg-table: #183e3a;
  height: var(--game-surface-height, calc(100dvh - 80px)); min-height: 180px;
  width: 100%; min-width: 0; display: flex; flex-direction: column; position: relative;
  overflow: hidden; background: var(--jg-bg); color: var(--jg-text); border: 1px solid var(--jg-line);
  border-radius: 6px; font: 13px/1.4 "Microsoft YaHei", system-ui, sans-serif; letter-spacing: 0;
}
.jigsaw-game *, .jigsaw-game *::before, .jigsaw-game *::after { box-sizing: border-box; }
.jigsaw-game button, .jigsaw-game input, .jigsaw-game select { font: inherit; letter-spacing: 0; }
.jigsaw-game [hidden] { display: none !important; }
.jigsaw-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; padding: 6px 8px; flex-shrink: 0; background: var(--jg-bg); border-bottom: 1px solid var(--jg-line); }
.jigsaw-game .jigsaw-title { font-size: 14px; font-weight: 600; margin: 0 8px 0 2px; color: var(--jg-text); white-space: nowrap; }
.jigsaw-game .jg-button { width: 32px; height: 32px; min-width: 32px; padding: 6px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--jg-muted); cursor: pointer; flex-shrink: 0; }
.jigsaw-game .jg-button:hover:not(:disabled) { background: #30453f; border-color: #648e80; color: #fff; }
.jigsaw-game .jg-button[aria-pressed=true] { background: #284b41; border-color: #548c78; color: var(--jg-accent); }
.jigsaw-game .jg-button:disabled { opacity: .4; cursor: default; }
.jigsaw-game .jg-button.is-text { width: auto; min-width: 64px; padding-inline: 10px; border-color: var(--jg-line); color: var(--jg-text); background: var(--jg-surface); }
.jigsaw-game .jg-button.is-primary { background: var(--jg-accent); color: #102c23; border-color: var(--jg-accent); }
.jigsaw-game .jg-button.is-primary:hover:not(:disabled) { background: #a9efd7; color: #102c23; }
.jigsaw-toolbar-divider { width: 1px; height: 22px; margin: 0 3px; background: var(--jg-line); }
.jigsaw-game select { border: 1px solid var(--jg-line); border-radius: 4px; height: 30px; background: #25303a; color: var(--jg-text); padding: 3px 6px; max-width: 140px; }
.jigsaw-tool-modes { display: flex; gap: 1px; }
.jigsaw-toolbar .jg-fullscreen { margin-left: auto; }
.game-page .jigsaw-game .game-page-tools { position: static; z-index: auto; display: flex; flex: 0 0 auto; width: auto; margin: 0 0 0 auto; padding: 0; }
.jigsaw-toolbar:has(.game-page-tools) .jg-fullscreen { margin-left: 0; }
.game-page .jigsaw-game .game-leaderboard-button { min-height: 30px; padding-inline: 9px; font-size: 12px; white-space: nowrap; }
.jigsaw-game .jigsaw-zoom-label { width: 44px; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; color: var(--jg-muted); }
.jigsaw-body { display: flex; flex: 1; min-height: 0; min-width: 0; }
.jigsaw-main { display: flex; min-width: 0; min-height: 0; flex: 1; }
.jigsaw-stage { flex: 1; min-width: 0; min-height: 0; position: relative; overflow: hidden; background: var(--jg-table); }
.jigsaw-stage > canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.jigsaw-stage > .jigsaw-base-layer { position: absolute; inset: 0; pointer-events: none; }
.jigsaw-stage > [data-jigsaw-canvas] { position: relative; }
.jigsaw-game > .jigsaw-drag-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.jigsaw-stage[data-tool=move] > canvas { cursor: grab; }
.jigsaw-stage.is-dragging > canvas { cursor: grabbing; }
.jigsaw-reference { width: 138px; flex-shrink: 0; padding: 10px; background: #1a2b2d; border-left: 1px solid var(--jg-line); overflow: auto; }
.jigsaw-reference[hidden] { display: none; }
.jigsaw-reference img { display: block; width: 100%; height: auto; }
.jigsaw-reference span { display: block; margin-bottom: 8px; font-size: 11px; color: var(--jg-muted); }
.jigsaw-tray { width: 210px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0; background: var(--jg-surface); border-left: 1px solid var(--jg-line); }
.jigsaw-tray-head { height: 39px; padding: 4px 9px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; border-bottom: 1px solid var(--jg-line); }
.jigsaw-tray-head > span { font-weight: 600; flex: 1; color: var(--jg-text); }
.jigsaw-tray-head label { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--jg-muted); white-space: nowrap; }
.jigsaw-game input[type=checkbox] { accent-color: var(--jg-accent); }
.jigsaw-tray-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; scrollbar-width: thin; scrollbar-color: #596b70 #202e35; overscroll-behavior: contain; }
.jigsaw-tray-spacer { position: relative; width: 100%; }
.jigsaw-tray canvas { display: block; position: sticky; top: 0; left: 0; width: 100%; touch-action: none; }
.jigsaw-status { display: flex; align-items: center; flex-shrink: 0; gap: 12px; height: 29px; padding: 4px 9px; font-size: 11px; background: var(--jg-bg); border-top: 1px solid var(--jg-line); color: var(--jg-muted); }
.jigsaw-status > span { white-space: nowrap; font-variant-numeric: tabular-nums; }
.jigsaw-status .jigsaw-save { margin-left: auto; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.jigsaw-save.is-error { color: #ffabb0; }
.jigsaw-game .jigsaw-retry-save { height: 24px; min-width: 24px; width: 24px; padding: 4px; color: #ffabb0; }
.jigsaw-progress { height: 2px; flex-shrink: 0; background: #263630; }
.jigsaw-progress > span { display: block; height: 100%; background: var(--jg-accent); transition: width 160ms ease-out; width: 0; }
.jigsaw-stage-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #0b211dc4; z-index: 4; padding: 12px; }
.jigsaw-stage-overlay:empty { display: none; }
.jigsaw-stage-overlay section { max-width: 340px; text-align: center; padding: 20px; background: var(--jg-bg); border: 1px solid #588878; border-radius: 6px; }
.jigsaw-stage-overlay h2 { font-size: 18px; margin: 0 0 12px; color: var(--jg-text); }
.jigsaw-stage-overlay p { color: var(--jg-muted); margin: 0 0 16px; }
.jigsaw-modal-host:empty { display: none; }
.jigsaw-modal-backdrop { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 12px; background: #081214bd; }
.jigsaw-dialog { width: min(620px, 100%); max-height: 100%; overflow: auto; background: var(--jg-bg); border: 1px solid #627b78; border-radius: 6px; box-shadow: 0 10px 35px #0006; padding: 16px; }
.jigsaw-dialog-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.jigsaw-game .jigsaw-dialog h2 { margin: 0; font-size: 17px; flex: 1; color: var(--jg-text); }
.jigsaw-draft-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.jigsaw-draft-controls select { max-width: 190px; flex: 1; }
.jigsaw-preview { height: min(290px, 38dvh); display: flex; align-items: center; justify-content: center; background: #102d29; overflow: hidden; border: 1px solid #344d48; }
.jigsaw-preview img { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; object-fit: contain; }
.jigsaw-preview .jigsaw-blank-preview { height: 80%; aspect-ratio: 1; background: #dce5e0; border: 1px solid #a5b7ae; }
.jigsaw-image-error { text-align: center; padding: 12px; color: #ffabb0; }
.jigsaw-preview-meta { color: var(--jg-muted); font-size: 11px; margin-top: 7px; min-height: 16px; }
.jigsaw-dialog-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.jigsaw-game .jigsaw-replace-note { margin: 0 auto 0 0; color: #d7c495; font-size: 11px; }
.jigsaw-crop-area { height: min(360px, 43dvh); background: #0f161b; }
.jigsaw-crop-area > img { display: block; max-width: 100%; }
.jigsaw-crop-toolbar { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.jigsaw-game .jigsaw-crop-toolbar .jg-button { min-width: 28px; width: 28px; }
.jigsaw-game .jigsaw-crop-toolbar input[type=range] { flex: 1; min-width: 70px; width: 100px; accent-color: var(--jg-accent); }
.jigsaw-records { width: 100%; border-collapse: collapse; margin-top: 10px; color: var(--jg-muted); }
.jigsaw-records th, .jigsaw-records td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--jg-line); }
.jigsaw-library-dialog { width: min(900px, 100%); display: flex; flex-direction: column; max-height: 100%; overflow: hidden; }
.jigsaw-library-top, .jigsaw-library-space, .jigsaw-library-tools, .jigsaw-library-pages { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.jigsaw-library-top { justify-content: space-between; margin-bottom: 10px; color: var(--jg-text); }
.jigsaw-library-space { font-size: 11px; color: var(--jg-muted); font-variant-numeric: tabular-nums; }
.jigsaw-library-space strong { color: var(--jg-accent); font-weight: 500; }
.jigsaw-library-note { margin: 8px 0 12px; font-size: 12px; color: var(--jg-muted); line-height: 1.6; }
.jigsaw-library-note .jg-button { margin-left: 6px; font-size: 11px; }
.jigsaw-library-scroll { overflow: auto; min-height: 90px; max-height: min(480px, 48dvh); overscroll-behavior: contain; scrollbar-width: thin; padding-right: 4px; }
.jigsaw-library-group { padding: 12px 0 16px; border-top: 1px solid var(--jg-line); }
.jigsaw-library-group > header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.jigsaw-library-group > header > div:first-child { min-width: 0; flex: 1; }
.jigsaw-library-group strong { display: block; font-size: 13px; overflow-wrap: anywhere; font-weight: 500; }
.jigsaw-library-group small { display: block; margin-top: 3px; color: var(--jg-muted); font-size: 11px; }
.jigsaw-library-group-actions { display: flex; flex-shrink: 0; gap: 6px; }
.jigsaw-library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.jigsaw-library-card { background: #1d2832; border: 1px solid var(--jg-line); border-radius: 4px; overflow: hidden; }
.jigsaw-library-thumbnail { display: grid; place-items: center; width: 100%; height: 150px; border: 0; border-bottom: 1px solid var(--jg-line); background: #102d29; padding: 8px; cursor: pointer; }
.jigsaw-library-thumbnail img { display: block; width: 100%; height: 100%; object-fit: contain; font-size: 11px; color: var(--jg-muted); }
.jigsaw-library-thumbnail:hover { background: #23483f; }
.jigsaw-library-caption { display: flex; gap: 5px; align-items: center; padding: 8px; }
.jigsaw-library-caption > span { flex: 1; color: var(--jg-text); font-size: 11px; font-variant-numeric: tabular-nums; }
.jigsaw-game .jigsaw-library-caption .jg-button { min-width: 40px; padding-inline: 6px; font-size: 11px; }
.jigsaw-library-empty { padding: 32px 12px; text-align: center; color: var(--jg-text); }
.jigsaw-library-empty p { color: var(--jg-muted); font-size: 12px; }
.jigsaw-library-feedback { padding: 8px 10px; margin: 8px 0; border-left: 2px solid var(--jg-accent); background: #203c34; color: var(--jg-accent); font-size: 12px; overflow-wrap: anywhere; }
.jigsaw-library-feedback.is-error { color: #ffc0bd; border-color: #ed9993; background: #402d30; }
.jigsaw-library-feedback .jg-button { margin: 5px 0 0 6px; }
.jigsaw-library-tools { border-top: 1px solid var(--jg-line); padding-top: 12px; flex-shrink: 0; }
.jigsaw-library-tools > :last-child { margin-left: auto; }
.jigsaw-library-pages { justify-content: center; min-height: 12px; margin: 6px 0; color: var(--jg-muted); font-size: 11px; flex-shrink: 0; }
.jigsaw-game :is(button, select, input):focus-visible { outline: 2px solid var(--jg-accent); outline-offset: 2px; }
.jigsaw-game:fullscreen { width: 100%; height: 100dvh; border: 0; border-radius: 0; }
@media (max-width: 700px) {
  .jigsaw-toolbar { gap: 3px; padding: 4px; }
  .jigsaw-game .jigsaw-title { margin-right: 3px; font-size: 13px; }
  .jigsaw-game .jg-button { min-width: 29px; width: 29px; height: 29px; padding: 5px; }
  .jigsaw-toolbar-divider { margin: 0 1px; }
  .jigsaw-body { flex-direction: column; }
  .jigsaw-tray { height: 139px; width: 100%; border-left: 0; border-top: 1px solid var(--jg-line); }
  .jigsaw-tray-head { height: 30px; }
  .jigsaw-tray-spacer { height: 100%; }
  .jigsaw-reference { width: 94px; padding: 6px; }
  .jigsaw-status { gap: 7px; padding-inline: 5px; font-size: 10px; }
  .jigsaw-dialog { padding: 12px; }
  .jigsaw-library-group > header { flex-wrap: wrap; }
  .jigsaw-library-group > header > div:first-child { flex-basis: 100%; }
  .jigsaw-library-group-actions { flex-wrap: wrap; }
  .jigsaw-library-grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 7px; }
  .jigsaw-library-caption { flex-wrap: wrap; padding: 6px; }
  .jigsaw-library-caption > span { flex-basis: 100%; }
  .jigsaw-library-thumbnail { height: 130px; }
  .jigsaw-library-top { gap: 5px; margin-bottom: 5px; font-size: 12px; }
  .jigsaw-library-tools { gap: 6px; }
  .jigsaw-library-note { margin-block: 5px 8px; }
}
@media (max-height: 500px) and (min-width: 500px) {
  .jigsaw-toolbar { padding-block: 2px; }
  .jigsaw-body { flex-direction: row; }
  .jigsaw-tray { width: 160px; height: auto; border-left: 1px solid var(--jg-line); border-top: 0; }
  .jigsaw-reference { width: 100px; }
  .jigsaw-preview { height: 130px; }
  .jigsaw-crop-area { height: 145px; }
  .jigsaw-dialog { padding: 8px 12px; }
  .jigsaw-dialog-head, .jigsaw-draft-controls { margin-bottom: 7px; }
  .jigsaw-dialog-actions { margin-top: 7px; }
  .jigsaw-library-dialog { overflow: auto; }
  .jigsaw-library-scroll { flex-shrink: 0; max-height: 160px; }
}
@media (prefers-reduced-motion: reduce) { .jigsaw-progress > span { transition: none; } }
