/* Lafz: deep Pakistan green for the frame, haldi yellow for "present" tiles. */
:root {
  --bg: #f3f0e8;
  --surface: #ffffff;
  --surface-2: #ebe6da;
  --fg: #17201b;
  --muted: #646b66;
  --border: #d3ccbd;
  --brand: #0c5a35;
  --brand-fg: #ffffff;
  --correct: #1d8a4e;
  --present: #d3a12a;
  --absent: #7b807c;
  --tile-fg: #ffffff;
  --key: #dcd6c8;
  --key-fg: #17201b;
  --danger: #c0392b;
  --font: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --urdu: "Noto Nastaliq Urdu", serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1310;
    --surface: #161e19;
    --surface-2: #1e2822;
    --fg: #eef2ee;
    --muted: #97a19a;
    --border: #2c3730;
    --brand: #3fb878;
    --brand-fg: #08130d;
    --correct: #2f9e5d;
    --present: #c79a22;
    --absent: #3a423d;
    --key: #2b352f;
    --key-fg: #eef2ee;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1310;
  --surface: #161e19;
  --surface-2: #1e2822;
  --fg: #eef2ee;
  --muted: #97a19a;
  --border: #2c3730;
  --brand: #3fb878;
  --brand-fg: #08130d;
  --correct: #2f9e5d;
  --present: #c79a22;
  --absent: #3a423d;
  --key: #2b352f;
  --key-fg: #eef2ee;
  color-scheme: dark;
}
:root[data-contrast="high"] {
  --correct: #f5793a;
  --present: #3d9be9;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* Header */
.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.top-side { display: flex; gap: 2px; }
.top-side.end { justify-content: flex-end; }
.logo { margin: 0; display: flex; align-items: baseline; gap: 8px; line-height: 1; }
.logo-ur { font-family: var(--urdu); font-size: 26px; color: var(--brand); line-height: 1.6; margin-top: -10px; }
.logo-en { font-weight: 800; font-size: 22px; letter-spacing: .02em; }
.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  background: none; border: 0; border-radius: 10px;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }

