/*
 * പര്യായം · Paryayam. The colours and the page's texture come from the look in
 * use (shared/looks.css); this file adds green for a word found and amber for a
 * near miss. Type: Baloo Chettan 2 for the word and the tiles, Anek Malayalam for
 * the rest.
 */
:root {
  --bg: #F7F0E0;
  --surface: #FFFCF3;
  --ink: #2A1C0E;
  --ink-soft: #6A5641;
  --line: #E5D5B3;
  --line-strong: #B39A6C;
  --key: #EFE2C4;
  --gold: #B8862B;
  --accent: #B0392B;
  --overlay: rgba(42, 28, 14, 0.45);
  --good: #2F6B3A;
  --good-bg: #E3EFD9;
  --warn: #8A5A00;
  --on-state: #FFFFFF;
  --shadow: 0 18px 50px rgba(14, 26, 20, 0.25);
  --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;
}
html[data-mode="dark"] {
  --good: #9BD08A;
  --good-bg: color-mix(in srgb, #4E9A52 24%, var(--surface));
  --warn: #E4B24C;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
html[data-mode="light"] { --good-bg: color-mix(in srgb, #4E9A52 18%, var(--surface)); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 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; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 600px; margin: 0 auto; padding: 0 16px 40px; }

/* Masthead, edged like a kasavu border */
.masthead {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  padding-block: 10px 8px;
  border-bottom: 5px double var(--gold);
}
.brand { display: flex; align-items: baseline; gap: 6px; margin-right: auto; min-width: 0; }
.name { margin: 0; font: 800 27px/1.1 var(--font-display); }
.edition { font-size: 13px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.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;
}

/* The word */
.prompt { text-align: center; padding: 18px 8px 8px; }
.ask { margin: 0; color: var(--ink-soft); font-size: 15px; }
.word {
  margin: 4px 0 2px;
  font: 700 clamp(44px, 13vw, 68px)/1.15 var(--font-display);
  color: var(--accent);
  overflow-wrap: anywhere;
}
.meta { margin: 0; color: var(--ink-soft); font-size: 15px; }
.latin { font-style: italic; }
.gloss { margin: 6px auto 0; max-width: 32em; font-size: 15px; }
.gloss b { font-weight: 600; }

/* The five to find */
.targets { margin: 8px 0 14px; }
.progress { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 2px 8px; font-size: 15px; }
.progress strong { font: 800 24px/1 var(--font-display); color: var(--gold); margin: 0 2px; }
.bonus-count { padding: 3px 12px; border-radius: 999px; border: 1px dashed var(--line-strong); color: var(--ink-soft); }
.bonus-count strong { font-size: 18px; color: var(--accent); }
.tiles { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tile {
  flex: 1 1 auto; min-width: 60px; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 12px; border: 2px solid var(--line); background: var(--surface); padding: 6px 4px; text-align: center; line-height: 1.2;
}
.tile .ml { font-weight: 700; font-size: 17px; white-space: nowrap; }
.tile .lat { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.tile.empty { border-style: dashed; }
.tile.empty .ml { color: var(--line-strong); font-size: 22px; }
.tile.hint { border-color: var(--gold); border-style: dashed; }
.tile.hint .ml { letter-spacing: 0.08em; }
.tile.found { background: var(--good-bg); border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.tile.missed { background: var(--key); border-color: var(--line-strong); }
.tile.missed .ml { color: var(--ink-soft); }
.tile.fresh { animation: pop 0.5s; }

/* Typing */
.guess { display: flex; gap: 8px; }
.field { position: relative; flex: 1; min-width: 0; display: flex; }
.guess input {
  flex: 1; min-width: 0; font-size: 18px; padding: 12px 14px;
  border: 2px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink);
}
.guess input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 25%, transparent); }
.guess input:disabled { opacity: 0.55; }
.guess.shake { animation: shake 0.35s; }

/* Suggestions under the box, as in a search engine */
.suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 5;
  list-style: none; margin: 0; padding: 4px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.suggest li { display: flex; align-items: baseline; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--key); }
.suggest .ml { font-weight: 600; font-size: 18px; }
.suggest .lat { color: var(--ink-soft); font-size: 13px; }
.suggest .tick { margin-left: auto; color: var(--good); font-weight: 700; }
.suggest li.got .ml { color: var(--ink-soft); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.feedback { min-height: 1.6em; margin: 8px 2px 0; font-size: 16px; }
.feedback.good { color: var(--good); font-weight: 600; }
.feedback.near { color: var(--good); }
.feedback.bad { color: var(--accent); }
.feedback.meh, .feedback.ask { color: var(--warn); }
.feedback.bonus { color: var(--accent); font-weight: 600; }
.feedback .yes { padding: 3px 12px; margin: 0 4px; font-size: 15px; background: var(--gold); border-color: var(--gold); color: #fff; }

/* Buttons */
.btn {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 12px;
  padding: 10px 14px; cursor: pointer; font-weight: 600; line-height: 1.2;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
html[data-mode="dark"] .btn.primary { color: #1A110A; }
.actions, .done-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.done-bar .btn { flex: 1 1 140px; min-height: 46px; }

/* Word lists */
.list-section { margin-top: 18px; }
.list-section h3, .list-section summary { margin: 0 0 8px; font-size: 17px; font-weight: 700; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.list-section summary { cursor: pointer; }
.chips { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; flex-direction: column; align-items: flex-start;
  background: var(--good-bg); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent);
  border-radius: 10px; padding: 4px 10px 3px; line-height: 1.25;
}
.chip .ml { font-weight: 600; font-size: 18px; }
.chip .lat { font-size: 12px; color: var(--ink-soft); }
.chip.fresh { animation: pop 0.5s; }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
.bonus .chip, .rest .chip { background: var(--surface); border: 1px dashed var(--line-strong); }
.rest .chip { padding: 2px 9px 1px; }
.rest .chip .ml { font-size: 16px; font-weight: 500; }

/* ----- 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;
  z-index: 1;
  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; color: var(--ink-soft); }

.result { margin-bottom: 18px; text-align: center; }
.verdict { margin: 4px 0 0; font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--good); }
.verdict.lost { color: var(--accent); }
.verdict-sub { margin: 0; color: var(--ink-soft); font-size: 14px; }
.answer-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 14px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.answer-word { font-family: var(--font-display); font-size: 28px; font-weight: 700; line-height: 1.2; color: var(--accent); }
.answer-five { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.answer-five li { display: flex; flex-direction: column; align-items: center; padding: 3px 10px 2px; border-radius: 8px; background: var(--key); line-height: 1.2; }
.answer-five li.got { background: var(--good-bg); }
.answer-five .ml { font-weight: 700; font-size: 17px; }
.answer-five .lat { font-size: 11px; color: var(--ink-soft); }

.numbers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.numbers div { display: flex; flex-direction: column-reverse; justify-content: flex-end; 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: 5px; }
.dist li { display: grid; grid-template-columns: 34px 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: 3px 8px 1px;
  border-radius: 4px;
  background: var(--line-strong);
  color: var(--bg);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}
.dist li.mine .bar { background: var(--good); }
.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; }
.share-actions { display: grid; margin-top: 16px; }
.share-actions .btn { min-height: 46px; }
.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: 420px) {
  .tiles { gap: 4px; }
  .tile { min-width: 54px; min-height: 58px; padding: 5px 6px; border-radius: 10px; }
  .tile .ml { font-size: 15px; }
  .tile .lat { font-size: 10px; }
  .btn { padding: 9px 11px; font-size: 15px; }
  .guess .btn.primary { padding: 0 12px; }
  .name { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .chip.fresh, .tile.fresh, .guess.shake { animation: none; }
}
