/*
 * പി.എസ്.സി. ക്വിസ് · PSC Quiz
 * Same house style as the other Play Keralam games: lime-washed wall,
 * backwater ink, kasavu brass, banana-leaf green for right and laterite red
 * for wrong. The question sits on a paper card with its four answers below,
 * lettered A to D like an OMR sheet.
 */
: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);
  --paper: #FBF8EE;
  --try2: #B8820F;
  --try3: #C8651E;
  --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);
    --paper: #1D2419;
    --try2: #C9971F;
    --try3: #D8783A;
    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);
  --paper: #1D2419;
  --try2: #C9971F;
  --try3: #D8783A;
  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);
}
.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; }
.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 question */
.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 16px;
}
.loading, .failed { margin: 40px 0; text-align: center; color: var(--ink-soft); font-size: 16px; }
.failed .btn { margin-top: 8px; padding-inline: 20px; }
#round { display: flex; flex-direction: column; gap: 10px; }
.status { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.ask {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
}
.ask-sub {
  display: inline-block;
  margin: 4px 0 0;
  padding: 3px 10px 1px;
  border-radius: 999px;
  background: var(--key);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
.count { margin: 0; color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; }
.count strong { color: var(--ink); font-family: var(--font-display); font-size: 24px; }

.pips { list-style: none; display: flex; gap: 5px; margin: 0; padding: 0; }
.pip { flex: 1; height: 6px; border-radius: 999px; background: var(--line); }
.pip[data-state="right"] { background: var(--hit); }
.pip[data-state="wrong"] { background: var(--wrong); }
.pip[data-state="open"] { background: var(--ink-soft); }

.question {
  position: relative;
  margin: 4px 0 0;
  padding: 16px 16px 14px 20px;
  border: 1.5px solid var(--line);
  border-left: 5px double var(--gold);
  border-radius: 4px 12px 12px 4px;
  background: var(--paper);
  font-family: var(--font-ui);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.choices { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 8px; }
.choice {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 8px 14px 6px 10px;
  border: 2px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: border-color 120ms, background-color 120ms, transform 120ms;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:active:not(:disabled) { transform: scale(0.99); }
.choice .letter {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  padding-top: 2px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
}
.choice:disabled { cursor: default; }
.choice[data-state="right"] { border-color: var(--hit); background: color-mix(in srgb, var(--hit) 14%, var(--surface)); }
.choice[data-state="right"] .letter { border-color: var(--hit); background: var(--hit); color: var(--on-state); }
.choice[data-state="right"] .letter::before { content: "✓"; }
.choice[data-state="wrong"] { border-color: var(--wrong); background: color-mix(in srgb, var(--wrong) 14%, var(--surface)); }
.choice[data-state="wrong"] .letter { border-color: var(--wrong); background: var(--wrong); color: var(--on-state); }
.choice[data-state="wrong"] .letter::before { content: "✗"; }
.choice[data-state="right"] .letter span, .choice[data-state="wrong"] .letter span { display: none; }
.choice[data-state="dim"] { opacity: 0.55; }

.answer {
  padding: 12px 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);
  animation: rise 300ms ease-out both;
}
.answer .verdict { margin: 0; font-size: 16px; font-weight: 700; color: var(--hit); }
.answer .verdict.lost { color: var(--accent); }
.because { margin: 6px 0 0; font-size: 16px; line-height: 1.5; }
.report { display: inline-block; margin-top: 8px; color: var(--ink-soft); font-size: 13px; font-weight: 600; text-underline-offset: 3px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.dock {
  display: flex;
  gap: 10px;
  padding-block: 10px 12px;
  border-top: 1px solid var(--line);
}
.dock .btn { flex: 1; }

.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); }

/* ----- The day's questions, once played */
.recap { display: flex; flex-direction: column; gap: 12px; }
.recap-score {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.recap-score strong { font-family: var(--font-display); font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }
.recap-score span { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--hit); }
.recap h2 { margin: 0; font-family: var(--font-display); font-size: 20px; }
.recap-note { margin: -10px 0 0; color: var(--ink-soft); font-size: 14px; }
.recap-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recap-item {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.recap-item summary {
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 7px;
  cursor: pointer;
  list-style: none;
}
.recap-item summary::-webkit-details-marker { display: none; }
.r-mark {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  padding-top: 2px;
  border-radius: 50%;
  color: var(--on-state);
  font-size: 13px;
  font-weight: 800;
}
.recap-item[data-state="right"] .r-mark { background: var(--hit); }
.recap-item[data-state="wrong"] .r-mark { background: var(--wrong); }
.r-body { display: grid; min-width: 0; }
.r-q { font-size: 15px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.recap-item:not([open]) .r-q { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.r-note { color: var(--ink-soft); font-size: 13px; }
.r-more { margin: 0; padding: 0 14px 12px 48px; font-size: 15px; line-height: 1.5; }
.r-more p { margin: 0 0 6px; }
.r-more .mine { color: var(--wrong); font-weight: 600; }
.r-more .right { color: var(--hit); font-weight: 700; }

/* ----- 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; }


.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: 20px 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; 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;
}

.fine.small { color: var(--ink-soft); font-size: 13px; }
.dist li { grid-template-columns: 24px 1fr; }

@media (max-width: 380px) {
  .name { font-size: 22px; }
  .question { font-size: 18px; }
  .choice { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ----- Today's date and "today in history" at the top of the page */
.today {
  margin: 0 0 12px;
  padding: 10px 14px 11px;
  border: 1.5px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: 10px;
  background: var(--paper);
}
.today-date { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.3; }
.today-head { margin: 6px 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.today-label { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.today-year { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.today-text { margin: 2px 0 0; font-size: 14.5px; line-height: 1.5; }
