@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #07111f;
  --panel: rgba(14, 28, 46, .88);
  --panel-light: rgba(255, 255, 255, .055);
  --line: rgba(255, 255, 255, .09);
  --text: #f5f8ff;
  --muted: #8e9db2;
  --cyan: #31d9c5;
  --cyan-dark: #0cae9d;
  --violet: #8d72ff;
  --danger: #ffb454;
  --radius: 24px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow-x: hidden;
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  background: radial-gradient(circle at 10% 0%, #142d44 0, transparent 38%), linear-gradient(145deg, #07111f, #0a1423 48%, #090f1c);
}
button, input, select { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, label:has(input:focus-visible) { outline: 3px solid rgba(49, 217, 197, .45); outline-offset: 2px; }

.ambient { position: fixed; width: 420px; height: 420px; border-radius: 50%; filter: blur(110px); opacity: .13; pointer-events: none; }
.ambient-one { top: -160px; right: -80px; background: var(--cyan); }
.ambient-two { bottom: -240px; left: 18%; background: var(--violet); }
.page-shell { position: relative; z-index: 1; width: min(1480px, 100%); margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 72px; margin-bottom: 18px; }
.topbar p { margin: 0; color: var(--muted); font-size: .92rem; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-size: 1.35rem; font-weight: 500; letter-spacing: -.04em; }
.brand strong { font-weight: 800; }
.brand-mark { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 40px; height: 40px; transform: rotate(4deg); }
.brand-mark i { display: block; border-radius: 5px; background: linear-gradient(145deg, var(--cyan), var(--cyan-dark)); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { opacity: .6; }

.layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 18px; align-items: stretch; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(155deg, rgba(19, 37, 58, .93), var(--panel)); box-shadow: 0 28px 70px rgba(0, 0, 0, .27); backdrop-filter: blur(18px); }
.sidebar { min-width: 0; padding: 24px; }
.game-panel { min-width: 0; padding: 24px 28px 18px; }
.section-heading { display: flex; align-items: center; gap: 13px; }
.step { display: grid; flex: 0 0 auto; place-items: center; width: 36px; height: 36px; border: 1px solid rgba(49, 217, 197, .3); border-radius: 11px; color: var(--cyan); background: rgba(49, 217, 197, .09); font-weight: 800; }
.eyebrow { margin: 0 0 2px; color: var(--cyan); font-size: .68rem; line-height: 1; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
h1, h2 { margin: 0; font-size: clamp(1.25rem, 2vw, 1.65rem); line-height: 1.15; letter-spacing: -.035em; }

.upload-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 24px 0 22px; }
#camera-input, #gallery-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-button { display: flex; min-width: 0; min-height: 90px; padding: 14px 11px; flex-direction: column; justify-content: center; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 16px; text-align: center; cursor: pointer; background: var(--panel-light); transition: border-color .2s, transform .2s, background .2s; }
.upload-button:hover { transform: translateY(-2px); border-color: rgba(49, 217, 197, .35); background: rgba(49, 217, 197, .075); }
.upload-button span:last-child { display: grid; gap: 2px; }
.upload-button strong { font-size: .82rem; }
.upload-button small { color: var(--muted); font-size: .66rem; }
.button-icon { color: var(--cyan); font-size: 1.35rem; line-height: 1; }
.gallery-upload .button-icon { color: #a893ff; }
.divider { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; color: #72839a; font-size: .67rem; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.divider::before, .divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.searchbar { display: flex; align-items: center; gap: 8px; height: 46px; padding-left: 14px; border: 1px solid var(--line); border-radius: 13px; background: rgba(4, 13, 25, .4); }
.searchbar > span { color: var(--muted); font-size: 1.25rem; }
.searchbar input { width: 100%; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: .83rem; }
.searchbar input::placeholder { color: #68798f; }
.searchbar button { align-self: stretch; margin: 4px; padding: 0 11px; border: 0; border-radius: 9px; color: #bafaf1; background: rgba(49, 217, 197, .11); cursor: pointer; font-size: .7rem; font-weight: 700; }
.gallery-header { display: flex; justify-content: space-between; margin: 21px 2px 10px; color: var(--muted); font-size: .69rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; max-height: 430px; overflow: auto; scrollbar-width: thin; scrollbar-color: #30445c transparent; }
.gallery-item { position: relative; min-width: 0; height: 106px; overflow: hidden; padding: 0; border: 2px solid transparent; border-radius: 13px; color: white; background: #091321; cursor: pointer; transition: transform .18s, border-color .18s; }
.gallery-item:hover { transform: translateY(-2px); }
.gallery-item.active { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(49, 217, 197, .12); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .84; }
.gallery-item span { position: absolute; inset: auto 0 0; padding: 20px 8px 7px; overflow: hidden; text-align: left; color: white; background: linear-gradient(transparent, rgba(0, 0, 0, .82)); font-size: .7rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.empty-message { grid-column: 1 / -1; display: flex; min-height: 190px; padding: 20px; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 15px; }
.empty-message > span { display: grid; width: 38px; height: 38px; margin-bottom: 10px; place-items: center; border-radius: 50%; color: var(--cyan); background: rgba(49, 217, 197, .08); font-size: 1.3rem; }
.empty-message strong { color: var(--text); font-size: .82rem; }
.empty-message p { max-width: 240px; margin: 5px 0 0; font-size: .72rem; line-height: 1.5; }
.empty-message code { color: #b7c5d7; }
.loader { grid-column: 1 / -1; width: 30px; height: 30px; margin: 75px auto; border: 3px solid var(--line); border-top-color: var(--cyan); border-radius: 50%; animation: spin .8s linear infinite; }

.game-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.size-selector { display: grid; grid-template-columns: auto auto; align-items: center; gap: 9px; }
.size-selector label { color: var(--muted); font-size: .72rem; font-weight: 600; }
.size-selector select { max-width: 170px; height: 40px; padding: 0 30px 0 11px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: #15263a; font-size: .76rem; font-weight: 700; cursor: pointer; }
.selection-card { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; align-items: center; gap: 14px; margin: 22px 0 14px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, .035); }
.selected-image-preview { display: grid; width: 62px; height: 52px; place-items: center; overflow: hidden; border-radius: 10px; color: #62768e; background: #091421; }
.selected-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.selected-image-preview span { font-size: 1.25rem; }
.selected-image-meta { min-width: 0; }
.selected-image-meta small { display: block; margin-bottom: 2px; color: var(--muted); font-size: .62rem; text-transform: uppercase; letter-spacing: .07em; }
.selected-image-meta strong, .selected-image-meta p { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-image-meta strong { font-size: .84rem; }
.selected-image-meta p { margin: 3px 0 0; color: var(--muted); font-size: .68rem; }
.primary, .secondary { min-height: 42px; padding: 0 18px; border: 0; border-radius: 11px; cursor: pointer; font-size: .78rem; font-weight: 800; transition: filter .2s, transform .2s, opacity .2s; }
.primary { color: #041913; background: linear-gradient(135deg, #55ecd9, #28cbb9); box-shadow: 0 9px 24px rgba(49, 217, 197, .15); }
.secondary { color: var(--text); background: rgba(255, 255, 255, .08); }
.primary:hover:not(:disabled), .secondary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
button:disabled { opacity: .35; cursor: not-allowed; }
.status-bar { display: flex; justify-content: space-between; align-items: center; gap: 14px; min-height: 45px; margin-bottom: 14px; padding: 0 13px; border-radius: 12px; color: var(--muted); background: rgba(4, 13, 25, .34); font-size: .72rem; }
.status-bar > div { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #66788d; box-shadow: 0 0 0 4px rgba(102, 120, 141, .1); }
[data-status="playing"] .status-dot { background: var(--cyan); box-shadow: 0 0 0 4px rgba(49, 217, 197, .1); animation: pulse 1.5s infinite; }
[data-status="success"] .status-dot { background: #67e597; }
[data-status="warning"] .status-dot { background: var(--danger); }
.game-stats { font-variant-numeric: tabular-nums; }
.game-stats > span { padding-right: 10px; border-right: 1px solid var(--line); }
.icon-button { display: grid; width: 30px; height: 30px; padding: 0; place-items: center; border: 0; border-radius: 8px; color: var(--text); background: var(--panel-light); cursor: pointer; font-size: 1.1rem; }
.board-wrapper { display: grid; min-height: 490px; padding: 20px; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background-color: rgba(3, 10, 20, .5); background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px); background-size: 28px 28px; }
.empty-board { display: flex; max-width: 350px; flex-direction: column; align-items: center; text-align: center; color: var(--muted); }
.empty-board strong { color: #dfe8f5; font-size: .95rem; }
.empty-board p { margin: 7px 0 0; font-size: .74rem; line-height: 1.5; }
.empty-illustration { display: grid; grid-template-columns: repeat(2, 37px); grid-template-rows: repeat(2, 37px); gap: 4px; margin-bottom: 19px; transform: rotate(-4deg); }
.empty-illustration i { border: 1px dashed #40556d; border-radius: 8px; background: rgba(255, 255, 255, .025); }
.empty-illustration i:nth-child(2) { transform: translate(4px, -5px); border-color: rgba(49, 217, 197, .55); background: rgba(49, 217, 197, .08); }
.puzzle-board { --size: 3; width: min(100%, 640px); max-height: 65vh; display: grid; grid-template-columns: repeat(var(--size), 1fr); grid-template-rows: repeat(var(--size), 1fr); gap: 3px; overflow: hidden; border: 5px solid #172a3e; border-radius: 12px; background: #07111d; box-shadow: 0 22px 50px rgba(0, 0, 0, .4); transition: filter .35s, transform .35s; }
.puzzle-board.completed { filter: brightness(1.2); transform: scale(1.015); }
.tile { min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 3px; background-image: var(--image); background-repeat: no-repeat; background-size: calc(var(--size) * 100%) calc(var(--size) * 100%); cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,.13); transition: filter .13s, transform .13s; }
.tile:hover { filter: brightness(1.13); transform: scale(.975); }
.tile.empty { background: rgba(5, 15, 27, .94); box-shadow: inset 0 0 18px rgba(0,0,0,.5); cursor: default; }
.game-tip { margin: 11px 0 0; text-align: center; color: #64768d; font-size: .66rem; }

.dialog-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; padding: 20px; place-items: center; background: rgba(2, 8, 16, .78); backdrop-filter: blur(12px); }
.victory-card { width: min(420px, 100%); padding: 36px; border: 1px solid rgba(49, 217, 197, .25); border-radius: 24px; text-align: center; background: linear-gradient(155deg, #183249, #0d1b2c); box-shadow: 0 30px 90px #000; animation: pop .35s ease-out; }
.confetti { display: grid; width: 66px; height: 66px; margin: 0 auto 18px; place-items: center; border-radius: 50%; color: #071b17; background: var(--cyan); box-shadow: 0 0 50px rgba(49, 217, 197, .3); font-size: 1.7rem; }
.victory-card h2 { font-size: 2rem; }
.victory-card > p:not(.eyebrow) { margin: 12px 0 24px; color: var(--muted); font-size: .85rem; line-height: 1.6; }
.victory-actions { display: flex; justify-content: center; gap: 9px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .5; } }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(12px); } }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { padding-bottom: 20px; }
  .gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); max-height: 260px; }
  .board-wrapper { min-height: 440px; }
}

@media (max-width: 620px) {
  body { padding: 12px; }
  .topbar { min-height: 56px; }
  .topbar p { display: none; }
  .brand { font-size: 1.18rem; }
  .brand-mark { width: 34px; height: 34px; }
  .panel { border-radius: 19px; }
  .sidebar, .game-panel { padding: 18px 15px; }
  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gallery-item { height: 92px; }
  .game-header { align-items: flex-end; }
  .size-selector { grid-template-columns: 1fr; gap: 3px; }
  .size-selector select { max-width: 148px; }
  .selection-card { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 9px; }
  .selected-image-preview { width: 52px; height: 48px; }
  .selected-image-meta p, .selected-image-meta small { display: none; }
  .selection-card .primary { min-width: 66px; padding: 0 11px; }
  .status-bar { padding-left: 10px; }
  .status-bar #status-text { max-width: 115px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .board-wrapper { min-height: 330px; padding: 10px; }
  .puzzle-board { max-height: 58vh; gap: 2px; border-width: 3px; }
  .game-tip { line-height: 1.4; }
}

@media (max-width: 390px) {
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-header { flex-direction: column; align-items: stretch; }
  .size-selector { grid-template-columns: auto 1fr; }
  .size-selector select { width: 100%; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Selection page */
.selection-shell { max-width: 1240px; }
.selection-hero { max-width: 700px; margin: 30px auto 34px; text-align: center; }
.selection-hero h1 { margin: 5px 0 10px; font-size: clamp(2.15rem, 5vw, 4.1rem); letter-spacing: -.065em; }
.selection-hero > p:last-child { margin: 0; color: var(--muted); font-size: .95rem; }
.selection-layout { display: grid; grid-template-columns: minmax(320px, .92fr) minmax(430px, 1.08fr); gap: 18px; align-items: start; }
.choice-panel, .setup-panel { padding: 25px; }
.selection-gallery { max-height: 335px; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0 30px; }
.mode-card { position: relative; display: flex; min-width: 0; min-height: 142px; padding: 17px; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 13px; border: 1px solid var(--line); border-radius: 18px; color: var(--text); text-align: left; background: rgba(255,255,255,.028); cursor: pointer; transition: .2s ease; }
.mode-card:hover { transform: translateY(-2px); border-color: rgba(49,217,197,.28); }
.mode-card.active { border-color: var(--cyan); background: linear-gradient(145deg, rgba(49,217,197,.11), rgba(49,217,197,.035)); box-shadow: inset 0 0 0 1px rgba(49,217,197,.12); }
.mode-card > span:nth-child(2) { display: grid; gap: 3px; }
.mode-card strong { font-size: .88rem; }
.mode-card small { color: var(--muted); font-size: .68rem; line-height: 1.35; }
.mode-card > b { position: absolute; top: 12px; right: 12px; display: grid; width: 21px; height: 21px; place-items: center; border-radius: 50%; color: #06221c; background: var(--cyan); opacity: 0; font-size: .7rem; }
.mode-card.active > b { opacity: 1; }
.mode-visual { display: grid; width: 64px; height: 52px; gap: 2px; }
.slide-visual { grid-template-columns: repeat(3, 1fr); }
.mode-visual i { display: block; border-radius: 3px; background: linear-gradient(145deg, #465d78, #24394f); }
.slide-visual i:last-child { opacity: .12; }
.jigsaw-visual { grid-template-columns: repeat(2, 1fr); gap: 4px; }
.jigsaw-visual i { border-radius: 7px 11px 6px 10px; background: linear-gradient(145deg, #9278ff, #5948b5); }
.jigsaw-visual i:nth-child(2), .jigsaw-visual i:nth-child(3) { transform: translateX(2px); }
.difficulty-block { padding-top: 25px; border-top: 1px solid var(--line); }
.difficulty-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin: 18px 0 26px; }
.difficulty-options button { min-width: 0; min-height: 60px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: rgba(255,255,255,.025); cursor: pointer; }
.difficulty-options button strong, .difficulty-options button small { display: block; }
.difficulty-options button strong { font-size: .65rem; }
.difficulty-options button small { margin-top: 3px; color: var(--muted); font-size: .62rem; }
.difficulty-options button.active { border-color: var(--violet); background: rgba(141,114,255,.12); box-shadow: inset 0 0 0 1px rgba(141,114,255,.15); }
.selection-summary { display: grid; grid-template-columns: 66px minmax(0,1fr); align-items: center; gap: 13px; padding: 11px; border: 1px solid var(--line); border-radius: 15px; background: rgba(4,13,25,.36); }
.selection-status { min-height: 20px; margin: 12px 2px; color: var(--muted); font-size: .7rem; }
.selection-status.ready { color: var(--cyan); }
.start-selection { width: 100%; min-height: 52px; font-size: .86rem; }

/* Dedicated game page */
.game-page { min-height: 100vh; }
.game-shell { position: relative; z-index: 1; width: min(1180px, 100%); margin: 0 auto; }
.game-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 64px; margin-bottom: 15px; }
.compact-brand { justify-self: center; font-size: 1.1rem; }
.compact-brand .brand-mark { width: 31px; height: 31px; }
.back-link, .reference-button { color: var(--muted); font-size: .75rem; font-weight: 700; text-decoration: none; }
.back-link:hover { color: var(--text); }
.reference-button { justify-self: end; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--panel-light); cursor: pointer; }
.play-layout { padding: 21px 25px 26px; border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(155deg, rgba(19,37,58,.93), var(--panel)); box-shadow: 0 28px 70px rgba(0,0,0,.27); }
.play-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.play-heading h1 { max-width: 620px; overflow: hidden; font-size: clamp(1.35rem, 3vw, 2rem); text-overflow: ellipsis; white-space: nowrap; }
.play-heading .game-stats { display: flex; align-items: stretch; gap: 8px; }
.play-heading .game-stats > div { min-width: 78px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 11px; text-align: center; background: rgba(4,13,25,.3); }
.play-heading .game-stats small, .play-heading .game-stats strong { display: block; }
.play-heading .game-stats small { margin-bottom: 2px; color: var(--muted); font-size: .55rem; text-transform: uppercase; letter-spacing: .08em; }
.play-heading .game-stats strong { font-size: .82rem; font-variant-numeric: tabular-nums; }
.play-heading .icon-button { width: 42px; height: auto; }
.game-instructions { min-height: 20px; margin: 10px 0 14px; color: var(--muted); font-size: .72rem; }
.game-area { min-height: 560px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background-color: rgba(3,10,20,.5); background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px), linear-gradient(90deg,rgba(255,255,255,.018) 1px,transparent 1px); background-size: 28px 28px; }
.loading-game { display: flex; min-height: 500px; flex-direction: column; justify-content: center; align-items: center; gap: 15px; color: var(--muted); font-size: .8rem; }
.loading-game .loader { margin: 0; }
.loading-game a { color: var(--cyan); }
.game-area > .puzzle-board { --ratio: 1; width: min(100%, 650px); max-height: none; margin: 0 auto; aspect-ratio: var(--ratio); }
.game-area > .puzzle-board::after { content: ''; pointer-events: none; }

.jigsaw-game { width: 100%; }
.jigsaw-target-wrap { display: grid; min-height: 390px; padding: 30px; place-items: center; }
.jigsaw-target { --size: 3; position: relative; display: grid; grid-template-columns: repeat(var(--size),1fr); grid-template-rows: repeat(var(--size),1fr); width: min(100%, 650px); aspect-ratio: var(--ratio, 1); overflow: visible; background-repeat: no-repeat; background-size: 100% 100%; box-shadow: 0 18px 55px rgba(0,0,0,.42), inset 0 0 0 2px rgba(255,255,255,.12); }
.jigsaw-slot { min-width: 0; min-height: 0; padding: 0; border: 1px dashed rgba(255,255,255,.13); background: transparent; cursor: pointer; }
.jigsaw-slot.wrong { background: rgba(255,90,90,.22); animation: shake .25s linear; }
.tray-heading { display: flex; justify-content: space-between; margin: 8px 4px 9px; color: var(--muted); font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
.piece-tray { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 7px; min-height: 118px; max-height: 245px; padding: 13px; overflow-y: auto; border: 1px solid var(--line); border-radius: 15px; background: rgba(4,13,25,.5); }
.jigsaw-piece { display: block; width: 100%; height: auto; margin: auto; touch-action: none; cursor: grab; filter: drop-shadow(0 4px 5px rgba(0,0,0,.45)); transition: filter .15s, transform .15s; }
.jigsaw-piece:hover, .jigsaw-piece.selected { filter: drop-shadow(0 0 7px var(--cyan)); transform: scale(1.035); }
.jigsaw-piece.dragging { margin: 0; pointer-events: auto; cursor: grabbing; transform: scale(1.07); filter: drop-shadow(0 10px 12px rgba(0,0,0,.65)); }
.jigsaw-piece.placed { margin: 0; pointer-events: none; transform: none; filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); animation: snap .25s ease-out; }

.reference-card { position: relative; width: min(850px, 95vw); max-height: 88vh; padding: 10px; border: 1px solid var(--line); border-radius: 18px; background: #0d1b2c; box-shadow: 0 30px 90px #000; }
.reference-card img { display: block; width: 100%; max-height: calc(88vh - 20px); object-fit: contain; border-radius: 11px; }
.reference-card button { position: absolute; z-index: 2; top: 18px; right: 18px; display: grid; width: 38px; height: 38px; padding: 0; place-items: center; border: 0; border-radius: 50%; color: white; background: rgba(0,0,0,.65); cursor: pointer; font-size: 1.5rem; }
.link-button { display: inline-grid; place-items: center; text-decoration: none; }

@keyframes snap { 50% { filter: drop-shadow(0 0 14px var(--cyan)); transform: scale(1.08); } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

@media (max-width: 850px) {
  .selection-layout { grid-template-columns: 1fr; }
  .selection-gallery { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .game-area { min-height: 470px; }
  .jigsaw-target-wrap { min-height: 320px; }
}

@media (max-width: 620px) {
  .selection-hero { margin: 22px auto 25px; }
  .selection-hero h1 { font-size: 2.35rem; }
  .choice-panel, .setup-panel { padding: 18px 15px; }
  .selection-gallery { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .mode-card { min-height: 130px; padding: 13px; }
  .difficulty-options { grid-template-columns: repeat(3,1fr); }
  .game-topbar { grid-template-columns: 1fr 1fr; }
  .compact-brand { display: none; }
  .play-layout { padding: 17px 12px; border-radius: 19px; }
  .play-heading { align-items: flex-start; }
  .play-heading h1 { max-width: 42vw; }
  .play-heading .game-stats { gap: 4px; }
  .play-heading .game-stats > div { min-width: 55px; padding: 6px; }
  .play-heading .icon-button { width: 34px; }
  .game-instructions { line-height: 1.45; }
  .game-area { min-height: 390px; padding: 8px; }
  .jigsaw-target-wrap { min-height: 260px; padding: 24px 18px; }
  .piece-tray { grid-template-columns: repeat(auto-fill,minmax(64px,1fr)); max-height: 260px; padding: 8px; }
}

@media (max-width: 390px) {
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 105px; flex-direction: row; align-items: center; }
  .mode-card > span:nth-child(2) { flex: 1; }
  .play-heading { flex-direction: column; }
  .play-heading h1 { max-width: 85vw; }
  .play-heading .game-stats { align-self: stretch; }
  .play-heading .game-stats > div { flex: 1; }
}
