/*
 * അന്താക്ഷരി · Antakshari helper
 * Same house style as the Keralam Times games: lime-washed wall, backwater
 * ink, kasavu brass. The alphabet is a grid of tiles with counts, like the
 * aksharamaala in വാക്ക്; laterite red marks letters that are hard to follow.
 */
:root {
  --bg: #F3F5EF;
  --surface: #FFFFFF;
  --ink: #16271F;
  --ink-soft: #56675D;
  --line: #CAD3CB;
  --line-strong: #8C9B91;
  --key: #DEE5DC;
  --hit: #257A4B;
  --miss: #6E7A73;
  --wrong: #A3462B;
  --on-state: #FFFFFF;
  --accent: #A3462B;
  --gold: #C29B2A;
  --overlay: rgba(14, 26, 20, 0.5);
  --shadow: 0 18px 50px rgba(14, 26, 20, 0.25);
  --pop-shadow: 0 -8px 28px rgba(14, 26, 20, 0.18);
  --font-ui: "Anek Malayalam", "Noto Sans Malayalam", "Manjari", "Kartika", system-ui, sans-serif;
  --font-display: "Baloo Chettan 2", "Anek Malayalam", "Noto Sans Malayalam", "Kartika", system-ui, sans-serif;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1713;
    --surface: #17221C;
    --ink: #E3EBE5;
    --ink-soft: #98A99F;
    --line: #2E3C34;
    --line-strong: #5E7065;
    --key: #28352E;
    --hit: #2C8A55;
    --miss: #3E4943;
    --wrong: #E38561;
    --accent: #E38561;
    --gold: #C9A43A;
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
    --pop-shadow: 0 -8px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0F1713;
  --surface: #17221C;
  --ink: #E3EBE5;
  --ink-soft: #98A99F;
  --line: #2E3C34;
  --line-strong: #5E7065;
  --key: #28352E;
  --hit: #2C8A55;
  --miss: #3E4943;
  --wrong: #E38561;
  --accent: #E38561;
  --gold: #C9A43A;
  --overlay: rgba(0, 0, 0, 0.6);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --pop-shadow: 0 -8px 28px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding-inline: 16px;
  display: flex;
  flex-direction: column;
}

/* ----- Header, edged like a kasavu border */
.masthead {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding-block: 10px 8px;
  border-bottom: 5px double var(--gold);
}
.switches { flex-basis: 100%; display: flex; gap: 8px; }
.brand { display: flex; align-items: baseline; gap: 6px; margin-right: auto; min-width: 0; }
.name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 27px;
  line-height: 1.1;
}
.edition { font-size: 13px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.modes { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--key); }
.modes button {
  border: 0;
  padding: 5px 11px 3px;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.modes button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); }
.tools { display: flex; gap: 4px; }
.icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

/* ----- Letters */
.play {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.ask, .results, .said { display: flex; flex-direction: column; gap: 10px; }
.ask label, .said h2 { font-weight: 700; font-size: 15px; }
.last { position: relative; display: grid; gap: 6px; }
#last-input, #prefix {
  width: 100%;
  height: 46px;
  padding: 4px 14px 0;
  border: 2px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
}
#last-input:focus, #prefix:focus { outline: none; border-color: var(--accent); }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 6;
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}
.option { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; padding: 8px 10px 6px; border-radius: 8px; cursor: pointer; }
.option[aria-selected="true"] { background: var(--key); }
.o-title { font-weight: 600; font-size: 16px; line-height: 1.25; }
.o-year { color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; }
.o-alt { grid-column: 1 / -1; color: var(--ink-soft); font-size: 13px; font-style: italic; }

.prefix-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
#prefix { height: 44px; font-family: var(--font-display); font-size: 22px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.clear { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--key); font-size: 22px; line-height: 1; cursor: pointer; }

.letters { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
.letter {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 4px 0 2px;
  border: 0;
  border-radius: 8px;
  background: var(--key);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.l-char { font-family: var(--font-display); font-size: 19px; font-weight: 700; line-height: 1.1; }
.l-count { font-size: 11px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.letter.few .l-count { color: var(--wrong); }
.letter.none { opacity: 0.45; }
.letter[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.letter[aria-pressed="true"] .l-count { color: var(--bg); opacity: 0.8; }
.letter:active { transform: translateY(1px); }

/* ----- Filters */
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--hit); }
select {
  height: 36px;
  padding: 0 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
}

/* ----- Films */
.results-title { margin: 0; padding-top: 12px; border-top: 5px double var(--gold); font-family: var(--font-display); font-size: 20px; line-height: 1.25; text-wrap: balance; }
.films { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.film {
  display: grid;
  gap: 8px;
  padding: 10px 12px 8px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.f-main { min-width: 0; display: grid; gap: 1px; }
.f-main p { margin: 0; }
.f-title { font-family: var(--font-display); font-size: 19px; font-weight: 700; line-height: 1.2; overflow-wrap: break-word; }
.f-year { color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; }
.f-alt { color: var(--ink-soft); font-size: 13px; font-style: italic; }
.f-people { color: var(--ink-soft); font-size: 13px; line-height: 1.35; }
.f-side { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.f-ends { padding: 2px 8px 0; border-radius: 999px; background: var(--key); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.f-ends[data-level="trap"] { background: var(--gold); color: #1B1405; }
.f-ends[data-level="dead"] { background: var(--wrong); color: var(--on-state); }
.said-btn {
  padding: 4px 10px 2px;
  border: 1.5px solid var(--hit);
  border-radius: 999px;
  background: transparent;
  color: var(--hit);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.said-btn:hover { background: var(--hit); color: var(--on-state); }
.more { align-self: center; min-width: 200px; }

.said-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.said h2 { margin: 0; font-family: var(--font-ui); }
.said-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.said-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 1px 10px; border-radius: 999px; background: var(--key); font-size: 13px; }
.unsay { width: 24px; height: 24px; border: 0; border-radius: 50%; background: transparent; font-size: 16px; line-height: 1; cursor: pointer; }
.link {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.btn {
  min-height: 44px;
  padding: 6px 12px 3px;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn.ghost { background: var(--key); color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 9px 14px 7px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity 160ms, transform 160ms;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ----- Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  background: var(--overlay);
}
.sheet:focus { outline: none; }
.sheet {
  position: relative;
  width: min(100%, 440px);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 20px 20px;
  border-top: 5px double var(--gold);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.close {
  position: absolute;
  top: 8px; right: 8px;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.sheet h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.2;
  text-wrap: balance;
}
.sheet h3 { margin: 18px 0 8px; font-size: 16px; }
.rules { margin: 0; padding-left: 18px; display: grid; gap: 10px; font-size: 15px; line-height: 1.45; }
.fine { margin: 10px 0 0; font-size: 14px; line-height: 1.45; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}


@media (max-width: 380px) {
  .name { font-size: 24px; }
  .letters { gap: 4px; }
  .l-char { font-size: 18px; }
}
