:root {
  --paper: #fbf8ef;
  --line: #c9d8ee;
  --margin: #e8828a;
  --ink: #1f3a8a;
  --ink-soft: #4a62a8;
  --text: #1c2340;
  --muted: #5b6382;
  --red: #e5383b;
  --red-soft: #ffd6d6;
  --heat1: #e5383b;   /* closest */
  --heat2: #f4845f;
  --heat3: #f7b267;
  --heat4: #fde4a5;   /* far */
  --win: #2fb36b;
  --win-soft: #d5f5e2;
  --land: #fffdf6;
  --water: transparent;
  --card: rgba(255, 255, 255, 0.82);
  --shadow: 3px 3px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 38px, var(--margin) 38px, var(--margin) 40px, transparent 40px),
    repeating-linear-gradient(180deg, transparent 0, transparent 31px, var(--line) 31px, var(--line) 32px);
  color: var(--text);
  font-family: "Patrick Hand", "Comic Sans MS", system-ui, sans-serif;
  font-size: 20px;
  line-height: 1.35;
  min-height: 100vh;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 40px 52px;
}

a { color: var(--ink); }

/* ---------- header ---------- */
.top { text-align: center; margin-bottom: 14px; }
.top h1 {
  font-family: "Archivo Black", Arial Black, sans-serif;
  font-size: clamp(30px, 7vw, 46px);
  color: var(--ink);
  margin: 6px 0 2px;
  letter-spacing: 0.5px;
  transform: rotate(-1.2deg);
}
.top h1::after {
  content: "";
  display: block;
  height: 12px;
  margin: -14px auto 0;
  width: min(90%, 420px);
  background: var(--red-soft);
  border-radius: 6px;
  z-index: -1;
  position: relative;
}
.sub { margin: 6px 0 0; color: var(--muted); }
.daynum { margin: 2px 0 0; color: var(--ink-soft); font-size: 17px; }

/* ---------- cards ---------- */
.card {
  position: relative;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: 14px 18px 12px 20px;
  box-shadow: var(--shadow);
  padding: 22px 18px 16px;
  margin: 18px 0;
}
.stamp {
  position: absolute;
  top: -14px;
  left: 14px;
  font-family: "Archivo Black", Arial Black, sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  background: var(--ink);
  color: #fff;
  padding: 3px 10px;
  border-radius: 6px;
  transform: rotate(-2deg);
}
.stamp.red { background: var(--red); }
.law {
  margin: 0;
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1.3;
  color: var(--text);
}

