/*
 * മണ്ഡലം · Kerala Guesser
 * The house style of the Keralam Times games (lime-washed wall, backwater
 * ink, kasavu brass) around a map drawn like a school atlas: a lagoon-blue sea
 * with shallows along the coast, sand-coloured neighbours, and Kerala shaded
 * from coastal-plain green to Western Ghats green. No district lines: the
 * only line is the state's own edge.
 */
: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);
  --sea: #BFDCDA;
  --sea-deep: #9CC6C7;
  --shallow-far: #CFE6E1;
  --shallow-near: #E4F0E6;
  --neighbour: #E6DDC5;
  --neighbour-ink: #A1977C;
  --kerala-coast: #B9D98F;
  --kerala-mid: #8DC174;
  --kerala-ghats: #3F7E4F;
  --kerala-edge: #2F5E3B;
  --target: #A3462B;
  --target-hit: #257A4B;
  --pin: #C29B2A;
  --pin-ink: #16271F;
  --sea-ink: #6FA2A6;
  --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);
    --sea: #12323A;
    --sea-deep: #0C252C;
    --shallow-far: #16404A;
    --shallow-near: #1D4D56;
    --neighbour: #26291F;
    --neighbour-ink: #6F705E;
    --kerala-coast: #5E8F4E;
    --kerala-mid: #477C45;
    --kerala-ghats: #23502F;
    --kerala-edge: #A9D39B;
    --target: #E38561;
    --target-hit: #57C08A;
    --pin: #E0B84A;
    --pin-ink: #0F1713;
    --sea-ink: #4F8490;
    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);
  --sea: #12323A;
  --sea-deep: #0C252C;
  --shallow-far: #16404A;
  --shallow-near: #1D4D56;
  --neighbour: #26291F;
  --neighbour-ink: #6F705E;
  --kerala-coast: #5E8F4E;
  --kerala-mid: #477C45;
  --kerala-ghats: #23502F;
  --kerala-edge: #A9D39B;
  --target: #E38561;
  --target-hit: #57C08A;
  --pin: #E0B84A;
  --pin-ink: #0F1713;
  --sea-ink: #4F8490;
  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;
}

/* ----- What to find */
.prompt {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding-block: 10px 8px;
}
.target { min-width: 0; }
.find { margin: 0; color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.prompt.overview .find { visibility: hidden; }
.seat { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; }
.tally { flex: none; text-align: right; }
.round { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.points { margin: 2px 0 0; color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ----- The map */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.map-wrap {
  position: relative;
  flex: 1;
  min-height: 280px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--sea);
  box-shadow: inset 0 0 0 1.5px var(--line), 0 0 0 4px var(--bg), 0 0 0 5.5px var(--gold);
}
.map { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.shallow { fill: none; stroke-linejoin: round; }
.shallow.far { stroke: var(--shallow-far); stroke-width: 9; }
.shallow.near { stroke: var(--shallow-near); stroke-width: 3.5; }
.land { fill: var(--neighbour); }
.kerala-edge { fill: none; stroke: var(--kerala-edge); stroke-width: 1.1; stroke-linejoin: round; vector-effect: non-scaling-stroke; opacity: 0.8; }
.labels { pointer-events: none; }
.sea-label { fill: var(--sea-ink); font-family: var(--font-display); font-size: 13px; font-weight: 700; letter-spacing: 0.08em; }
.sea-label-en { font-family: var(--font-ui); font-size: 7px; letter-spacing: 0.5em; font-weight: 600; }
.state-label { fill: var(--neighbour-ink); font-family: var(--font-ui); font-size: 8px; font-weight: 600; letter-spacing: 0.3em; }
/* Spacing letters apart breaks up Malayalam conjuncts */
html[data-lang="ml"] .sea-label, html[data-lang="ml"] .state-label { letter-spacing: 0; }
html[data-lang="ml"] .state-label { font-size: 9px; }
.target { fill: var(--target); fill-opacity: 0.32; stroke: var(--target); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.target.hit { fill: var(--target-hit); stroke: var(--target-hit); }
.reach { stroke: var(--pin-ink); stroke-width: 2; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.edge-dot { fill: var(--target); stroke: var(--surface); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.pin path { fill: var(--pin); stroke: var(--pin-ink); stroke-width: 1.6; }
.pin .pin-eye { fill: var(--pin-ink); }
.pin.live { animation: drop 260ms cubic-bezier(0.3, 1.6, 0.5, 1) both; }
@keyframes drop { from { opacity: 0; } }
.seat-label { fill: var(--ink); font-family: var(--font-ui); font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }

.compass, .scale, .zoom, .hint { position: absolute; }
.compass {
  top: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  pointer-events: none;
}
.compass::before {
  content: "";
  position: absolute;
  top: -7px;
  border: 6px solid transparent;
  border-bottom: 8px solid var(--accent);
  border-top: 0;
}
.scale { left: 12px; bottom: 12px; display: grid; gap: 2px; pointer-events: none; }
.scale .bar { height: 6px; border: 2px solid var(--ink); border-top: 0; }
.scale .label { font-size: 11px; font-weight: 700; color: var(--ink); text-shadow: 0 0 3px var(--sea); }
.zoom { top: 10px; right: 10px; display: grid; gap: 4px; }
.zoom button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.hint {
  left: 50%;
  bottom: 44px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px 4px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0.88;
}

/* ----- Guess and result */
.bar { display: flex; align-items: center; gap: 12px; }
.bar .btn { flex: none; min-width: 150px; }
.result { flex: 1; min-width: 0; }
.result p { margin: 0; }
.r-head { font-family: var(--font-display); font-size: 19px; font-weight: 800; line-height: 1.2; color: var(--target); }
.result[data-hit="true"] .r-head { color: var(--hit); }
.r-sub { color: var(--ink-soft); font-size: 13px; line-height: 1.35; }
.btn {
  min-height: 48px;
  padding: 6px 14px 3px;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--hit); color: var(--on-state); }
.btn.primary:disabled { background: var(--key); color: var(--ink-soft); cursor: default; }
.btn.ghost { background: var(--key); color: var(--ink); }
.bar .btn:only-child { flex: 1; }
.link {
  margin-top: 12px;
  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;
}

/* ----- Summary */
.total { margin: 0; font-size: 18px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.total strong { font-family: var(--font-display); font-size: 48px; color: var(--ink); line-height: 1; }
.verdict-sub { margin: -8px 0 12px; color: var(--ink-soft); font-size: 15px; }
.rounds { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.round-row { display: grid; grid-template-columns: 22px 1fr auto 36px; align-items: center; gap: 8px; padding: 5px 0 3px; border-bottom: 1px solid var(--line); }
.rr-name { min-width: 0; overflow-wrap: anywhere; }
.rr-km { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.rr-pts { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.record { margin: 12px 0 0; color: var(--ink-soft); font-size: 13px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.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;
}

/* ----- 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; }
}


.fine a { color: inherit; }

@media (max-width: 420px) {
  .brand .edition { display: none; }
}

@media (max-width: 380px) {
  .name { font-size: 24px; }
  .seat { font-size: 24px; }
  .bar .btn { min-width: 120px; }
}
