:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --text: #e9edf3;
  --text-dim: #9aa3b2;
  --border: #2b2f3a;
  --border-strong: #565f70;
  --key: #2a2f3a;
  --key-text: #e9edf3;
  --correct: #4fa86a;
  --present: #c9a23a;
  --absent: #3a3f4b;
  --accent: #4fa86a;
  --tile: clamp(44px, min(13vw, 9.2vh), 64px);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden;
  user-select: none;
}

/* ── topbar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand-row { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; }
.brand-avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 2px var(--correct); flex: 0 0 auto;
  transition: transform 120ms ease;
}
.brand-avatar:hover { transform: scale(1.12) rotate(-6deg); }
.brand {
  margin: 0; font-size: 30px; font-weight: 800; letter-spacing: 2px;
  text-transform: uppercase; text-align: center;
  background: linear-gradient(180deg, #fff, #b9c2d0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* faint Sajid watermark behind everything */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url(sajid/p21.jpg); background-size: 116px;
  opacity: 0.04; filter: grayscale(1);
}
.topbar, #game, .toast-wrap, .modal-overlay { position: relative; z-index: 1; }

/* Sajid click-pop */
.sajid-pop {
  position: fixed; z-index: 90; pointer-events: none;
  border-radius: 50%; object-fit: cover;
  box-shadow: 0 6px 18px -6px rgba(0,0,0,0.6), 0 0 0 2px rgba(255,255,255,0.18);
  animation: sajidpop 0.9s cubic-bezier(0.2,0.7,0.2,1) forwards;
  will-change: transform, opacity;
}
@keyframes sajidpop {
  0%   { transform: translate(0,0) scale(0.2) rotate(0); opacity: 0; }
  22%  { transform: translate(calc(var(--dx) * 0.3), -12px) scale(1.06) rotate(var(--rot)); opacity: 1; }
  100% { transform: translate(var(--dx), -94px) scale(0.65) rotate(var(--rot)); opacity: 0; }
}

/* Sajid win confetti */
.sajid-confetti {
  position: fixed; top: -64px; z-index: 85; pointer-events: none;
  border-radius: 9px; object-fit: cover;
  box-shadow: 0 4px 10px -4px rgba(0,0,0,0.5);
  animation-name: sajidfall; animation-timing-function: linear; animation-fill-mode: forwards;
  will-change: transform;
}
@keyframes sajidfall {
  0%   { transform: translateY(-12vh) rotate(0); opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(112vh) rotate(var(--spin)); opacity: 0.9; }
}

/* Sajid in the modal */
.modal-sajid {
  width: 52px; height: 52px; border-radius: 50%; object-fit: cover;
  display: block; margin: -6px auto 12px; box-shadow: 0 0 0 2px var(--correct);
}
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  background: transparent; border: none; color: var(--text-dim);
  font-size: 22px; font-weight: 700; cursor: pointer; border-radius: 8px;
  transition: background 120ms ease, color 120ms ease, transform 60ms ease;
}
.icon-btn:hover { color: var(--text); background: var(--bg-elev); }
.icon-btn:active { transform: scale(0.92); }

/* ── layout ── */
#game { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.board-wrap { flex: 1 1 auto; display: grid; place-items: center; min-height: 0; padding: 8px; overflow: hidden; }
.board {
  display: grid; gap: var(--gap, 5px);
  grid-template-rows: repeat(var(--rows, 6), var(--tile));
}
.row { display: grid; grid-template-columns: repeat(var(--cols, 5), var(--tile)); gap: var(--gap, 5px); }

.tile {
  width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  font-size: calc(var(--tile) * 0.52); font-weight: 700;
  text-transform: uppercase; color: var(--text);
  border: 2px solid var(--border);
  border-radius: 4px; background: transparent;
  transition: transform 90ms ease, border-color 90ms ease;
}
.tile.filled { border-color: var(--border-strong); animation: pop 110ms ease; }
@keyframes pop { 0% { transform: scale(0.92); } 45% { transform: scale(1.06); } 100% { transform: scale(1); } }

