:root{
  --gap:14px;
  --tile-size:96px;
  --cols:6;
  --anim-fast: 180ms;
  --anim-med: 420ms;
  --anim-ease: cubic-bezier(.2,.9,.25,1);
  --bg-1: #f6f7fb;
  --bg-2: #eef2ff;
  --card-bg: #ffffffdd;
  --muted: #6b7280;
  --accent: #7c5cff;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  margin:0;min-height:100%;background:linear-gradient(180deg,var(--bg-1) 0%, var(--bg-2) 100%);color:#0f172a;display:flex;align-items:center;justify-content:center;padding:28px;
}
main{
  width:100%;max-width:980px;margin:0 auto;padding:28px;border-radius:16px;background:var(--card-bg);box-shadow:0 10px 30px rgba(13,20,30,0.08);
  display:flex;flex-direction:column;align-items:center;gap:18px;text-align:center
}
.h1-inline{display:inline-flex}
h1{margin:0;font-family:Poppins, Inter, sans-serif;font-weight:600;font-size:28px;color:#0b1220;display:inline-flex;align-items:center;gap:10px}
/* Title row grid: left slot, centered title, right slot. Keeps title centered while slots change. */
.title-row{display:grid;grid-template-columns:160px 1fr 160px;align-items:center;width:100%;max-width:980px}
.title-slot{min-height:44px;display:flex;align-items:center;justify-content:center}
.title-slot .encouragement-inline{opacity:0;transform:translateY(-4px);transition:opacity .22s ease,transform .22s ease}
.title-slot .encouragement-inline.show{opacity:1;transform:translateY(0)}
.title-left{text-align:left}
.title-right{text-align:right}
.controls{width:100%;max-width:920px;display:flex;justify-content:space-between;align-items:center;margin-top:14px}
.footer-controls{margin-top:18px}
.status{color:var(--muted);font-size:15px;padding:6px 10px;border-radius:8px;text-align:left}
.board-wrapper{width:100%;display:flex;justify-content:center}
.board{display:grid;grid-template-columns:repeat(var(--cols), var(--tile-size));gap:var(--gap);justify-content:center;width:100%;max-width:840px}
.tile{width:var(--tile-size);height:var(--tile-size);padding:0;border-radius:12px;border:0;background:linear-gradient(180deg,#ffffff, #fbfbff);cursor:pointer;position:relative;overflow:hidden;display:inline-flex;align-items:center;justify-content:center;font-size:28px;user-select:none;box-shadow:0 6px 18px rgba(12,18,30,0.06);transition:transform .18s ease,box-shadow .18s ease}
.tile:hover{transform:translateY(-4px);box-shadow:0 12px 26px rgba(12,18,30,0.09)}
.tile:active{transform:translateY(-1px)}
.tile:focus{outline:2px solid #dbeafe;box-shadow:0 0 0 4px rgba(124,92,255,0.12)}
.tile .back{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:linear-gradient(180deg,#7c5cff,#5a39ff);color:#fff;font-size:26px;transform:scaleY(1);transition:transform .18s;border-radius:12px}
.tile .front{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;transform:translateY(100%);transition:transform .24s;border-radius:12px}
.tile.revealed .back{transform:translateY(-100%)}
.tile.revealed .front{transform:translateY(0)}
.tile.removed{opacity:0;transform:scale(.9);pointer-events:none;transition:opacity var(--anim-fast) ease,transform var(--anim-fast) ease}
.tile.enter{animation:tileIn var(--anim-med) var(--anim-ease) both}
@keyframes tileIn{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
/* Make front images fill the tile and remove white padding */
.tile .front img{width:100%;height:100%;object-fit:cover;display:block;border-radius:12px}
.tile .front img, .tile .back{border-radius:12px}
@media (max-width:740px){
  :root{--tile-size:72px}
  .board{grid-template-columns:repeat(var(--cols), var(--tile-size))}
}

/* Wiggle animation for matched tiles */
.tile.wiggle{animation:wiggle var(--anim-med) var(--anim-ease)}
@keyframes wiggle{
  0%{transform:translateY(0) rotate(0)}
  25%{transform:translateY(-8px) rotate(-3deg)}
  50%{transform:translateY(0) rotate(3deg)}
  75%{transform:translateY(-6px) rotate(-1deg)}
  100%{transform:translateY(0) rotate(0)}
}

/* Loader shown while image is loading */
.tile .loader{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:28px;height:28px;border-radius:50%;box-sizing:border-box;border:3px solid rgba(255,255,255,0.85);border-top-color:rgba(11,17,34,0.18);animation:spin .9s linear infinite;z-index:3}
.tile.loading{filter:grayscale(.02) blur(.2px);opacity:.96;transition:filter var(--anim-fast) ease,opacity var(--anim-fast) ease}
.tile .front img{transition:opacity .24s ease}
.tile.loaded .front img{opacity:1}

.controls #resetBtn{background:#fff;border:0;padding:8px 14px;border-radius:10px;box-shadow:0 6px 16px rgba(12,18,30,0.06);cursor:pointer;font-weight:600}
.controls #resetBtn:hover{transform:translateY(-2px)}

.footer-note{font-size:13px;color:var(--muted);margin-top:6px}

@keyframes spin{to{transform:translate(-50%,-50%) rotate(360deg)}}

/* Encouraging match badge */
.encouragement-inline{
  display:inline-block;
  margin-left:14px;
  font-family:Poppins, Inter, system-ui, sans-serif;
  font-weight:600;
  font-size:15px;
  color:rgba(124,92,255,0.9);
  background:transparent;
  padding:6px 10px;
  border-radius:8px;
  box-shadow:none;
.opacity-anim{transition:opacity .22s ease,transform .22s ease,color .2s ease}
  opacity:0;transform:translateY(-4px);transition:opacity .22s ease,transform .22s ease,color .2s ease;
}
.encouragement-inline.show{opacity:1;transform:translateY(0)}
.encouragement-inline.left{margin-right:12px}
.encouragement-inline.right{margin-left:12px}

/* Progress bar */
.progress-wrap{width:100%;max-width:920px;display:flex;flex-direction:column;gap:8px;align-items:center}
.progress{width:100%;height:10px;background:linear-gradient(90deg,#eef1ff,#f6f8ff);border-radius:999px;overflow:hidden;box-shadow:inset 0 1px 0 rgba(255,255,255,0.6)}
.progress-bar{height:100%;background:linear-gradient(90deg,var(--accent),#5b3bff);width:0%;transition:width .5s ease}
.progress-wrap{transition:transform var(--anim-fast) var(--anim-ease),opacity var(--anim-fast) var(--anim-ease)}
.board.fade-out{opacity:0;transform:translateY(10px);transition:opacity var(--anim-fast) var(--anim-ease),transform var(--anim-fast) var(--anim-ease)}
.board.fade-in{opacity:1;transform:none;transition:opacity var(--anim-fast) var(--anim-ease),transform var(--anim-fast) var(--anim-ease)}
.progress-info{font-size:13px;color:var(--muted);font-weight:600}
