/* GIS Day Globe Challenge
   Palette and lettering borrowed from nautical charts: buff land, pale blue
   water, dark ink, and the magenta charts use for annotations. */

@font-face {
  font-family: "Alegreya";
  font-style: italic;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/alegreya-latin-500-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Alegreya Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/alegreya-sans-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Alegreya Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/alegreya-sans-latin-700-normal.woff2") format("woff2");
}

:root {
  --paper: #f3f8f9;      /* deep water on a chart: almost white */
  --water: #cde4ec;      /* shallow water blue */
  --land: #ead9a2;       /* chart buff */
  --ink: #12293d;
  --ink-soft: #4a6076;
  --magenta: #b5177e;    /* chart annotation magenta */
  --magenta-dark: #8f0f62;
  --rule: #9fb6c2;
  --sheet: #ffffff;

  --serif: "Alegreya", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Alegreya Sans", "Gill Sans", "Trebuchet MS", system-ui, sans-serif;

  --t-small: 0.875rem;
  --t-body: 1.0625rem;
  --t-lead: 1.3125rem;
  --t-title: 1.75rem;
  --t-place: 2rem;
  --t-score: 3.5rem;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.4;
  font-variant-numeric: lining-nums;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body.game { overflow: hidden; position: fixed; inset: 0; }

[hidden] { display: none !important; }

h1, h2, p { margin: 0; }

button, input { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--magenta); outline-offset: 2px; }

/* ---------- Globe ---------- */

#globe {
  position: absolute;
  inset: 0;
  background: var(--paper);
  touch-action: none;
}
#globe canvas { outline: none; }

.zoom {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--sheet);
  z-index: 3;
}
.zoom button {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.zoom button + button { border-top: 1.5px solid var(--ink); }

/* Pins */
.pin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--magenta);
  box-shadow: 0 0 0 1.5px var(--ink);
}
.pin.answer {
  background: var(--ink);
  border-radius: 3px;
  transform: rotate(45deg);
}

/* ---------- Cards: a chart's title block, ink rule inside a paper margin ---------- */

.card {
  background: var(--sheet);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 0 0 4px var(--sheet), 0 0 0 5px var(--rule);
}

.panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px 16px max(20px, env(safe-area-inset-bottom));
  pointer-events: none;
  overflow-y: auto;
}
.panel > .card {
  pointer-events: auto;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 22px 20px 20px;
}
.panel.full { justify-content: flex-start; background: rgba(243, 248, 249, 0.88); }
.panel.full > .card { margin-top: max(12px, env(safe-area-inset-top)); }

.event {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: var(--t-title);
  line-height: 1.12;
  letter-spacing: 0.005em;
}
.lead { margin-top: 8px; font-size: var(--t-body); color: var(--ink-soft); max-width: 34em; }

form { margin-top: 18px; display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-weight: 700; font-size: var(--t-small); }
input[type="text"], input[type="email"] {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--paper);
  font-size: 1.0625rem;  /* 17px: no zoom-on-focus on iOS */
  font-weight: 400;
}
.name-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fineprint { font-size: var(--t-small); color: var(--ink-soft); }
.error { color: var(--magenta-dark); font-weight: 700; font-size: var(--t-small); min-height: 1.3em; }

.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 10px 18px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--magenta);
  color: #fff;
  font-weight: 700;
  font-size: var(--t-lead);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn:active { background: var(--magenta-dark); }
.btn[disabled] { background: var(--paper); color: var(--ink-soft); border-color: var(--rule); cursor: default; }
.btn.quiet { background: var(--sheet); color: var(--ink); }
.btn.quiet:active { background: var(--water); }
.btn-row { display: grid; gap: 10px; margin-top: 16px; }
.textlink {
  background: none; border: 0; padding: 8px 0; margin-top: 6px;
  color: var(--ink-soft); text-decoration: underline; font-size: var(--t-small); cursor: pointer;
}

.standing { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }
.standing strong { font-size: var(--t-lead); }

/* ---------- Playing ---------- */

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  z-index: 4;
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 14px 12px;
}
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: var(--t-small);
  color: var(--ink-soft);
}
.hud-top b { color: var(--ink); }
.mult {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border: 1px solid var(--magenta);
  border-radius: 3px;
  color: var(--magenta-dark);
  font-weight: 700;
}
.place {
  margin-top: 2px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: var(--t-place);
  line-height: 1.08;
  overflow-wrap: anywhere;
}
.place.long { font-size: 1.5rem; }
.hint { margin-top: 2px; color: var(--ink-soft); }

/* Timer drawn as a chart scale bar that empties */
.timer { margin-top: 10px; display: flex; align-items: center; gap: 10px; }
.timer-track {
  flex: 1;
  height: 8px;
  border: 1.5px solid var(--ink);
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), var(--rule) calc(10% - 1px) 10%);
  overflow: hidden;
}
.timer-fill { height: 100%; width: 100%; background: var(--ink); transform-origin: left center; }
.timer.low .timer-fill { background: var(--magenta); }
.timer-num { min-width: 2.4em; text-align: right; font-weight: 700; font-variant-numeric: lining-nums tabular-nums; }
.timer.low .timer-num { color: var(--magenta-dark); }

#bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 4;
  max-width: 520px;
  margin: 0 auto;
}
#bar .tip {
  text-align: center;
  font-size: var(--t-small);
  color: var(--ink);
  margin-bottom: 8px;
  text-shadow: 0 0 4px var(--paper), 0 0 4px var(--paper);
}

/* Result sheet after each guess */
#reveal {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 6;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 18px 18px;
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.result-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.points {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 2.75rem;
  line-height: 1;
}
.points small { font-family: var(--sans); font-style: normal; font-size: var(--t-body); color: var(--ink-soft); }
.distance { text-align: right; font-weight: 700; }
.distance span { display: block; font-weight: 400; color: var(--ink-soft); font-size: var(--t-small); }
.answer-name { margin-top: 10px; font-weight: 700; }
#reveal .btn { margin-top: 14px; }

/* ---------- Final score ---------- */

.final-score { display: flex; align-items: baseline; gap: 10px; margin-top: 6px; }
.final-score .num {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: var(--t-score);
  line-height: 1;
}
.final-score .of { color: var(--ink-soft); }
.final-meta { margin-top: 4px; }
.final-meta b { font-variant-numeric: lining-nums tabular-nums; }
.best-note { margin-top: 6px; font-weight: 700; color: var(--magenta-dark); }

.rounds { width: 100%; margin-top: 14px; border-collapse: collapse; font-size: var(--t-small); }
.rounds td { padding: 6px 0; border-top: 1px solid var(--rule); vertical-align: baseline; }
.rounds td.n { text-align: right; white-space: nowrap; padding-left: 10px; font-variant-numeric: lining-nums tabular-nums; }
.rounds td.n b { font-size: var(--t-body); }
.rounds .dist { color: var(--ink-soft); }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: 86vw;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 4px;
  text-align: center;
}

#loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  pointer-events: none;
}

@media (min-height: 760px) {
  .panel > .card { padding: 26px 22px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  #reveal { animation: none; }
}

/* ============ Leaderboard (projector and phone) ============ */

body.board { min-height: 100%; }
.board-wrap {
  display: grid;
  grid-template-columns: minmax(260px, 30%) 1fr;
  gap: clamp(20px, 3vw, 56px);
  min-height: 100vh;
  padding: clamp(16px, 3vw, 48px);
  align-items: start;
}
.join { position: sticky; top: clamp(16px, 3vw, 48px); padding: clamp(16px, 2vw, 28px); }
.join .event { font-size: clamp(1.75rem, 3vw, 3rem); }
.join img { display: block; width: 100%; max-width: 420px; height: auto; margin-top: 16px; border: 1.5px solid var(--ink); }
.join .scan { margin-top: 14px; font-size: clamp(1.2rem, 1.8vw, 1.9rem); font-weight: 700; }
.join .url { margin-top: 2px; font-size: clamp(0.95rem, 1.25vw, 1.35rem); overflow-wrap: anywhere; color: var(--ink-soft); }
.join .tally { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rule); color: var(--ink-soft); }

.ranks { width: 100%; border-collapse: collapse; font-size: clamp(1.05rem, 1.7vw, 1.9rem); }
.ranks caption {
  text-align: left;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.6rem, 2.6vw, 2.75rem);
  padding-bottom: 0.35em;
}
.ranks th {
  text-align: left;
  font-weight: 400;
  font-size: 0.7em;
  color: var(--ink-soft);
  padding: 0 0.6em 0.4em 0;
  border-bottom: 1.5px solid var(--ink);
}
.ranks td { padding: 0.42em 0.6em 0.42em 0; border-bottom: 1px solid var(--rule); }
.ranks .num { text-align: right; font-variant-numeric: lining-nums tabular-nums; white-space: nowrap; }
.ranks th.num { text-align: right; }
.ranks td.rank { width: 2.4em; font-weight: 700; }
.ranks td.name { font-weight: 700; overflow-wrap: anywhere; }
.ranks td.score { font-weight: 700; }
.ranks tr.first td { font-size: 1.25em; }
.ranks tr.first td.rank, .ranks tr.first td.score { color: var(--magenta-dark); }
.ranks tr.me td { background: var(--water); }
.empty { padding: 1.2em 0; color: var(--ink-soft); font-size: clamp(1.05rem, 1.7vw, 1.9rem); }
.board-foot { margin-top: 1em; font-size: var(--t-small); color: var(--ink-soft); }
.board-foot a { color: inherit; }

@media (max-width: 760px) {
  .board-wrap { grid-template-columns: 1fr; }
  .join { position: static; }
  .join img, .join .scan, .join .url { display: none; }   /* already on a phone */
  .join .tally { margin-top: 8px; padding-top: 0; border-top: 0; }
  .ranks .games { display: none; }
}

/* ============ Admin ============ */

.admin { max-width: 900px; margin: 0 auto; padding: 24px 16px 60px; }
.admin h1 { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: var(--t-title); }
.admin h2 { font-size: var(--t-lead); margin-top: 28px; }
.admin ul { padding-left: 1.2em; }
.admin li { margin: 6px 0; }
.admin table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: var(--t-small); }
.admin th, .admin td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--rule); }
.admin tr.is-hidden td { color: var(--ink-soft); text-decoration: line-through; }
.admin tr.is-hidden td:last-child { text-decoration: none; }
.admin button { border: 1.5px solid var(--ink); background: var(--sheet); border-radius: 4px; padding: 4px 10px; cursor: pointer; }
