/*
 * താരനിര · Thaaranira
 * Same house style as വാക്ക്: lime-washed wall, backwater ink, kasavu brass,
 * banana-leaf green for a right guess and laterite red for a wrong one.
 * Baloo Chettan 2 for names on the cast list, Anek Malayalam for the rest.
 */
: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;
}

/* ----- Clues */
.play {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 14px 12px;
}
.prompt { margin-bottom: 10px; }
.ask {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
}
.ask-sub { margin: 2px 0 0; color: var(--ink-soft); font-size: 14px; }

.pips { list-style: none; display: flex; gap: 5px; margin: 0 0 14px; padding: 0; }
.pip {
  flex: 1;
  max-width: 34px;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
}
.pip[data-state="wrong"], .pip[data-state="skip"] { background: var(--wrong); }
.pip[data-state="right"] { background: var(--hit); }
.pip[data-state="open"] { background: var(--gold); }

.clues { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.clue {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 8px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.clue .num {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  padding-top: 2px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.clue .body { display: flex; flex-direction: column; min-width: 0; }
.clue .actor {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.clue .tried { font-size: 14px; font-weight: 600; line-height: 1.3; }
.clue[data-state="wrong"] .tried { color: var(--wrong); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.clue[data-state="wrong"] .tried::before { content: "✗"; display: inline-block; margin-right: 0.35em; text-decoration: none; }
.clue[data-state="skip"] .tried { color: var(--ink-soft); }
.clue[data-state="right"] { border-color: var(--hit); box-shadow: inset 5px 0 0 var(--hit); }
.clue[data-state="right"] .num { background: var(--hit); border-color: var(--hit); color: var(--on-state); }
.clue[data-state="right"] .tried { color: var(--hit); }
.clue[data-state="right"] .tried::before { content: "✓"; margin-right: 0.35em; }
.clue[data-state="open"] { border-color: var(--gold); box-shadow: 0 2px 0 var(--gold); }
.clue[data-state="unused"] { background: transparent; border-style: dashed; }
.clue[data-state="unused"] .num { border-color: var(--line-strong); color: var(--ink-soft); }
.clue[data-state="unused"] .actor { font-size: 18px; color: var(--ink-soft); }
.clue.new { animation: rise 380ms ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ----- The answer, once the game is over */
.reveal {
  margin-bottom: 14px;
  padding: 14px 16px 12px;
  border-top: 5px double var(--gold);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.reveal .verdict { margin: 0; font-size: 15px; font-weight: 700; color: var(--hit); }
.reveal .verdict.lost { color: var(--accent); }
.film {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.15;
  text-wrap: balance;
}
.film .year { font-family: var(--font-ui); font-size: 18px; font-weight: 600; color: var(--ink-soft); }
.reveal .alt { margin: 2px 0 0; font-size: 15px; color: var(--ink-soft); font-style: italic; }
.reveal .meta { margin: 6px 0 0; font-size: 14px; line-height: 1.4; }
.imdb {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px 2px;
  border-radius: 6px;
  background: var(--gold);
  color: #1B1405;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

/* ----- Guess box, with the film list opening above it */
.guess, .done {
  position: relative;
  padding-block: 10px 12px;
  border-top: 1px solid var(--line);
}
.guess-row { display: flex; gap: 8px; }
.guess-row.shake { animation: shake 420ms; }
#guess {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 4px 14px 0;
  border: 2px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  font-size: 17px;
}
#guess:focus { outline: none; border-color: var(--accent); }
#guess::placeholder { color: var(--ink-soft); opacity: 0.8; }
.go { min-width: 72px; }
.skip {
  display: block;
  margin: 8px auto 0;
  padding: 4px 10px 2px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% - 4px);
  z-index: 6;
  max-height: min(300px, 45vh);
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--pop-shadow);
}
.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; }
.option.tried .o-title { text-decoration: line-through; color: var(--ink-soft); }

.done { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 7;
  max-width: calc(100% - 16px);
  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; }
.example { display: grid; gap: 6px; margin-top: 14px; }
.example .clue { padding-block: 7px 5px; }
.example .actor { font-size: 18px; }
.example-note { margin: 6px 0 0; font-size: 14px; line-height: 1.4; }
.fine { margin: 10px 0 0; font-size: 14px; line-height: 1.45; }
.eras { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.eras th { padding: 0 6px 4px; font-size: 13px; text-align: left; line-height: 1.2; }
.eras td { padding: 5px 6px 3px; border-top: 1px solid var(--line); }
.eras th:not(:first-child), .eras td:not(:first-child) { text-align: right; }

.result { margin-bottom: 18px; text-align: center; }
.result .verdict { margin: 4px 0 0; font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--hit); }
.result .verdict.lost { color: var(--accent); }
.verdict-sub { margin: 0; color: var(--ink-soft); font-size: 14px; }
.answer-card {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  max-width: 100%;
  margin-top: 12px;
  padding: 10px 18px 8px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.answer-title { font-family: var(--font-display); font-size: 24px; font-weight: 700; line-height: 1.2; }
.answer-meta { color: var(--ink-soft); font-size: 14px; }

.numbers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.numbers div { display: flex; flex-direction: column-reverse; align-items: center; text-align: center; }
.numbers dd { margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.numbers dt { font-size: 12px; line-height: 1.25; }
.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.dist li { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.dist .try { font-size: 14px; font-weight: 600; text-align: right; }
.dist .bar {
  display: block;
  width: var(--w);
  min-width: 26px;
  padding: 2px 8px 0;
  border-radius: 4px;
  background: var(--miss);
  color: var(--on-state);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}
.dist li.mine .bar { background: var(--hit); }
.next {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.next strong { font-family: var(--font-display); font-size: 24px; font-variant-numeric: tabular-nums; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.btn {
  min-height: 46px;
  padding: 6px 10px 3px;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary { background: var(--hit); color: var(--on-state); }
.btn.ghost { background: var(--key); color: var(--ink); }
.share-fallback {
  width: 100%;
  margin-top: 12px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 var(--font-ui);
  resize: none;
}

@media (max-width: 380px) {
  .name { font-size: 24px; }
  .modes button { padding-inline: 8px; font-size: 13px; }
  .clue .actor { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