/* ---------- map ---------- */
.map-wrap {
  position: relative;
  border: 2.5px solid var(--ink);
  border-radius: 16px 12px 18px 14px;
  background: #e6eefa;
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}
#map { display: block; width: 100%; height: auto; aspect-ratio: 1.6; cursor: grab; }
#map:active { cursor: grabbing; }
#map .country {
  fill: var(--land);
  stroke: var(--ink);
  stroke-width: 0.6px;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  transition: fill 0.35s ease;
}
#map .country:hover { fill: #eef3ff; }
#map .country.h1 { fill: var(--heat1); }
#map .country.h2 { fill: var(--heat2); }
#map .country.h3 { fill: var(--heat3); }
#map .country.h4 { fill: var(--heat4); }
#map .country.win { fill: var(--win); stroke-width: 1.6px; animation: pulse 1s ease 2; }
#map .country.answer { fill: var(--win); stroke-width: 1.6px; }
#map .dot { stroke: var(--ink); stroke-width: 2px; vector-effect: non-scaling-stroke; }
@keyframes pulse { 50% { fill: #7fe0a8; } }

.map-tools {
  position: absolute; right: 8px; top: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.icon-btn {
  width: 36px; height: 36px;
  font: 22px/1 "Archivo Black", Arial Black, sans-serif;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  cursor: pointer;
}
.legend {
  position: absolute; left: 8px; bottom: 6px;
  display: flex; align-items: center; gap: 4px;
  font-size: 15px; color: var(--ink);
  background: rgba(255,255,255,0.8);
  padding: 2px 8px; border-radius: 8px;
}
.sw { display: inline-block; width: 16px; height: 12px; border: 1.5px solid var(--ink); border-radius: 3px; }
.s1 { background: var(--heat1); } .s2 { background: var(--heat2); }
.s3 { background: var(--heat3); } .s4 { background: var(--heat4); }

/* ---------- guessing ---------- */
.guess-box { margin: 18px 0 6px; }
.input-row { display: flex; gap: 10px; }
.ac { position: relative; flex: 1; min-width: 0; }
#guess {
  width: 100%;
  font: inherit;
  font-size: 22px;
  padding: 10px 14px;
  color: var(--text);
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  outline: none;
}
#guess:focus { box-shadow: 0 0 0 4px var(--red-soft); }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  z-index: 10;
  margin: 0; padding: 4px;
  list-style: none;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  max-height: 240px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.suggest li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--red-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: "Archivo Black", Arial Black, sans-serif;
  font-size: 17px;
  color: #fff;
  background: var(--red);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn.ghost { background: #fff; color: var(--ink); }
.hint { color: var(--muted); font-size: 17px; margin: 8px 2px 0; }
.link-btn {
  background: none; border: none; padding: 4px 2px;
  font: inherit; font-size: 17px;
  color: var(--ink-soft); text-decoration: underline; cursor: pointer;
}

/* ---------- guesses ---------- */
.guesses h3 {
  font-family: "Archivo Black", Arial Black, sans-serif;
  font-size: 18px; color: var(--ink);
  margin: 18px 0 6px;
}
#guessList { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#guessList li {
  display: grid;
  grid-template-columns: 22px 1fr auto 28px;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 7px 12px;
  animation: pop 0.25s ease;
}
#guessList .chip { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--ink); }
#guessList .name { font-size: 21px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#guessList .km { color: var(--ink); font-size: 19px; }
#guessList .dir { font-size: 22px; text-align: center; display: inline-block; }
#guessList li.win { background: var(--win-soft); border-color: var(--win); }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }

/* ---------- end screen ---------- */
.end { text-align: center; padding-top: 26px; }
.end .stamp { left: 50%; transform: translateX(-50%) rotate(-2deg); }
.stamp.green { background: var(--win); }
.end h2 {
  font-family: "Archivo Black", Arial Black, sans-serif;
  color: var(--ink);
  margin: 6px 0 2px;
  font-size: clamp(30px, 8vw, 44px);
}
.end-sub { margin: 0; font-size: 22px; }
.emoji { font-size: 24px; letter-spacing: 2px; margin: 6px 0 14px; }
.end-law {
  margin: 0 0 12px;
  padding: 10px 14px;
  font-size: 20px;
  text-align: left;
  background: var(--red-soft);
  border-left: 4px solid var(--red);
  border-radius: 6px;
}
.end-story { text-align: left; margin: 0 0 8px; }
.src { font-size: 17px; color: var(--muted); word-break: break-word; text-align: left; margin: 0; }

/* "how everyone did" graph: single series, the player's bar is the only coloured one */
.compare {
  margin: 18px 0 0;
  padding: 14px 12px 10px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  text-align: left;
}
.compare h3 {
  font-family: "Archivo Black", Arial Black, sans-serif;
  font-size: 17px; color: var(--ink);
  margin: 0 0 2px;
}
.compare-head { margin: 0 0 10px; font-size: 20px; }
.compare-head b { color: var(--ink); font-family: "Archivo Black", Arial Black, sans-serif; font-weight: normal; }
.axis-note { margin: 0 0 2px; width: 64px; text-align: right; font-size: 13px; color: var(--muted); line-height: 1.1; }
.bars { display: grid; gap: 2px; }
.bar-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  border-radius: 6px;
  outline: none;
  cursor: default;
}
.bar-row:hover, .bar-row:focus-visible { background: #f1f4fb; }
.bar-label { text-align: right; font-size: 16px; color: var(--muted); }
.bar-row.mine .bar-label { color: var(--text); font-weight: bold; }
.bar-track { position: relative; display: flex; align-items: center; height: 18px; }
.bar {
  display: block;
  height: 100%;
  background: #b9c6e6;
  border-radius: 0 4px 4px 0;
  transition: width 0.6s ease;
}
.bar-row.gu .bar { background: #d4d7e0; }
.bar-row.mine .bar { background: var(--red); }
.bar-row.mine.gu .bar { background: var(--muted); }
.bar-you {
  margin-left: 6px;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
}
.compare-read { margin: 8px 0 0; font-size: 15px; color: var(--muted); min-height: 1.3em; }

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin: 18px 0 14px;
}
.stats div {
  display: flex; flex-direction: column; align-items: center;
  border: 2px solid var(--ink); border-radius: 12px;
  background: #fff; padding: 8px 4px;
}
.stats b { font-family: "Archivo Black", Arial Black, sans-serif; font-size: 24px; color: var(--ink); }
.stats span { font-size: 15px; color: var(--muted); line-height: 1.1; }

.tomorrow {
  border: 2.5px dashed var(--ink);
  border-radius: 14px;
  padding: 12px 10px 10px;
  background: rgba(255, 255, 255, 0.7);
}
.tomorrow p { margin: 0; }
.tomorrow-head { font-family: "Archivo Black", Arial Black, sans-serif; color: var(--red); font-size: 20px; }
.countdown-label { margin-top: 8px !important; color: var(--muted); font-size: 16px; }
.countdown {
  font-family: "Archivo Black", Arial Black, sans-serif;
  font-size: 34px; color: var(--ink); letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 16px 0 4px; }

.social p { margin: 10px 0 8px; color: var(--muted); font-size: 18px; }
.social-row { display: flex; justify-content: center; gap: 16px; }
.soc {
  width: 56px; height: 56px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.12s ease;
}
.soc svg { width: 30px; height: 30px; }
.soc:hover { transform: translateY(-2px) rotate(-3deg); }
.soc:active { transform: translate(2px, 2px); box-shadow: none; }
.soc.ig { background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 90%); }
.soc.fb { background: #1877f2; }

/* once today's law is done: no more guessing */
body.ended .law-card,
body.ended .guess-box,
body.ended .legend { display: none; }
body.ended #map .country { cursor: default; }
body.ended #map .country:hover { fill: var(--land); }
body.ended #map .country.h1:hover { fill: var(--heat1); }
body.ended #map .country.h2:hover { fill: var(--heat2); }
body.ended #map .country.h3:hover { fill: var(--heat3); }
body.ended #map .country.h4:hover { fill: var(--heat4); }
body.ended #map .country.win:hover, body.ended #map .country.answer:hover { fill: var(--win); }

.foot { text-align: center; color: var(--muted); font-size: 16px; margin-top: 28px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 12px;
  font-size: 18px; z-index: 50;
  max-width: calc(100% - 32px);
}

@media (max-width: 520px) {
  body { font-size: 19px; }
  /* centered with equal gutters; cards sit on top of the red margin line */
  .page { padding: 12px 16px 32px; }
  .card, .map-wrap, #guessList li, #guess { position: relative; z-index: 1; }
  .card { background: #fffef9; }
  .top h1 { font-size: 27px; transform: rotate(-1deg); }
  .top h1::after { margin-top: -12px; height: 10px; }
  .sub { font-size: 17px; }
  #map { aspect-ratio: 1.3; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .end-sub { font-size: 20px; }
  .map-tools { gap: 4px; right: 6px; top: 6px; }
  .icon-btn { width: 30px; height: 30px; font-size: 18px; border-radius: 8px; }
  .legend { font-size: 13px; }
  .btn { font-size: 15px; padding: 10px 12px; }
  .result-actions .btn { flex: 1 1 100%; }
}