/* reveal flip */
.tile.reveal { animation: flip 560ms ease forwards; }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
.tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.tile.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

.row.shake { animation: shake 480ms ease; }
@keyframes shake {
  10%,90% { transform: translateX(-2px); }
  20%,80% { transform: translateX(4px); }
  30%,50%,70% { transform: translateX(-7px); }
  40%,60% { transform: translateX(7px); }
}
.tile.win { animation: bounce 900ms ease; }
@keyframes bounce {
  0%,20% { transform: translateY(0); }
  40% { transform: translateY(-26px); }
  50% { transform: translateY(4px); }
  60% { transform: translateY(-12px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

/* ── keyboard ── */
.keyboard {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 7px;
  padding: 8px 6px max(8px, env(safe-area-inset-bottom)); max-width: 520px;
  width: 100%; margin: 0 auto;
}
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; height: 56px;
  background: var(--key); color: var(--key-text);
  border: none; border-radius: 5px; cursor: pointer;
  font-size: 14px; font-weight: 700; text-transform: uppercase;
  display: grid; place-items: center;
  transition: background 120ms ease, transform 60ms ease, color 120ms ease;
}
.key:active { transform: scale(0.94); }
.key.wide { flex: 1.5 1 0; font-size: 11px; }
.key svg { width: 22px; height: 22px; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent  { background: var(--absent);  color: #8b90a0; }

/* ── toast ── */
.toast-wrap {
  position: fixed; top: 64px; left: 0; right: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: #e9edf3; color: #11141a;
  font-weight: 700; font-size: 14px;
  padding: 11px 16px; border-radius: 8px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.6);
  animation: toast-in 140ms ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ── modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 16px;
  animation: fade 160ms ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: relative; width: 100%; max-width: 400px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; padding: 26px 22px 22px;
  box-shadow: 0 30px 80px -24px rgba(0,0,0,0.8);
  animation: rise 200ms cubic-bezier(0.2,0,0,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-x {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border: none; background: transparent;
  color: var(--text-dim); font-size: 17px; cursor: pointer; border-radius: 7px;
}
.modal-x:hover { color: var(--text); background: var(--bg); }
.modal h2 { margin: 0 0 14px; font-size: 16px; text-transform: uppercase; letter-spacing: 1px; text-align: center; }
.modal p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

/* stats */
.stats-grid { display: flex; justify-content: center; gap: 6px; margin: 6px 0 18px; }
.stat { flex: 1; text-align: center; }
.stat .n { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11px; color: var(--text-dim); line-height: 1.2; margin-top: 2px; }
.dist { display: flex; flex-direction: column; gap: 5px; margin-bottom: 18px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.dist-row .g { width: 12px; text-align: right; color: var(--text-dim); }
.dist-row .bar {
  background: var(--absent); color: #fff; font-weight: 700;
  padding: 2px 8px; border-radius: 3px; min-width: 22px; text-align: right;
  transition: width 400ms ease;
}
.dist-row .bar.hot { background: var(--correct); }

.share-foot { display: flex; align-items: center; gap: 14px; }
.countdown { flex: 1; text-align: center; }
.countdown .l { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.countdown .t { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.share-divider { width: 1px; height: 48px; background: var(--border); }
.btn-share {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; border: none; border-radius: 30px;
  padding: 14px; font-size: 16px; font-weight: 800; text-transform: uppercase;
  cursor: pointer; transition: filter 120ms ease, transform 60ms ease;
}
.btn-share:hover { filter: brightness(1.08); }
.btn-share:active { transform: scale(0.97); }
.btn-share svg { width: 20px; height: 20px; }

/* help */
.help-ex { display: flex; gap: 4px; margin: 10px 0; }
.help-ex .tile { --tile: 34px; font-size: 18px; }
.help li { margin: 10px 0; font-size: 14px; color: var(--text-dim); line-height: 1.45; }
.help b { color: var(--text); }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.muted-note { color: var(--text-dim); font-size: 12px; text-align: center; }