/* Mode tabs */
.modes {
  display: flex;
  gap: 5px;
  padding: 8px 10px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.modes::-webkit-scrollbar { display: none; }
.mode-tab {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center;
  gap: 0;
  min-width: 0;
  padding: 4px 2px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.mode-tab .ur { font-family: var(--urdu); font-size: 15px; line-height: 1.9; color: var(--muted); }
.mode-tab .en { font-weight: 700; font-size: 13px; line-height: 1; }
.mode-tab .n { font-size: 11px; color: var(--muted); line-height: 1.3; }
.mode-tab[aria-current="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.mode-tab[aria-current="true"] .ur, .mode-tab[aria-current="true"] .n { color: inherit; opacity: .85; }
.mode-tab .done { font-size: 10px; }

.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  font-size: 14px;
  min-height: 44px;
}
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: none; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.sub-info { display: flex; align-items: center; gap: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sub-info b { color: var(--fg); }
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 14px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.btn.wa { background: #25d366; border-color: #25d366; color: #062b16; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.custom-banner {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px;
  min-width: 0;
}
.custom-banner span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Play area */
.play {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 10px 16px;
  outline: none;
  scroll-behavior: smooth;
}
.boards {
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  gap: var(--gap, 10px);
  align-items: start;
}
.board {
  container-type: inline-size;
  min-width: 0;
  border-radius: 8px;
  padding: 3px;
  transition: opacity .3s;
}
.board.solved { background: color-mix(in srgb, var(--correct) 10%, transparent); }
.board.solved.collapsed { opacity: .75; }
.bhead {
  display: flex; justify-content: space-between; align-items: center;
  font-size: clamp(9px, 9cqi, 13px);
  color: var(--muted);
  height: 1.6em;
  padding: 0 2px;
  white-space: nowrap;
  overflow: hidden;
}
.grid { display: grid; gap: clamp(1px, 1.4cqi, 5px); }
.row { display: grid; grid-template-columns: repeat(var(--len), minmax(0, 1fr)); gap: clamp(1px, 1.4cqi, 5px); }
.tile {
  aspect-ratio: 1;
  display: grid; place-items: center;
  border: 2px solid var(--border);
  border-radius: clamp(2px, 1.6cqi, 6px);
  font-weight: 800;
  font-size: clamp(9px, calc(52cqi / var(--len)), 34px);
  text-transform: uppercase;
  line-height: 1;
  user-select: none;
}
.tile.filled { border-color: var(--muted); animation: pop .1s ease-out; }
.tile.s0, .tile.s1, .tile.s2 { border-color: transparent; color: var(--tile-fg); }
.tile.s0 { background: var(--absent); }
.tile.s1 { background: var(--present); }
.tile.s2 { background: var(--correct); }
.tile.miss { border-color: var(--danger); color: var(--danger); }
.row.reveal .tile { animation: flip .5s ease-in-out both; animation-delay: calc(var(--i) * 0.12s); }
.row.pop .tile { animation: pop .18s ease-out; }
.row.shake { animation: shake .4s; }

/* Ek: one big board */
.ek-wrap { max-width: 340px; margin: 0 auto; }
.ek-wrap .board { padding: 0; }
.ek-wrap .grid, .ek-wrap .row { gap: 6px; }
.ek-hint {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  margin: 2px 0 10px;
}
.ek-hint b { color: var(--fg); }

/* Hazaar: kilordle-style */
.hz-top {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px;
  font-size: 14px; color: var(--muted);
  margin: 0 0 8px;
}
.hz-top b { color: var(--fg); font-variant-numeric: tabular-nums; }
.hz-input { max-width: 300px; margin: 0 auto 8px; container-type: inline-size; }
.hz-recent {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  margin: 0 auto 12px; max-width: 640px;
}
.chip {
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.chip.hit { background: var(--correct); color: var(--tile-fg); }
.hz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.hz-card {
  container-type: inline-size;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px;
}
.hz-card .row { gap: 2px; }
.hz-card .tile { border-width: 1px; font-size: clamp(9px, 13cqi, 18px); }
.hz-meta { display: flex; justify-content: space-between; gap: 4px; font-size: 11px; color: var(--muted); margin-top: 4px; min-height: 14px; }
.hz-meta .y { color: var(--present); font-weight: 700; letter-spacing: .08em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hz-more { display: flex; justify-content: center; margin-top: 12px; }

/* Keyboard */
.keyboard {
  padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
  user-select: none;
}
.krow { display: flex; justify-content: center; gap: 5px; margin: 0 auto 6px; max-width: 520px; }
.krow:last-child { margin-bottom: 0; }
.key {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: clamp(42px, 6.4dvh, 56px);
  border: 0;
  border-radius: 7px;
  background: var(--key);
  color: var(--key-fg);
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  touch-action: manipulation;
  transition: opacity .2s;
}
.key.wide { flex: 1.55 1 0; font-size: 12px; }
.key .lbl { position: relative; z-index: 1; }
.key .segs { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--sc), 1fr); }
.key .segs i { display: block; }
.key .segs i.s0 { background: var(--absent); }
.key .segs i.s1 { background: var(--present); }
.key .segs i.s2 { background: var(--correct); }
.key.s0 { background: var(--absent); color: var(--tile-fg); }
.key.s1 { background: var(--present); color: var(--tile-fg); }
.key.s2 { background: var(--correct); color: var(--tile-fg); }
.key.has-segs { color: var(--key-fg); }
.key.has-segs .lbl { text-shadow: 0 0 3px var(--key), 0 0 6px var(--key); }
.key.gone { opacity: .28; }
.key:active { filter: brightness(.9); }
.key svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }

/* Toasts */
.toasts {
  position: fixed; top: 170px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 50; pointer-events: none;
}
.toast {
  background: var(--fg); color: var(--bg);
  padding: 9px 14px; border-radius: 8px;
  font-weight: 600; font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .2);
  animation: fadein .15s ease-out;
}

/* Modal */
dialog {
  border: 0;
  padding: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--fg);
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog[open] { animation: rise .18s ease-out; }
.modal-close-form { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 8px 8px 0; height: 0; z-index: 2; }
.modal-body { padding: 20px 20px 22px; overflow-y: auto; max-height: calc(100dvh - 32px); }
.modal-body h2 { margin: 0 40px 6px 0; font-size: 22px; font-weight: 800; line-height: 1.2; }
.modal-body h3 { font-size: 15px; margin: 20px 0 8px; }
.modal-body p { margin: 0 0 10px; line-height: 1.5; }
.modal-body .muted { color: var(--muted); font-size: 14px; }
.modal-body ul { padding-left: 1.1em; margin: 0 0 10px; line-height: 1.5; }
.modal-body li { margin-bottom: 4px; }
.modal-body .ur { font-family: var(--urdu); }
.ur, [lang="ur"] { unicode-bidi: isolate; }
.modal-body:focus { outline: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.field { display: grid; gap: 6px; margin: 10px 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select {
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
.field textarea { min-height: 110px; text-transform: uppercase; font-weight: 600; letter-spacing: .06em; resize: vertical; }
.field .err { color: var(--danger); font-size: 13px; min-height: 1em; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: 0; }
.toggle small { display: block; color: var(--muted); font-size: 13px; }
.toggle input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.toggle select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }

.big-word {
  display: flex; justify-content: center; gap: 5px; margin: 10px 0 6px;
}
.big-word .tile { width: 44px; font-size: 22px; container-type: normal; }
.gloss { list-style: none; padding: 0 !important; margin: 0; display: grid; gap: 8px; }
.gloss li { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline; margin: 0 !important; }
.gloss .w { font-weight: 800; letter-spacing: .06em; }
.gloss .w.miss { color: var(--danger); }
.gloss .w.ok { color: var(--correct); }
.gloss .m { font-size: 14px; color: var(--muted); }
.answers { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.answers span { font-weight: 700; font-size: 13px; letter-spacing: .05em; padding: 3px 8px; border-radius: 6px; background: color-mix(in srgb, var(--correct) 18%, transparent); }
.answers span.miss { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin: 6px 0 4px; }
.stats-grid b { display: block; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats-grid span { font-size: 12px; color: var(--muted); }
.dist { display: grid; gap: 4px; margin-top: 8px; }
.dist div { display: grid; grid-template-columns: 14px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.dist i { display: block; background: var(--absent); color: var(--tile-fg); font-style: normal; font-weight: 700; font-size: 12px; padding: 2px 6px; text-align: right; border-radius: 4px; min-width: 22px; }
.dist i.hl { background: var(--correct); }
.mode-stats { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.mode-stats th, .mode-stats td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.mode-stats th:first-child, .mode-stats td:first-child { text-align: left; }
.mode-stats th { color: var(--muted); font-weight: 600; font-size: 12px; }

.lb { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.lb td, .lb th { padding: 7px 4px; border-bottom: 1px solid var(--border); text-align: right; }
.lb td:nth-child(2), .lb th:nth-child(2) { text-align: left; }
.lb th { color: var(--muted); font-size: 12px; font-weight: 600; }
.lb tr.me td { font-weight: 700; color: var(--brand); }
.lb .rank { width: 28px; color: var(--muted); text-align: left; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.pill { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 600; }
.pill[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.mehfil-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin: 10px 0; }
.mehfil-card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mehfil-card h3 { margin: 0; }
.code { font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: .12em; background: var(--surface-2); padding: 2px 8px; border-radius: 6px; }
.example { display: flex; gap: 4px; margin: 8px 0 4px; max-width: 240px; container-type: inline-size; }
.example .tile { flex: 1; font-size: 18px; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

@keyframes flip {
  0% { transform: rotateX(0); background: transparent; color: var(--fg); border-color: var(--muted); }
  49% { transform: rotateX(90deg); background: transparent; color: var(--fg); border-color: var(--muted); }
  51% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes pop { 0% { transform: scale(.88); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-delay: 0s !important; transition: none !important; }
  .play { scroll-behavior: auto; }
}
@media (max-width: 380px) {
  .logo-en { font-size: 19px; }
  .icon-btn { width: 36px; height: 36px; }
  .mode-tab .en { font-size: 12px; }
}
