/* Tantala — "Ajrakh" identity: indigo (neel) ground, haldi and madder accents,
   Kutch block-print border. One display face (Shrikhand), system sans for UI. */

@font-face {
  font-family: "Shrikhand";
  src: url("../public/fonts/shrikhand-latin.woff2") format("woff2");
  font-display: swap;
  unicode-range: U+0020-007E, U+2014, U+2019;
}

/* Noto Sans Devanagari Bold, subset to the Devanagari block (conjunct GSUB kept).
   Only referenced under [data-script="devanagari"], so Hinglish never loads it. */
@font-face {
  font-family: "Tantala Deva";
  src: url("../public/fonts/noto-sans-devanagari-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0900-097F, U+200C-200D, U+25CC;
}

:root {
  --neel: #1d2257;        /* indigo band */
  --neel-deep: #141845;
  --paper: #eef0f8;       /* indigo-washed muslin */
  --ink: #1b1f4b;
  --ink-soft: #4b5080;
  --tile: #ffffff;
  --tile-edge: #c8cbe4;
  --haldi: #f2b705;       /* turmeric: found theme words */
  --haldi-thread: #9a6a00;
  --madder: #a8233a;      /* madder red: the taana */
  --madder-thread: #6e1222;
  --peacock: #0e7c7b;     /* live selection thread */
  --on-accent: #ffffff;
  --focus: #0e7c7b;
  --shadow: 0 1px 0 rgba(27, 31, 75, .14);
  --display: "Shrikhand", "Georgia", serif;
  --deva: "Tantala Deva", "Noto Sans Devanagari", "Mangal", "Nirmala UI", sans-serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --board-w: min(100%, 26rem, calc((100svh - 17rem) * .75));
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --neel: #181c4c;
    --neel-deep: #0d1030;
    --paper: #10132e;
    --ink: #eceaf6;
    --ink-soft: #a9accb;
    --tile: #1d2150;
    --tile-edge: #343a72;
    --haldi: #f5c431;
    --haldi-thread: #8a5e00;
    --madder: #c23a52;
    --madder-thread: #f2a3b1;
    --peacock: #2bb5b0;
    --on-accent: #ffffff;
    --focus: #5fd6d1;
    --shadow: 0 1px 0 rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 var(--ui);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- header band ---------- */

.band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .55rem max(1rem, env(safe-area-inset-right)) .45rem max(1rem, env(safe-area-inset-left));
  background: var(--neel);
  color: #f6f2e4;
}

.brand { margin: 0; display: flex; align-items: flex-end; gap: .6rem; line-height: 1; }

.wordmark { height: 2.6rem; width: auto; fill: #f2b705; display: block; }

.brand-latin {
  font: 400 .95rem/1 var(--display);
  color: #cfd2f0;
  letter-spacing: .02em;
  padding-bottom: .2rem;
}

.tools { display: flex; gap: .25rem; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent;
  color: #f6f2e4;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }

/* Kutch ajrakh-style border: madder diamonds and haldi dots on indigo */
.ajrakh {
  height: 14px;
  background-color: var(--neel-deep);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='14'%3E%3Cpath d='M14 1l6 6-6 6-6-6z' fill='%23a8233a'/%3E%3Cpath d='M14 4.5l2.5 2.5L14 9.5 11.5 7z' fill='%230d1030'/%3E%3Ccircle cx='1' cy='7' r='1.6' fill='%23f2b705'/%3E%3Ccircle cx='27' cy='7' r='1.6' fill='%23f2b705'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: center;
  border-bottom: 2px solid var(--haldi);
}

/* ---------- main column ---------- */

.app {
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
}

.theme {
  width: var(--board-w); min-width: 16.5rem;
  margin: 0 auto .25rem;
}
.theme-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.theme-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.theme-text { min-width: 0; }
.theme-kicker { margin: 0; font-size: .875rem; color: var(--ink-soft); }
.theme-title {
  margin: 0;
  font: 400 clamp(1.75rem, 8vw, 2.3rem)/1.1 var(--display);
  color: var(--ink);
}
.theme-sub { margin: 0; color: var(--ink-soft); font-size: 1rem; min-height: 1.5em; }

/* script switch: ABC | अआ. Labels use system fonts so the Hindi webfont
   is never fetched until Devanagari mode is on. */
.script-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  border: 1.5px solid var(--tile-edge);
  background: var(--tile);
}
.script-switch button {
  min-width: 52px; min-height: 40px;
  padding: 0 .75rem;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font: 700 .9375rem/1 var(--ui);
  cursor: pointer;
  position: relative;
}
/* 40px pill + 3px padding on each side = 46px tap target */
.script-switch button::after { content: ""; position: absolute; inset: -3px 0; }
.script-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.script-switch button:disabled { opacity: .4; cursor: not-allowed; }

/* progress counter: a big number with a small label */
.progress {
  flex: none;
  margin: 0;
  display: flex; flex-direction: column; align-items: flex-end;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.progress b { font: 400 2rem/1 var(--display); color: var(--madder); }
@media (prefers-color-scheme: dark) { .progress b { color: var(--haldi); } }
.progress span { font-size: .8125rem; color: var(--ink-soft); }

.readout {
  min-height: 3.5rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .15rem;
  margin: .25rem auto .35rem;
  width: var(--board-w);
  text-align: center;
}
.readout-word {
  font: 400 1.5rem/1.1 var(--display);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--peacock);
  min-height: 1.1em;
}
.readout-word.is-empty {
  font: 400 .9375rem/1.3 var(--ui);
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-soft);
}
.readout-word.is-good { color: var(--haldi-thread); }
.readout-word.is-taana { color: var(--madder); }
.readout-word.is-bad { color: var(--ink-soft); text-decoration: line-through 2px; }
@media (prefers-color-scheme: dark) {
  .readout-word.is-good { color: var(--haldi); }
  .readout-word.is-taana { color: var(--madder-thread); }
}
.readout-msg { font-size: .875rem; font-weight: 600; color: var(--ink); min-height: 1.3em; }

/* ---------- board ---------- */

.board {
  position: relative;
  width: var(--board-w);
  min-width: 16.5rem;              /* 6 x 44px targets */
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.threads {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

/* each cell fills its grid area exactly so overlay centres line up;
   the visible tile is the inset ::before */
.cell {
  position: relative;
  display: grid; place-items: center;
  min-width: 44px; min-height: 44px;
  padding: 0; border: 0;
  background: none;
  cursor: pointer;
  font: 400 clamp(1.15rem, 6vw, 1.6rem)/1 var(--display);
  text-transform: uppercase;
  color: var(--ink);
  -webkit-touch-callout: none;
}
.cell::before {
  content: "";
  position: absolute; inset: 9%;
  border-radius: 32%;
  background: var(--tile);
  border: 1.5px solid var(--tile-edge);
  box-shadow: var(--shadow);
  transition: background-color .15s, border-color .15s, transform .15s;
}
.cell > span { position: relative; z-index: 3; pointer-events: none; }
.cell:focus-visible { outline: none; }
.cell:focus-visible::before { outline: 3px solid var(--focus); outline-offset: 2px; }

.cell.is-sel::before { background: var(--peacock); border-color: var(--peacock); transform: scale(1.04); }
.cell.is-sel { color: var(--on-accent); }

.cell.is-theme::before { background: var(--haldi); border-color: var(--haldi); }
.cell.is-theme { color: #1b1f4b; cursor: default; }

.cell.is-taana::before {
  background-color: var(--madder);
  border-color: var(--madder);
  background-image: radial-gradient(circle, rgba(255, 255, 255, .55) 0 1.6px, transparent 2.2px);
  background-size: 9px 9px;
  background-position: 2px 2px;
}
.cell.is-taana { color: var(--on-accent); cursor: default; }

.cell.is-hint::after {
  content: "";
  position: absolute; inset: 1%;
  border-radius: 36%;
  border: 2.5px dashed var(--madder);
  pointer-events: none;
}
@media (prefers-color-scheme: dark) { .cell.is-hint::after { border-color: var(--madder-thread); } }

/* threads: a strand plus a dashed highlight reads as twisted cotton */
.strand { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.live .strand { stroke: var(--peacock); stroke-width: .2; opacity: .85; }
.live .twist { fill: none; stroke: #fff; stroke-width: .07; stroke-dasharray: .07 .13; stroke-linecap: round; opacity: .55; }
.live .knot { fill: var(--peacock); }
.found-theme .strand { stroke: var(--haldi-thread); stroke-width: .15; opacity: .6; }
.found-taana .strand { stroke: var(--madder-thread); stroke-width: .15; opacity: .7; stroke-dasharray: .22 .1; }

/* ---------- actions ---------- */

.actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr;
  gap: .5rem;
  width: var(--board-w);
  min-width: 16.5rem;
  margin: 1rem auto .25rem;
}

.btn {
  min-height: 48px;
  padding: .5rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-ghost { border-color: var(--tile-edge); }
.btn-small { min-height: 44px; padding: .25rem .9rem; }

.btn-hint.is-ready { border-color: var(--madder); background: var(--madder); color: #fff; }

/* hint meter: three beads strung on a thread */
.beads {
  position: relative;
  display: inline-flex; gap: 4px;
  padding: 0 2px;
}
.beads::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 50%;
  border-top: 1.5px solid currentColor;
  opacity: .5;
}
.beads i {
  position: relative;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  background: var(--paper);
}
.beads i.on { background: var(--haldi); border-color: var(--haldi-thread); }
.btn-hint.is-ready .beads i { background: var(--haldi); border-color: #fff; }

.hint-note {
  width: var(--board-w); min-width: 16.5rem;
  margin: 0 auto; min-height: 1.4em;
  text-align: center; font-size: .875rem; color: var(--ink-soft);
}

/* ---------- found list ---------- */

.found { width: var(--board-w); min-width: 16.5rem; margin: 1.25rem auto 0; }
.found-heading { margin: 0 0 .4rem; font-size: 1rem; font-weight: 600; }
.found-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.found-list li {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .7rem;
  border-radius: 999px;
  background: var(--haldi); color: #1b1f4b;
  font: 400 1rem/1.6 var(--display);
}
.found-list li.taana {
  background-color: var(--madder); color: #fff;
  background-image: radial-gradient(circle, rgba(255, 255, 255, .35) 0 1.4px, transparent 2px);
  background-size: 8px 8px;
}
.found-list li.empty { background: none; color: var(--ink-soft); font: italic .9375rem/1.6 var(--ui); padding: 0; }
.bonus-line { margin: .6rem 0 0; font-size: .9375rem; color: var(--ink-soft); }

/* ---------- footer ---------- */

.site-foot {
  max-width: 30rem;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(2rem + env(safe-area-inset-bottom));
  border-top: 1.5px solid var(--tile-edge);
  text-align: center;
  font-size: .875rem;
  color: var(--ink-soft);
}
.site-foot p { margin: 0 0 .35rem; }
.site-foot a {
  color: var(--ink);
  font-weight: 600;
  text-decoration-color: var(--haldi);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  display: inline-block;
  padding: .75rem 0;                /* >= 44px tall tap target without changing the line */
  margin: -.75rem 0;
}

.foot-links { display: flex; justify-content: center; gap: 1.5rem; margin-top: .25rem; }

/* ---------- content pages: about, privacy, 404 ---------- */

.brand-link { display: flex; align-items: flex-end; gap: .6rem; color: inherit; text-decoration: none; }
.wordmark-img { height: 2.6rem; width: auto; display: block; }
.band .play-link {
  color: #1b1f4b; background: #f2b705;
  border-radius: 999px; padding: .55rem 1rem; min-height: 44px;
  display: inline-flex; align-items: center;
  font-weight: 700; text-decoration: none;
}
.page {
  max-width: 36rem;
  margin: 0 auto;
  padding: 1.75rem 1rem 2rem;
  line-height: 1.6;
}
.page h1 { font: 400 clamp(2rem, 9vw, 2.6rem)/1.1 var(--display); margin: 0 0 .5rem; }
.page h2 { font-size: 1.15rem; margin: 2rem 0 .5rem; }
.page p, .page li { max-width: 62ch; }
.page p { margin: 0 0 .9rem; }
.page ul { padding-left: 1.2rem; margin: 0 0 1rem; }
.page li { margin-bottom: .35rem; }
.page a { color: var(--ink); font-weight: 600; text-decoration-color: var(--haldi); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.page .lede { font-size: 1.125rem; color: var(--ink-soft); }
.page .updated { font-size: .875rem; color: var(--ink-soft); }
.page code { font-size: .9em; background: var(--tile); border: 1px solid var(--tile-edge); border-radius: .3rem; padding: .05rem .3rem; }
.page table { border-collapse: collapse; width: 100%; margin: 0 0 1rem; font-size: .9375rem; }
.page th, .page td { text-align: left; vertical-align: top; padding: .5rem .5rem .5rem 0; border-bottom: 1px solid var(--tile-edge); }
.page th { font-weight: 600; }
.page .big-mark { font: 400 5rem/1 var(--display); color: var(--haldi); margin: 0; }
.page .btn-primary { color: var(--paper); text-decoration: none; }

/* ---------- banner ---------- */

.banner {
  position: fixed; left: 1rem; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom));
  max-width: 28rem; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .5rem .5rem .5rem 1rem;
  border-radius: 1rem;
  background: var(--neel); color: #f6f2e4;
  border: 2px solid var(--haldi);
  z-index: 15;
}
.banner .btn { border-color: var(--haldi); background: var(--haldi); color: #1b1f4b; }

/* ---------- dialogs ---------- */

.sheet {
  width: min(28rem, calc(100% - 2rem));
  max-height: calc(100svh - 2rem);
  padding: 0;
  border: 0;
  border-radius: 1.25rem;
  background: var(--paper);
  color: var(--ink);
  border-top: 10px solid var(--neel);
  box-shadow: 0 20px 60px rgba(13, 16, 48, .45);
}
.sheet::backdrop { background: rgba(13, 16, 48, .55); }
.sheet-inner { padding: 1.25rem 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .75rem; }
.sheet h2 { margin: 0; font: 400 1.75rem/1.15 var(--display); }
.sheet h3 { margin: .5rem 0 0; font-size: 1rem; }
.sheet p { margin: 0; }
.rules, .legend { margin: 0; padding-left: 1.1rem; display: grid; gap: .5rem; }
.legend { list-style: none; padding: 0; }
.legend li { display: flex; align-items: center; gap: .6rem; }
.swatch { flex: none; width: 28px; height: 28px; border-radius: 30%; }
.sw-theme { background: var(--haldi); }
.sw-taana {
  background-color: var(--madder);
  background-image: radial-gradient(circle, rgba(255, 255, 255, .55) 0 1.6px, transparent 2.2px);
  background-size: 8px 8px;
}
.sw-hint { border: 2.5px dashed var(--madder); background: var(--tile); }
.fine { font-size: .875rem; color: var(--ink-soft); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 44px; }
.switch-row input { width: 24px; height: 24px; accent-color: var(--peacock); }
.lang { border: 1.5px solid var(--tile-edge); border-radius: .75rem; padding: .5rem .9rem .75rem; display: grid; gap: .25rem; }
.lang legend { padding: 0 .3rem; font-weight: 600; }
.lang label { display: flex; align-items: center; gap: .6rem; min-height: 44px; }
.lang input { width: 20px; height: 20px; accent-color: var(--peacock); }
.lang .is-disabled { color: var(--ink-soft); }

.done { text-align: center; align-items: stretch; }
.share-preview {
  margin: 0 auto;
  padding: .75rem 1rem;
  border-radius: .75rem;
  background: var(--tile);
  border: 1.5px solid var(--tile-edge);
  font: 1.1rem/1.45 var(--ui);
  white-space: pre-wrap;
  text-align: left;
}
.streak { font-weight: 600; }
.share-fallback { width: 100%; min-height: 8rem; font: .9375rem/1.4 var(--ui); padding: .5rem; border-radius: .5rem; }

/* ---------- empty / fallback screen ---------- */

.fallback { text-align: center; padding: 2.5rem 0 1rem; }
.fallback h2 { font: 400 1.9rem/1.15 var(--display); margin: 0 0 .75rem; }
.fallback p { margin: 0 auto .75rem; max-width: 22rem; color: var(--ink-soft); }
.fallback .loom {
  width: 9rem; height: 6rem; margin: 0 auto 1.5rem; display: block;
  stroke-linecap: round; fill: none;
}
.noscript { padding: 2rem 1rem; text-align: center; }

/* ---------- motion ---------- */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes settle {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}
.board.shake { animation: shake .36s ease-out; }
.cell.pop::before { animation: settle .4s ease-out; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
  .cell.is-sel::before { transform: none; }
  /* motion-free miss feedback: a brief outline flash instead of a shake */
  .board.shake { outline: 3px dashed var(--madder); outline-offset: 6px; border-radius: 1rem; }
}

@media (min-height: 760px) and (min-width: 480px) {
  .wordmark { height: 3rem; }
}

/* ---------- Devanagari mode ----------
   Never letter-space or uppercase Devanagari: spacing breaks the shirorekha
   (the headline joining letters). Line-height leaves room for matras above
   (ि ी े ै ँ) and below (ु ू ृ). */
[data-script="devanagari"] .cell {
  font: 700 clamp(1.15rem, 5.8vw, 1.55rem)/1 var(--deva);
  letter-spacing: 0;
}
/* Noto Devanagari reserves headroom for top matras; nudge glyphs down so the
   shirorekha body sits optically centred in the tile. */
[data-script="devanagari"] .cell > span { padding-top: .2em; }
[data-script="devanagari"] .readout-word:not(.is-empty) {
  font: 700 1.5rem/1.35 var(--deva);
  letter-spacing: 0;
}
[data-script="devanagari"] .theme-title {
  font: 700 clamp(1.7rem, 7.5vw, 2.2rem)/1.3 var(--deva);
}
[data-script="devanagari"] .found-list li:not(.empty) {
  font: 700 1rem/1.8 var(--deva);
}
[data-script="devanagari"] .bonus-line span { font-family: var(--deva); font-weight: 700; }
