:root{
  color-scheme:dark;
  --bg:#090b10;
  --panel:#121722;
  --panel-2:#0e131c;
  --line:#293244;
  --text:#eef4ff;
  --muted:#9eabc0;
  --accent:#59e0c7;
  --accent-2:#8b7cff;
  --good:#7cf39c;
  --warn:#ffd36b;
  --card-gap:10px;
  --board-cols:4;
  --board-rows:4;
  --flip-ms:360ms;
  --shadow:0 18px 50px rgba(0,0,0,.38);
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;background:var(--bg);color:var(--text)}
body{
  min-height:100dvh;
  overflow-x:hidden;
  background:
    radial-gradient(circle at 15% 10%,rgba(89,224,199,.10),transparent 30rem),
    radial-gradient(circle at 85% 0%,rgba(139,124,255,.12),transparent 34rem),
    linear-gradient(180deg,#0a0d14,#080a0f 62%,#05070a);
}
button,select,a{font:inherit}
button,select{color:inherit}
button{cursor:pointer}
button:focus-visible,a:focus-visible,select:focus-visible{outline:3px solid var(--accent);outline-offset:3px}
[hidden]{display:none!important}

.app-shell{min-height:100dvh;display:flex;flex-direction:column}
.game-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
  padding:14px clamp(14px,3vw,34px);
  border-bottom:1px solid rgba(255,255,255,.08);
  background:rgba(8,11,16,.82);
  backdrop-filter:blur(14px);
  position:relative;
  z-index:20;
}
.brand{display:flex;align-items:center;gap:12px;color:inherit;text-decoration:none;min-width:0}
.brand-mark{width:42px;height:42px;filter:drop-shadow(0 0 18px rgba(89,224,199,.22))}
.brand span{display:grid;gap:1px}
.brand strong{font-size:clamp(1rem,2.5vw,1.35rem);letter-spacing:.12em}
.brand small{color:var(--muted);font-size:.76rem}
.header-actions{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.icon-btn,.difficulty,.primary-btn,.secondary-btn{
  border:1px solid var(--line);
  background:#141a26;
  color:var(--text);
  border-radius:12px;
  min-height:42px;
  padding:9px 13px;
  transition:transform .18s ease,border-color .18s ease,background .18s ease;
}
.icon-btn:hover,.difficulty:hover,.secondary-btn:hover{border-color:#4a5b78;background:#182131}
.icon-btn:active,.difficulty:active,.primary-btn:active{transform:translateY(1px)}

.game-main{
  width:min(1180px,100%);
  margin:0 auto;
  padding:14px clamp(10px,2vw,22px) 18px;
  flex:1;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.control-panel{
  display:flex;
  align-items:stretch;
  justify-content:space-between;
  gap:10px;
}
.difficulty-group{display:grid;grid-template-columns:repeat(3,minmax(110px,1fr));gap:8px;flex:1}
.difficulty{display:grid;text-align:left;gap:2px;padding:9px 12px}
.difficulty span{font-weight:800}
.difficulty small{font-size:.69rem;color:var(--muted)}
.difficulty.active{border-color:var(--accent);background:linear-gradient(135deg,rgba(89,224,199,.15),rgba(139,124,255,.12))}
.difficulty.active small{color:#d6fff7}
.deck-control{
  display:grid;
  grid-template-columns:repeat(2,auto);
  gap:6px;
  align-items:stretch;
}
.deck-button{
  border:1px solid var(--line);
  background:#141a26;
  color:var(--muted);
  border-radius:12px;
  min-height:42px;
  padding:8px 11px;
  font-size:.72rem;
  font-weight:900;
  letter-spacing:.05em;
}
.deck-button.active{
  color:#07100f;
  border-color:var(--accent);
  background:linear-gradient(135deg,#53d7c0,#8375ef);
}
.deck-button:hover{border-color:#4a5b78}
.gfx-control{
  width:188px;
  display:grid;
  grid-template-columns:auto 1fr;
  align-items:center;
  gap:4px 8px;
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#111722;
}
.gfx-control label{font-size:.72rem;font-weight:800;letter-spacing:.1em;color:var(--muted)}
.gfx-control select{min-width:0;background:#0c111a;border:1px solid #344159;border-radius:8px;padding:6px}
.gfx-control small{grid-column:1/-1;color:var(--muted);font-size:.68rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.stats{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:8px;
}
.stats>div{
  border:1px solid rgba(255,255,255,.08);
  border-radius:12px;
  background:rgba(17,23,34,.85);
  padding:8px 11px;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:8px;
}
.stats small{color:var(--muted);font-size:.72rem;text-transform:uppercase;letter-spacing:.08em}
.stats strong{font-size:1rem}

.board-wrap{
  position:relative;
  flex:1;
  min-height:0;
  display:flex;
  justify-content:center;
  align-items:center;
}
.board{
  width:min(100%,1050px);
  height:min(68dvh,700px);
  min-height:410px;
  display:grid;
  grid-template-columns:repeat(var(--board-cols),minmax(0,1fr));
  grid-template-rows:repeat(var(--board-rows),minmax(0,1fr));
  gap:var(--card-gap);
  perspective:1200px;
  padding:2px;
}
.memory-card{
  position:relative;
  min-width:0;
  min-height:0;
  padding:0;
  border:0;
  border-radius:15px;
  background:transparent;
  perspective:900px;
  touch-action:manipulation;
}
.card-inner{
  position:absolute;
  inset:0;
  border-radius:inherit;
  transform-style:preserve-3d;
  transition:transform var(--flip-ms) cubic-bezier(.2,.75,.2,1);
  box-shadow:0 8px 22px rgba(0,0,0,.28);
}
.memory-card.flipped .card-inner,
.memory-card.matched .card-inner{transform:rotateY(180deg)}
.card-face{
  position:absolute;
  inset:0;
  border-radius:inherit;
  overflow:hidden;
  backface-visibility:hidden;
  -webkit-backface-visibility:hidden;
}
.card-back{
  display:grid;
  place-items:center;
  background:
    linear-gradient(145deg,rgba(89,224,199,.15),rgba(139,124,255,.16)),
    repeating-linear-gradient(45deg,rgba(255,255,255,.025) 0 8px,transparent 8px 16px),
    #111725;
  border:1px solid #354158;
}
.card-back::after{
  content:"";
  width:min(48%,64px);
  aspect-ratio:1;
  background:url("/assets/d4-mark.svg") center/contain no-repeat;
  opacity:.82;
  filter:drop-shadow(0 0 16px rgba(89,224,199,.32));
}
body[data-deck="kids"] .card-back{
  background:
    radial-gradient(circle at 28% 22%,rgba(255,255,255,.12),transparent 28%),
    linear-gradient(145deg,#355ed8,#8a4fd6 56%,#ed7c74);
  border-color:rgba(255,255,255,.18);
}
body[data-deck="kids"] .card-back::after{
  content:"★";
  width:auto;
  aspect-ratio:auto;
  background:none;
  font-size:clamp(1.7rem,6vw,3.4rem);
  line-height:1;
  color:#fff4a8;
  opacity:1;
  filter:drop-shadow(0 3px 8px rgba(0,0,0,.28));
}
.card-front{
  transform:rotateY(180deg);
  border:1px solid rgba(255,255,255,.12);
  background:#161c27;
}
.card-front img{width:100%;height:100%;display:block;object-fit:cover;background:#111722}
.card-front.kid-card{
  display:grid;
  place-items:center;
  background:linear-gradient(145deg,#fff6c7,#ffd9e8 48%,#cdeeff);
}
.kid-icon{
  display:block;
  font-size:clamp(2rem,8vw,5rem);
  line-height:1;
  transform:translateY(-4%);
  filter:drop-shadow(0 4px 3px rgba(0,0,0,.14));
}
.card-front .card-label{
  position:absolute;
  left:0;right:0;bottom:0;
  padding:14px 7px 6px;
  font-size:clamp(.54rem,1.25vw,.72rem);
  font-weight:800;
  line-height:1.05;
  text-align:center;
  color:#fff;
  background:linear-gradient(transparent,rgba(0,0,0,.84));
  text-shadow:0 1px 2px #000;
}
.card-front.image-failed img{display:none}
.card-front.image-failed{
  display:grid;
  place-items:center;
  padding:10px;
  background:linear-gradient(135deg,#182231,#222943);
}
.card-front.image-failed::before{content:"D4";font-size:clamp(1rem,5vw,2.4rem);font-weight:950;letter-spacing:.08em;color:var(--accent)}
.memory-card:not(.flipped):not(.matched):hover .card-inner{transform:translateY(-3px) rotateX(1deg)}
.memory-card.matched{pointer-events:none}
.memory-card.matched .card-inner{
  box-shadow:0 0 0 2px rgba(124,243,156,.85),0 0 28px rgba(124,243,156,.30),0 10px 24px rgba(0,0,0,.35);
}
.memory-card.matched::after{
  content:"✓";
  position:absolute;
  z-index:6;
  top:6px;right:6px;
  width:24px;height:24px;
  display:grid;place-items:center;
  border-radius:50%;
  background:var(--good);
  color:#07120a;
  font-weight:950;
  box-shadow:0 3px 10px rgba(0,0,0,.3);
}
.memory-card.bad-match .card-inner{animation:nudge .26s ease}
@keyframes nudge{25%{transform:rotateY(180deg) translateX(-4px)}75%{transform:rotateY(180deg) translateX(4px)}}
@keyframes matchedPulse{50%{transform:scale(1.035)}}
.memory-card.just-matched{animation:matchedPulse .36s ease}

.status-line{
  margin:0;
  min-height:24px;
  text-align:center;
  color:var(--muted);
  font-size:.82rem;
}
.game-footer{
  display:flex;
  justify-content:space-between;
  gap:16px;
  padding:10px clamp(14px,3vw,34px);
  color:#79869a;
  font-size:.7rem;
  border-top:1px solid rgba(255,255,255,.06);
}

.round-overlay{
  position:absolute;
  inset:-8px;
  z-index:30;
  display:grid;
  place-items:center;
  background:rgba(5,7,11,.78);
  backdrop-filter:blur(10px);
  border-radius:18px;
}
.result-card{
  width:min(430px,92%);
  border:1px solid #39465d;
  background:linear-gradient(160deg,#151d2a,#0d121b);
  border-radius:24px;
  padding:24px;
  text-align:center;
  box-shadow:var(--shadow);
}
.result-kid-icon{
  display:none;
  width:84px;height:84px;
  align-items:center;
  justify-content:center;
  margin:0 auto;
  border-radius:50%;
  font-size:3.5rem;
  background:linear-gradient(145deg,#fff6c7,#ffd9e8 48%,#cdeeff);
  border:2px solid var(--accent);
}
body[data-deck="kids"] .result-kid-icon{display:flex}
body[data-deck="kids"] .result-mouse{display:none}
.result-mouse{
  width:84px;height:84px;
  object-fit:cover;
  border-radius:50%;
  border:2px solid var(--accent);
  background:#111722;
  box-shadow:0 0 34px rgba(89,224,199,.18);
}
.eyebrow{color:var(--accent);font-size:.72rem;letter-spacing:.16em;font-weight:900;margin:12px 0 4px}
.result-card h1{margin:0 0 8px;font-size:clamp(1.7rem,6vw,2.6rem)}
.result-card p{color:var(--muted);margin:0 auto 12px;line-height:1.5}
.stars{font-size:2rem;letter-spacing:.2em;color:var(--warn);min-height:42px}
.result-actions{display:flex;gap:8px;justify-content:center;margin-top:12px}
.primary-btn{background:linear-gradient(135deg,#53d7c0,#8375ef);color:#07100f;border:0;font-weight:900}
.secondary-btn{text-decoration:none;display:inline-flex;align-items:center;justify-content:center}

.particle{
  position:fixed;
  width:8px;height:8px;
  border-radius:2px;
  pointer-events:none;
  z-index:100;
  background:currentColor;
  animation:particleFly .72s ease-out forwards;
}
@keyframes particleFly{
  from{transform:translate3d(0,0,0) rotate(0);opacity:1}
  to{transform:translate3d(var(--dx),var(--dy),0) rotate(260deg);opacity:0}
}

body[data-gfx="high"] .card-back{box-shadow:inset 0 0 28px rgba(89,224,199,.05)}
body[data-gfx="high"] .memory-card.matched .card-inner{animation:glow 1.5s ease-in-out infinite alternate}
@keyframes glow{to{box-shadow:0 0 0 2px rgba(124,243,156,.9),0 0 34px rgba(124,243,156,.38),0 10px 24px rgba(0,0,0,.35)}}
body[data-gfx="low"]{
  background:#090b10;
}
body[data-gfx="low"] .game-header{backdrop-filter:none;background:#0b0e14}
body[data-gfx="low"] .round-overlay{backdrop-filter:none;background:rgba(5,7,11,.92)}
body[data-gfx="low"] .card-inner{box-shadow:0 4px 10px rgba(0,0,0,.28)}
body[data-gfx="low"] .memory-card:not(.flipped):not(.matched):hover .card-inner{transform:none}
body[data-gfx="low"] .memory-card.matched .card-inner{box-shadow:0 0 0 2px rgba(124,243,156,.72)}
body[data-gfx="low"] .memory-card.just-matched,
body[data-gfx="low"] .memory-card.bad-match .card-inner{animation:none}
body[data-gfx="low"] .card-back::after{filter:none}
body[data-gfx="low"] .kid-icon{filter:none}
body[data-gfx="low"] .result-mouse{box-shadow:none}
body[data-gfx="low"] .particle{display:none}

@media (orientation:portrait) and (max-width:700px){
  .game-header{padding:9px 10px;gap:8px}
  .brand-mark{width:34px;height:34px}
  .brand small{display:none}
  .brand strong{font-size:.92rem}
  .header-actions{gap:5px}
  .icon-btn{padding:7px 9px;min-height:36px;font-size:.75rem}
  .game-main{padding:8px 7px 9px;gap:7px}
  .control-panel{display:grid;grid-template-columns:1fr auto;gap:6px}
  .difficulty-group{grid-column:1/-1;gap:5px}
  .deck-control{grid-template-columns:repeat(2,1fr);gap:5px}
  .deck-button{min-height:34px;padding:5px 7px;border-radius:9px;font-size:.62rem}
  .difficulty{min-height:46px;min-width:0;padding:6px 7px;border-radius:9px}
  .difficulty span{font-size:.78rem}
  .difficulty small{font-size:.56rem;white-space:nowrap}
  .gfx-control{width:128px;padding:5px 7px;border-radius:9px}
  .gfx-control label{display:none}
  .gfx-control select{grid-column:1/-1;padding:5px;font-size:.72rem}
  .gfx-control small{font-size:.58rem}
  .stats{gap:5px}
  .stats>div{padding:5px 6px;border-radius:8px;display:grid;gap:0;text-align:center}
  .stats small{font-size:.56rem}
  .stats strong{font-size:.82rem}
  .board{
    height:calc(100dvh - 266px);
    min-height:390px;
    max-height:690px;
    gap:5px;
  }
  .memory-card{border-radius:9px}
  .memory-card.matched::after{width:17px;height:17px;top:3px;right:3px;font-size:.65rem}
  .card-front .card-label{font-size:.5rem;padding:10px 3px 4px}
  .status-line{font-size:.7rem;min-height:18px}
  .game-footer{display:none}
}
@media (orientation:landscape) and (max-height:650px){
  html,body,.app-shell{height:100dvh;min-height:0;overflow:hidden}
  .game-header{padding:5px 10px;gap:8px;flex:0 0 auto}
  .brand-mark{width:28px;height:28px}
  .brand strong{font-size:.84rem}
  .brand small{display:none}
  .header-actions{gap:5px}
  .header-actions .icon-btn{min-height:30px;padding:4px 8px;font-size:.68rem;border-radius:9px}
  .game-main{padding:5px 8px 6px;gap:4px;min-height:0;overflow:hidden}
  .control-panel{gap:6px;flex:0 0 auto}
  .difficulty-group{gap:5px}
  .deck-control{gap:4px}
  .deck-button{min-height:32px;padding:4px 7px;border-radius:8px;font-size:.58rem}
  .difficulty{min-height:34px;padding:4px 7px;border-radius:8px}
  .difficulty span{font-size:.73rem}
  .difficulty small{display:none}
  .gfx-control{width:138px;padding:3px 6px;border-radius:8px}
  .gfx-control label,.gfx-control small{display:none}
  .gfx-control select{grid-column:1/-1;padding:4px 6px;font-size:.7rem}
  .stats{
    position:static;
    transform:none;
    width:100%;
    pointer-events:auto;
    grid-template-columns:repeat(4,1fr);
    gap:5px;
    flex:0 0 auto
  }
  .stats>div{padding:3px 7px;min-height:29px;background:rgba(10,14,21,.86);border-radius:7px}
  .stats small{font-size:.51rem}
  .stats strong{font-size:.73rem}
  .board-wrap{min-height:0;align-items:stretch}
  .board{height:100%;min-height:0;max-height:none;width:min(100%,1180px);gap:5px}
  .memory-card{border-radius:8px}
  .card-front .card-label{font-size:.48rem;padding:8px 3px 3px}
  .memory-card.matched::after{width:16px;height:16px;top:3px;right:3px;font-size:.62rem}
  .status-line{font-size:.61rem;line-height:1.1;min-height:13px;flex:0 0 auto}
  .game-footer{display:none}
}
@media (max-width:430px){
  .header-actions #sound-btn{display:none}
  .difficulty-group{grid-template-columns:repeat(3,1fr)}
  .difficulty small{font-size:.52rem}
}
@media (prefers-reduced-motion:reduce){
  :root{--flip-ms:1ms}
  *,*::before,*::after{scroll-behavior:auto!important;animation-duration:1ms!important;animation-iteration-count:1!important;transition-duration:1ms!important}
}
