:root { color-scheme: light; --ink: #183f35; --green: #137c59; --gold: #f5b73e; }
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { color: var(--ink); font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif; background: radial-gradient(ellipse at top left, #dcf2d7, transparent 65%), #f3f7ef; }
button, select, a { font: inherit; -webkit-tap-highlight-color: transparent; }
button, a, label, select { touch-action: manipulation; }
button, a { color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid #e69b12; outline-offset: 2px; }
.page { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; height: 100vh; height: 100dvh; max-width: 1240px; margin: auto; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 38px; }
.home-link { display: inline-flex; align-items: center; min-height: 38px; text-decoration: none; font-size: 14px; font-weight: 800; }
h1 { margin: 0; font-size: clamp(20px, 3vw, 27px); letter-spacing: .05em; }
.photo-credit { font-size: 12px; color: #53685c; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.photo-credit[hidden] { display: none; }
.game-shell { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-height: 0; gap: 6px; }
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 8px 12px; }
.config-controls { display: flex; align-items: end; gap: 6px; min-width: 0; }
.config-field { display: grid; gap: 2px; color: #53685c; font-size: 11px; font-weight: 800; }
.config-field select { height: 38px; min-width: 72px; border: 1px solid #bdd5c5; border-radius: 10px; padding: 0 28px 0 9px; color: var(--ink); background: #fff; font-size: 14px; font-weight: 800; cursor: pointer; }
.config-field:first-child select { min-width: 112px; }
.stats { display: flex; gap: 12px; align-items: center; margin: 0; }
.stat { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.stat dt { font-size: 12px; color: #53685c; }
.stat dd { margin: 0; font-size: 22px; line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; }
.restart-btn, .again-btn { min-height: 40px; border: 0; border-radius: 11px; padding: 8px 14px; background: var(--green); color: #fff; font-size: 14px; font-weight: 800; white-space: nowrap; }
.restart-btn { background: #e2ebdc; color: var(--ink); }
.info-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 22px; }
.status { margin: 0; overflow: hidden; color: #466255; font-size: 13px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.progress { width: 94px; height: 6px; flex: 0 0 auto; overflow: hidden; border-radius: 20px; background: #dce8d8; }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .45s ease; }
.board-stage { min-height: 0; min-width: 0; display: grid; place-items: center; }
.board { --columns: 4; --rows: 4; --board-gap: clamp(4px, .8vmin, 9px); display: grid; grid-template-columns: repeat(var(--columns), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows), minmax(0, 1fr)); width: var(--board-width, 600px); height: var(--board-height, 600px); max-width: 100%; max-height: 100%; gap: var(--board-gap); padding: clamp(4px, .8vmin, 8px); border: 1px solid #c8ddcb; border-radius: clamp(12px, 2.5vmin, 20px); background: #e1eedc; }
.board[data-columns="6"], .board[data-rows="6"] { --board-gap: clamp(3px, .55vmin, 6px); }
.card { position: relative; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: clamp(6px, 1.6vmin, 13px); background: transparent; perspective: 900px; }
.card-inner { position: absolute; inset: 0; border-radius: inherit; transform-style: preserve-3d; transition: transform .3s cubic-bezier(.2,.75,.25,1); box-shadow: 0 3px 5px #17392b1c; }
.card.is-flipped .card-inner { transform: rotateY(180deg); }
.card-side { position: absolute; inset: 0; overflow: hidden; border: clamp(1px, .3vmin, 2px) solid #fff; border-radius: inherit; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.card-back { display: grid; place-items: center; color: #fff6d5; background: radial-gradient(circle at 15% 20%, #ffffff18 0 3%, transparent 4%), radial-gradient(circle at 80% 80%, #ffffff18 0 3%, transparent 4%), linear-gradient(145deg, #24916c, #106b50); }
.card-back::before { content: "?"; display: grid; place-items: center; width: 46%; aspect-ratio: 1; border-radius: 50%; border: 2px solid #ffffff58; background: #ffffff0d; font-size: clamp(18px, 4vmin, 44px); font-weight: 900; }
.card-front { background: #dfe6df; transform: rotateY(180deg); }
.card-media { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; object-position: center; background-color: #dfe6df; }
.sprite-media { background-repeat: no-repeat; background-size: 600% 300%; background-position: var(--sprite-x) var(--sprite-y); }
.card-label { position: absolute; z-index: 1; inset: auto 0 0; display: grid; place-items: end center; min-height: 34%; padding: clamp(15px, 4vmin, 30px) 3px 4px; color: #fff; background: linear-gradient(transparent, #07150ed9); text-align: center; text-shadow: 0 1px 3px #000; font-size: clamp(12px, 2.2vmin, 20px); font-weight: 900; line-height: 1.05; white-space: nowrap; }
.board[data-columns="6"] .card-label { font-size: clamp(10px, 1.75vmin, 15px); padding-bottom: 3px; }
.card.is-matching { z-index: 2; animation: match-pop .7s ease both; pointer-events: none; }
.card.is-matching::after { content: ""; position: absolute; inset: -3px; border: 3px solid #efbb45; border-radius: inherit; pointer-events: none; animation: match-ring .65s ease-out both; }
.card.is-matched { opacity: 0; visibility: hidden; pointer-events: none; }
@keyframes match-pop { 0% { transform: scale(1); } 25% { transform: scale(1.09) rotate(-2deg); filter: brightness(1.15); } 48% { transform: scale(.98) rotate(2deg); opacity: 1; } 100% { transform: scale(.65) translateY(-12px); opacity: 0; } }
@keyframes match-ring { 0% { transform: scale(.96); opacity: 1; } 100% { transform: scale(1.32); opacity: 0; } }
.effects { position: fixed; inset: 0; z-index: 30; pointer-events: none; overflow: hidden; }
.spark { position: absolute; width: 9px; height: 9px; background: var(--spark-color); border-radius: 2px; animation: sparkle .72s ease-out forwards; }
@keyframes sparkle { from { transform: translate(-50%, -50%) scale(.6) rotate(0); opacity: 1; } to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0) rotate(160deg); opacity: 0; } }
.result-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); background: #102c29a6; backdrop-filter: blur(6px); }
.result-overlay[hidden] { display: none; }
.result-card { position: relative; z-index: 1; width: min(410px, 100%); max-height: 100%; overflow: auto; border: 3px solid #fff; border-radius: 26px; padding: clamp(20px, 5vh, 40px) 24px; background: #fffdf5; box-shadow: 0 24px 80px #06201955; text-align: center; animation: victory-enter .6s cubic-bezier(.2,1.5,.4,1) both; }
.victory-stars { color: #e7a31b; font-size: clamp(26px, 7vh, 48px); letter-spacing: .1em; animation: stars-enter .8s .15s both; }
.result-card h2 { margin: 8px 0; font-size: clamp(28px, 8vh, 42px); }
.result-card p { margin: 8px 0 24px; font-size: 16px; line-height: 1.7; }
.result-card strong { display: block; margin-block: 4px; color: var(--green); font-size: 38px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.result-card span { display: block; }
.again-btn { min-width: 160px; }
#celebration { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 25; }
@keyframes victory-enter { from { opacity: 0; transform: translateY(24px) scale(.8); } to { opacity: 1; transform: none; } }
@keyframes stars-enter { from { opacity: 0; transform: scale(.2) rotate(-18deg); } 70% { transform: scale(1.15) rotate(4deg); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) {
  .page { gap: 5px; padding-inline: max(7px, env(safe-area-inset-left)) max(7px, env(safe-area-inset-right)); }
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 5px 8px; }
  .config-controls { grid-column: 1 / -1; }
  .config-field { flex: 1 1 0; }
  .config-field:first-child { flex-grow: 1.35; }
  .config-field select, .config-field:first-child select { width: 100%; min-width: 0; height: 36px; padding-left: 7px; }
  .stats { justify-content: flex-start; }
  .restart-btn { min-height: 36px; padding-block: 6px; }
  .game-shell { gap: 4px; }
  .progress { width: 60px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .page { grid-template-columns: 184px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 9px; }
  .topbar { grid-column: 1; grid-row: 1; align-self: start; flex-wrap: wrap; justify-content: flex-start; }
  h1 { order: 3; flex: 1 0 100%; font-size: 21px; }
  .home-link { flex: 1; }
  .game-shell { display: contents; }
  .toolbar { grid-column: 1; grid-row: 1; align-self: start; display: grid; grid-template-columns: 1fr auto; margin-top: 72px; gap: 6px; }
  .config-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; }
  .config-field:first-child { grid-column: 1 / -1; }
  .config-field select, .config-field:first-child select { width: 100%; height: 33px; min-width: 0; }
  .stats { gap: 9px; }
  .stat { gap: 3px; }
  .restart-btn { min-height: 34px; padding: 6px 9px; }
  .info-row { grid-column: 1; grid-row: 1; align-self: end; flex-direction: column; align-items: flex-start; gap: 5px; }
  .status { max-width: 184px; white-space: normal; }
  .board-stage { grid-column: 2; grid-row: 1; }
  .result-card { padding: 16px 24px; }
  .result-card p { margin-bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .effects, #celebration { display: none; }
}
