:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --ink: #293e38;
  --muted: #596a63;
  --sage: #c6d9cd;
  --sage-deep: #3b6653;
  --line: #d7ded5;
  --face: #fffdf7;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; -webkit-font-smoothing: antialiased; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
button:focus-visible, a:focus-visible { outline: 3px solid #9a592e; outline-offset: 4px; }
a { color: inherit; }
[hidden] { display: none !important; }
.shell { min-height: 100svh; max-width: 980px; margin: auto; padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.tools { display: flex; gap: 8px; }
.tool-button { background: transparent; border: 1px solid var(--line); min-height: 44px; border-radius: 24px; }
.tool-button:hover { background: #eaf0e9; }
.sound-button { width: 44px; display: grid; place-items: center; flex: 0 0 auto; }
.sound-button svg { width: 21px; height: 21px; }
.help-button { padding: 8px 15px; font-size: .875rem; font-weight: 600; }
.sound-off, #sound[aria-pressed="false"] .sound-waves { display: none; }
#sound[aria-pressed="false"] .sound-off { display: initial; }
.game-layout { width: 100%; max-width: clamp(280px, calc((100svh - 360px) * .8), 440px); margin: 12px auto 6px; }
.heading { text-align: center; margin-bottom: 12px; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .16em; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 6vw, 2.25rem); font-weight: 500; letter-spacing: -.045em; line-height: 1.14; margin: 0; }
h1 span { color: var(--sage-deep); }
.scoreboard { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); text-align: center; gap: 8px 0; margin: 0 0 12px; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat-label { color: var(--muted); font-size: .875rem; }
.stat p { margin: 2px 0 0; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat strong { font-size: 1.5rem; font-weight: 650; }
.stat-total { font-size: 1rem; color: var(--muted); }
progress { grid-column: 1 / -1; height: 4px; width: 100%; overflow: hidden; border: 0; border-radius: 8px; background: #e0e6dc; color: var(--sage-deep); }
progress::-webkit-progress-bar { background: #e0e6dc; }
progress::-webkit-progress-value { background: var(--sage-deep); border-radius: 8px; transition: width .3s; }
progress::-moz-progress-bar { background: var(--sage-deep); }
.play-area { position: relative; }
.board { display: grid; grid-template-columns: repeat(var(--columns, 4), minmax(0, 1fr)); gap: 10px; perspective: 1200px; }
.card { display: block; padding: 0; border: 0; width: 100%; aspect-ratio: 1; background: transparent; border-radius: 13px; user-select: none; position: relative; }
.card:disabled { opacity: 1; cursor: default; }
.board[data-phase="preview"] .card-inner, .board[data-phase="shuffling"] .card-inner { transition: none; }
.board[data-phase="shuffling"] .card { will-change: transform; }
.card:focus-visible { outline-offset: 3px; z-index: 1; }
.card-inner { display: block; width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform .32s cubic-bezier(.2,.6,.3,1); }
.card.is-flipped .card-inner, .card.is-matched .card-inner { transform: rotateY(180deg); }
.card-back, .card-face { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 13px; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.card-back { background: var(--sage); border: 1px solid #b3c9bc; box-shadow: 0 3px 0 #a9c0b1; }
.card-back::before { content: ""; position: absolute; inset: 7px; border: 1px solid #f8fff6a6; border-radius: 8px; }
.card-back svg { color: #527662; width: 35%; height: 35%; }
.card-face { background: var(--face); transform: rotateY(180deg); box-shadow: 0 3px 0 #d7ddd1; }
.card-face img { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 13px; }
.card.is-matched { cursor: default; }
.card.is-matched .card-face { background: #e8eee0; outline: 2px solid #74916b; outline-offset: -2px; box-shadow: 0 2px 0 #b7c7ad; }
.match-tick { position: absolute; bottom: -3px; right: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--sage-deep); color: #fff; font: 700 12px/18px "Segoe UI", sans-serif; text-align: center; opacity: 0; }
.card.is-matched .match-tick { opacity: 1; }
@media (hover: hover) {
  .card:not(.is-flipped):not(.is-matched):not(:disabled):hover .card-back { background: #d6e3d7; border-color: #72947e; }
}
.loading { position: absolute; inset: 0 0 auto; min-height: 180px; text-align: center; z-index: 2; background: var(--paper); padding: 32px 16px; border-radius: 13px; }
.loading p { line-height: 1.6; }
.board[aria-busy="true"] { min-height: 240px; opacity: .4; }
.board-message { min-height: 2.7em; display: grid; place-items: center; text-align: center; font-size: .875rem; line-height: 1.35; margin: 12px 0 8px; }
.round-controls { text-align: center; }
.new-game { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #b7c5b9; border-radius: 24px; background: transparent; padding: 10px 24px; font-size: .875rem; font-weight: 650; }
.new-game svg { width: 18px; height: 18px; }
.new-game:hover { background: #eaf0e9; }
.save-note { font-size: .75rem; color: var(--muted); margin: 10px 0 0; line-height: 1.5; }
.footer { margin-top: auto; padding-top: 8px; }
.footer nav, .dialog-legal { display: flex; justify-content: center; gap: 20px; color: var(--muted); font-size: .75rem; }
.footer a, .dialog-legal a { padding: 4px 0; text-decoration: none; }
.footer a:hover, .dialog-legal a:hover { text-decoration: underline; }
dialog { border: 1px solid #d0d9cb; width: min(410px, calc(100% - 32px)); max-height: calc(100svh - 32px); border-radius: 24px; padding: 0; color: var(--ink); background: var(--paper); box-shadow: 0 24px 80px #263e383b; }
dialog::backdrop { background: #233b3866; backdrop-filter: blur(5px); }
.dialog-content { text-align: center; padding: 30px 28px 18px; }
.dialog-content h2 { font: 500 2rem/1.12 Georgia, serif; letter-spacing: -.03em; margin: 10px 0 16px; }
#dialog-text { margin: 0; font-size: 1rem; line-height: 1.65; }
.dialog-note { color: var(--muted); font-size: .875rem; line-height: 1.6; margin: 15px 0 0; }
.dialog-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
.primary, .secondary { padding: 12px 18px; min-height: 48px; border-radius: 14px; font-size: 1rem; font-weight: 650; }
.primary { border: 1px solid var(--sage-deep); background: var(--sage-deep); color: #fffdf7; }
.primary:hover { background: #2d5141; }
.start-game { min-height: 44px; padding: 10px 26px; border-radius: 24px; font-size: .875rem; }
.start-game:disabled { opacity: 1; background: #dce6d9; color: var(--muted); border-color: #dce6d9; cursor: default; }
.secondary { border: 1px solid #bac9bc; background: transparent; }
.secondary:hover { background: #eaf0e9; }
.dialog-legal { margin-top: 19px; }
.celebration { display: flex; align-items: center; justify-content: center; gap: 20px; height: 76px; margin-bottom: 8px; color: #9a592e; }
.celebration span { font-size: 2.2rem; animation: celebrate .7s ease-out both; }
.celebration span:nth-child(2) { font-size: 4rem; animation-delay: .08s; color: var(--sage-deep); }
.celebration span:nth-child(3) { animation-delay: .16s; }
@keyframes celebrate { from { opacity: 0; transform: translateY(15px) scale(.65) rotate(-20deg); } to { opacity: 1; transform: none; } }
.noscript { position: fixed; inset: auto 0 0; background: var(--paper); padding: 20px; text-align: center; z-index: 10; }
@media (max-width: 400px) {
  .shell { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar { gap: 6px; }
  .tools { gap: 6px; }
  .help-button { padding: 8px 10px; }
  .game-layout { margin-top: 12px; }
  .board { gap: 8px; }
  .card, .card-back, .card-face, .card-face img { border-radius: 10px; }
  .card-back::before { inset: 5px; border-radius: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .card-inner, .card.is-flipped .card-inner, .card.is-matched .card-inner, .card-face { transform: none; }
  .card-face { visibility: hidden; }
  .card.is-flipped .card-face, .card.is-matched .card-face { visibility: visible; }
  .card.is-flipped .card-back, .card.is-matched .card-back { visibility: hidden; }
}
@media (forced-colors: active) {
  .card-back, .card-face { border: 2px solid ButtonText; }
  .card.is-matched .card-face { outline: 3px solid Highlight; }
  .match-tick { forced-color-adjust: none; }
}
