:root {
  --bg: #0f172a;            /* slate-900 */
  --panel: #111827;         /* gray-900 */
  --tile: #1f2937;          /* gray-800 */
  --tile-hover: #374151;    /* gray-700 */
  --accent: #22d3ee;        /* cyan-400 */
  --accent-2: #a78bfa;      /* violet-400 */
  --text: #e5e7eb;          /* gray-200 */
  --muted: #9ca3af;         /* gray-400 */
  --danger: #f87171;        /* red-400 */
  --success: #34d399;       /* green-400 */
  --focus: #f59e0b;         /* amber-500 */
  --radius: 10px;
  --duration: 320ms;
  --shadow: 0 6px 18px rgba(0,0,0,.25);
  --tile-size: 64px; /* overridden per size */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 500 14px/1.35 system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial, sans-serif;
  overflow: hidden;
}

#ad {
  position: relative;
  width: 100%; height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: linear-gradient(180deg, #0b1220 0%, #0f172a 70%);
}

.header, .footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px;
}
.header {
  gap: 8px;
}
.brand {
  display:flex; align-items:center; gap:8px;
}
.brand-badge {
  width: 16px; height: 16px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}
.title {
  font-weight: 700; letter-spacing: .3px;
  font-size: 12px; color: var(--text);
  text-transform: uppercase;
}

.meta {
  display:flex; gap: 10px; align-items:center; color: var(--muted);
  font-size: 11px;
}
.meta .dot { width:4px; height:4px; background:#475569; border-radius:50%; display:inline-block; }

.timer, .attempts { white-space:nowrap; }

.board-wrap {
  display:flex; align-items:center; justify-content:center;
  padding: 4px 6px 2px;
}

.board {
  display:grid;
  gap: 6px;
  align-content:center; justify-content:center;
  perspective: 800px;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--duration) cubic-bezier(.2,.8,.2,1);
  border-radius: var(--radius);
  outline: none;
}
.tile:focus-visible {
  box-shadow: 0 0 0 2px var(--focus) inset, 0 0 0 2px var(--focus);
}

.face {
  position:absolute; inset:0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display:flex; align-items:center; justify-content:center;
  box-shadow: var(--shadow);
}

.front {
  background: radial-gradient(120% 120% at 0% 0%, #0b1220 0%, var(--tile) 100%);
  border: 1px solid #0b1220;
}
.back {
  background: radial-gradient(120% 120% at 0% 0%, #0b1220 0%, #1e293b 100%);
  transform: rotateY(180deg);
  border: 1px solid #0b1220;
  color: #e2e8f0;
  font-weight: 800;
  font-size: 22px;
}

.tile:hover .front { filter: brightness(1.1); }
.tile.matched { transform: rotateY(180deg); }
.tile.flipped { transform: rotateY(180deg); }
.tile.matched .back { outline: 2px solid var(--success); }

.feedback {
  position:absolute; top:6px; right:8px; font-size: 11px;
  padding: 2px 6px; border-radius: 999px; background:#0b1220; color:var(--muted); border:1px solid #1f2937;
}

.cta-bar {
  display:flex; gap:8px; align-items:center; justify-content:space-between;
  padding: 6px 8px 8px;
}
.btn {
  appearance:none; border:0; border-radius: 999px; padding: 8px 12px;
  font-weight: 700; letter-spacing:.2px; cursor:pointer;
}
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn-replay { background:#0b1220; color:var(--text); border:1px solid #1f2937; }
.btn-cta { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color:#0b1220; }

.overlay {
  position:absolute; inset:0; display:none; align-items:center; justify-content:center;
  background: rgba(2,6,23, .86);
}
.overlay.show { display:flex; }

.dialog {
  background: #0b1220; border: 1px solid #1f2937; border-radius: 14px; padding: 12px;
  width: 86%; max-width: 260px; text-align:center; box-shadow: var(--shadow);
}
.dialog h3 { margin: 0 0 6px; font-size: 16px; }
.dialog p { margin: 6px 0; color: var(--muted); font-size: 12px; }
.stats { display:flex; gap:10px; justify-content:center; font-weight:700; color: var(--text); }

/* Size overrides (set via data-size on #ad) */
#ad[data-size="300x250"] { --tile-size: 60px; }
#ad[data-size="300x600"] { --tile-size: 56px; }
#ad[data-size="320x480"] { --tile-size: 58px; }

/* Preloader */
.preloader {
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
}
.spinner {
  width: 26px; height: 26px; border: 3px solid #0b1220; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }