:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --ink: #1a1a1f;
  --muted: #6e6c78;
  --line: #dedde3;
  --tile-border: #d3d2da;
  --tile-filled: #8a8896;
  --key: #d6d5dd;
  --key-ink: #1a1a1f;
  --green: #3f9f62;
  --grey: #7d7b88;
  --backdrop: rgba(255, 255, 255, .6);
  --shadow: 0 12px 40px rgba(0, 0, 0, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1d24;
    --surface: #2a2932;
    --ink: #f2f1f5;
    --muted: #8e8c99;
    --line: #3a3944;
    --tile-border: #5a5866;
    --tile-filled: #8e8c99;
    --key: #6b6977;
    --key-ink: #ffffff;
    --grey: #44434d;
    --backdrop: rgba(0, 0, 0, .6);
    --shadow: 0 20px 60px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1e1d24;
  --surface: #2a2932;
  --ink: #f2f1f5;
  --muted: #8e8c99;
  --line: #3a3944;
  --tile-border: #5a5866;
  --tile-filled: #8e8c99;
  --key: #6b6977;
  --key-ink: #ffffff;
  --grey: #44434d;
  --backdrop: rgba(0, 0, 0, .6);
  --shadow: 0 20px 60px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Helvetica Neue", Arial, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  /* Stop double-tap zoom (e.g. tapping Backspace quickly on iPhone). */
  touch-action: manipulation;
}
button, a { touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

/* Header */
.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; font-size: 22px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.logo-mark {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--green); color: #fff;
  font-size: 15px; font-weight: 900;
}
.title { font-size: 20px; color: var(--muted); font-weight: 500; letter-spacing: .02em; white-space: nowrap; }
.links { display: flex; justify-content: flex-end; align-items: center; gap: 14px; font-size: 14px; }
.links a { color: var(--muted); }
.theme-btn {
  border: 0; background: transparent; padding: 2px;
  color: var(--muted);
  display: grid; place-items: center;
}
.theme-btn:hover { color: var(--ink); }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: block; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .moon { display: none; }
}

/* Board */
.board-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(12px, 3svh, 24px) 16px 12px;
  min-height: 0;
}
.board { display: flex; flex-direction: column; gap: 8px; margin: auto 0; }
.row { display: flex; gap: 8px; position: relative; }
.tile {
  /* Sized from the *small* viewport height (svh), which stays fixed when
     Safari's toolbar shows or hides, so tiles never jump in size. */
  --size: clamp(44px, 7.4vh, 62px);
  --size: clamp(44px, 7.4svh, 62px);
  width: var(--size); height: var(--size);
  border: 2px solid var(--tile-border);
  display: grid; place-items: center;
  font-size: calc(var(--size) * .55);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
}
.tile.filled { border-color: var(--tile-filled); animation: pop .1s ease; }
.tile.done { border-color: var(--grey); background: var(--grey); color: #fff; }
.tile.g { border-color: var(--green); background: var(--green); color: #fff; }
.row.start .tile { border-color: var(--tile-border); background: transparent; color: var(--ink); }
.row.start .tile.g { border-color: var(--green); background: transparent; color: var(--green); }
.tile.reveal { animation: flip .5s ease forwards; }
.row.win .tile { animation: bounce .6s ease; }
.row.win .tile:nth-child(2) { animation-delay: .08s; }
.row.win .tile:nth-child(3) { animation-delay: .16s; }
.row.win .tile:nth-child(4) { animation-delay: .24s; }
.row.answer .tile { opacity: .55; border-style: dashed; }
.row.shake { animation: shake .5s; }

@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18px); } 70% { transform: translateY(4px); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%, 55% { transform: translateX(-7px); }
  35%, 75% { transform: translateX(7px); }
}

/* Keyboard */
.keyboard {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 8px 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kb-row { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1;
  max-width: 43px;
  height: clamp(44px, 7vh, 58px);
  height: clamp(44px, 7svh, 58px);
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-ink);
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}
.key.wide { max-width: 66px; flex: 1.5; font-size: 14px; text-transform: none; }
.key:active, .key.pressed { filter: brightness(1.2); }
.keyboard { touch-action: none; }

/* Footer links */
.foot {
  display: flex;
  justify-content: space-around;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  font-size: 16px;
}
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--ink); }

/* Toast */
/* Birthday banner (only shown on the birthday date) */
.bday {
  border: 0;
  width: 100%;
  padding: 10px 16px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(90deg, #e2558b, #f2a93b, #3f9f62, #4a8fe0, #9b5de5);
  background-size: 300% 100%;
  animation: bday-shift 6s linear infinite;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
@keyframes bday-shift { from { background-position: 0 0; } to { background-position: 300% 0; } }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
@media (prefers-reduced-motion: reduce) { .bday { animation: none; } }

.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translate(-50%, -8px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
  text-align: center;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Modals */
.modal {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  width: min(420px, calc(100% - 32px));
  max-height: calc(100dvh - 40px);
  padding: 24px 22px 22px;
  box-shadow: var(--shadow);
}
.modal::backdrop { background: var(--backdrop); }
.modal h2 { margin: 0 0 12px; font-size: 20px; text-align: center; text-transform: uppercase; letter-spacing: .06em; }
.modal h3 { margin: 20px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; text-align: center; }
.modal ul { padding-left: 20px; line-height: 1.6; }
.modal .small { font-size: 14px; color: var(--muted); }
.close {
  position: absolute; top: 8px; right: 12px;
  border: 0; background: transparent;
  font-size: 28px; line-height: 1;
  color: var(--muted);
}
.close:focus:not(:focus-visible) { outline: none; }
.z { color: var(--green); }
.example { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 14px 0; }
.mini { display: flex; gap: 4px; }
.mini span {
  width: 30px; height: 30px;
  border: 2px solid var(--grey);
  background: var(--grey);
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px;
  color: #fff;
}
.mini span.g { background: var(--green); border-color: var(--green); }

.path { text-align: center; font-weight: 700; letter-spacing: .04em; line-height: 1.8; }
.path .opt { color: var(--muted); font-weight: 500; font-size: 14px; margin-top: 6px; }
.result { text-align: center; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.result p { margin: 0 0 10px; color: var(--muted); }
.zain-gif {
  display: block;
  margin: 4px auto 12px;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(240px, 32svh);
  border-radius: 10px;
}
.result-btns { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.btn {
  border: 0;
  border-radius: 6px;
  padding: 12px 22px;
  font-weight: 700;
  font-size: 16px;
  background: var(--key);
  color: #fff;
}
.btn.primary { background: var(--green); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; }
.stats b { display: block; font-size: 32px; font-weight: 500; }
.stats span { font-size: 12px; color: var(--muted); }
.dist { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.dist .bar-row { display: grid; grid-template-columns: 32px 1fr; gap: 8px; align-items: center; }
.dist .bar-fill {
  background: var(--grey);
  padding: 2px 8px;
  text-align: right;
  font-weight: 700;
  min-width: 24px;
}
.dist .bar-fill.me { background: var(--green); }
.countdown { text-align: center; margin: 20px 0 0; color: var(--muted); }
.countdown b { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 18px; }
.giveup { text-align: center; margin: 14px 0 0; font-size: 13px; }
.giveup a { color: var(--muted); }

/* Smaller screens */
@media (max-width: 420px) {
  .bar { grid-template-columns: auto 1fr auto; padding: 10px 12px; }
  .logo { font-size: 19px; }
  .title { font-size: 17px; text-align: center; }
  .links { gap: 10px; font-size: 13px; }
  .foot { font-size: 14px; }
}
@media (max-width: 360px) {
  .logo-mark { display: none; }
}
