:root {
  /* --ground is replaced at load with a dark version of the day's photo colour */
  --ground: #142036;
  --ink: #f3f1ec;
  --dim: #b9bcbd;
  --far: #8ab4ff;
  --near: #ef5b45;
  --hit: #ffcf3a;
  --btn: #f3f1ec;
  --btn-ink: #0f1a2e;
  --cond: "Fira Sans Condensed", "Arial Narrow", sans-serif;
  --body: "Fira Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.4 var(--body);
  -webkit-tap-highlight-color: transparent;
  transition: background-color .6s;
}

#app {
  height: 100vh;            /* older iPhones without dvh */
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 52fr) minmax(0, 48fr);
}

/* ---------- photo ---------- */
#photo { position: relative; overflow: hidden; background: #000; }
#frame { position: absolute; inset: 0; overflow: hidden; }
#frame::before {            /* blurred copy of the photo fills the edges around it */
  content: ""; position: absolute; inset: -40px;
  background: var(--bg) center / cover no-repeat;
  filter: blur(24px) brightness(.55);
}
#pic {
  position: relative;
  width: 100%; height: 100%;
  object-fit: contain;       /* always the whole photo, never cropped */
  transition: opacity .4s;
  user-select: none;
  opacity: 0;
}
#pic.ready { opacity: 1; }
#sv, #block { position: absolute; inset: 0; display: none; }
body.sv #sv, body.sv #block { display: block; }
body.sv #block[hidden] { display: none; }
body.sv #frame { display: none; }
/* keep Google's logo and terms visible above our bottom shade */
body.sv #photo::after { height: 7rem; bottom: 1.6rem; }

#top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: baseline; gap: .6rem;
  padding: max(.7rem, env(safe-area-inset-top)) 1rem 2.2rem;
  background: linear-gradient(rgba(0,0,0,.55), rgba(0,0,0,0));
  pointer-events: none;
}
#top .brand {
  margin: 0;
  font: 800 1.9rem/1 var(--cond);
  letter-spacing: -.01em;
}
#daynum { font: 600 1rem var(--cond); color: var(--dim); }
#score { font: 800 1.05rem var(--cond); color: var(--hit); }
#top .brand, #daynum, #score { white-space: nowrap; }
#daynum, #score { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#top .brand, #top button { flex-shrink: 0; }
@media (max-width: 480px) {
  #top { gap: .55rem; padding-left: .9rem; padding-right: .7rem; }
  #top .brand { display: none; }   /* the start page carries the name; the header needs the room */
}
@media (min-aspect-ratio: 4/3) and (max-width: 1000px) { #top .brand { display: none; } }
#top button { pointer-events: auto; padding: .4rem .7rem; min-width: 2.4rem; }
#zoomBtn { margin-left: auto; }

#readout {
  position: absolute; left: 1rem; right: 1rem; bottom: 2.1rem;
  font-family: var(--cond);
  text-shadow: 0 1px 2px rgba(0,0,0,.7), 0 0 18px rgba(0,0,0,.45);
  pointer-events: none;
}
#readout .num { display: block; font-weight: 800; font-size: clamp(3.2rem, 15vw, 6rem); line-height: .9; }
#readout .word { font-weight: 600; font-size: 1.15rem; }
#readout .place { display: block; font-weight: 800; font-size: 1.35rem; margin-top: .1rem; }
#readout.pop .num { animation: pop .5s ease-out; }
@keyframes pop { from { transform: translateY(.4rem); opacity: 0; } }

#photo::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 9rem;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.55));
  pointer-events: none;
}
#readout, #credit { z-index: 1; }

#credit {
  position: absolute; right: .6rem; bottom: .35rem; left: 1rem; margin: 0;
  text-align: right;
  font-size: .7rem; color: #fff;
  text-shadow: 0 1px 2px #000;
}
#credit a { color: inherit; }

/* ---------- map ---------- */
#guess { position: relative; display: grid; grid-template-rows: minmax(0,1fr) auto; }
#map { background: #c9d3d6; }
#map .leaflet-tile-pane { filter: saturate(.55) contrast(1.04); }
.leaflet-container { font-family: var(--body); }

#bar {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .8rem calc(.6rem + env(safe-area-inset-bottom));
  background: var(--ground);
}
#tries { display: flex; gap: .35rem; margin: 0; padding: 0; list-style: none; }
#tries li {
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  display: grid; place-items: center;
  font: 600 .8rem var(--cond); color: #111;
}
#tries li { color: rgba(255,255,255,.55); }
#tries li.now { border-color: var(--ink); color: var(--ink); }
#tries li.used { border-color: transparent; color: #111; }

button {
  font: 600 1.05rem var(--cond);
  border: 0; border-radius: .35rem;
  padding: .75rem 1.1rem;
  background: var(--btn); color: var(--btn-ink);
  cursor: pointer;
}
button:hover:not(:disabled) { background: #fff; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible { outline: 3px solid var(--hit); outline-offset: 2px; }
button.ghost { background: transparent; color: var(--ink); border: 1.5px solid rgba(255,255,255,.5); padding: .45rem .85rem; }
#go { flex: 1; white-space: nowrap; padding-left: .6rem; padding-right: .6rem; }

/* map markers */
.pin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #111;
  display: grid; place-items: center;
  font: 700 13px var(--cond); color: #111;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.pin.draft { background: #fff; }
.truth {
  width: 34px; height: 34px; border-radius: 50%;
  border: 4px solid #fff; background: #111;
  box-shadow: 0 0 0 3px #111, 0 2px 8px rgba(0,0,0,.5);
}

/* ---------- dialogs ---------- */
dialog {
  border: 0; padding: 0; max-width: 30rem; width: calc(100% - 1.5rem);
  background: var(--ground); color: var(--ink);
  border-radius: .5rem;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet { padding: 1.3rem 1.3rem 1.1rem; }
.sheet p { margin: 0 0 .8rem; }
.sheet .lead { font: 600 1.35rem/1.2 var(--cond); }
.sheet .small { font-size: .8rem; color: var(--dim); }
#endScore { font: 800 3.2rem/1 var(--cond); margin-bottom: .1rem !important; color: var(--hit); }
#endLine { color: var(--dim); }
/* you vs everyone today */
#compare { position: relative; margin: .2rem 0 1rem; }
#compare[hidden] { display: none; }
#cmpText { font-size: .95rem; margin-bottom: .4rem; }
#cmpText b { color: var(--ink); }
#cmpText small { display: block; color: var(--dim); font-size: .8rem; }
#cmpChart svg { display: block; width: 100%; height: auto; overflow: visible; }
#cmpChart path { fill: #7d868b; }
#cmpChart path.me { fill: var(--hit); }
#cmpChart .base { stroke: rgba(255,255,255,.22); stroke-width: 1; }
#cmpChart text { font: 600 10px var(--cond); fill: var(--dim); }
#cmpChart text.ti { font-size: 12px; fill: var(--ink); text-anchor: middle; }
#cmpChart text.mid { text-anchor: middle; }
#cmpChart text.end { text-anchor: end; }
#cmpChart .hit { fill: transparent; cursor: default; }
#cmpTip {
  position: absolute; top: 2.6rem; padding: .3rem .5rem; border-radius: .3rem;
  background: #0d1114; color: var(--ink); font: 600 .8rem var(--cond); white-space: nowrap; pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
#endList { list-style: none; margin: 0 0 1rem; padding: 0; font-family: var(--cond); }
#endList li { display: flex; gap: .7rem; padding: .35rem 0; border-top: 1px solid rgba(255,255,255,.12); }
#endList .p { flex: 1; min-width: 0; }
#endList .d { font-weight: 600; white-space: nowrap; }
#endList .s { font-weight: 800; min-width: 2.6rem; text-align: right; }
#endList li { cursor: pointer; margin: 0 -.5rem; padding-left: .5rem; padding-right: .5rem; border-radius: .25rem; }
#endList li:hover, #endList li:focus-visible { background: rgba(255,255,255,.07); outline: none; }
#endTip { margin-top: -.6rem !important; }
#stats:empty { display: none; }
#stats { display: flex; flex-wrap: wrap; gap: .8rem 1.2rem; margin: .2rem 0 1rem; }
#stats dt { white-space: nowrap; }
#stats div { display: flex; flex-direction: column-reverse; }
#stats dt { font-size: .75rem; color: var(--dim); }
#stats dd { margin: 0; font: 800 1.7rem/1 var(--cond); }
.row { display: flex; gap: .6rem; }
.row button:first-child { flex: 1; }
#next { margin: .9rem 0 0; font-size: .85rem; color: var(--dim); }
button.link {
  background: none; color: var(--ink); padding: .5rem 0 0; font: 600 .95rem var(--cond);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(255,255,255,.4);
}
button.link:hover:not(:disabled) { background: none; text-decoration-color: var(--ink); }
#fbText {
  width: 100%; margin: 0 0 .8rem; padding: .6rem .7rem; border-radius: .35rem;
  border: 1.5px solid rgba(255,255,255,.3); background: rgba(0,0,0,.25); color: var(--ink);
  font: 16px/1.4 var(--body);   /* 16px: iPhone doesn't zoom in on the box */
  resize: vertical;
}
#fbText:focus { outline: 3px solid var(--hit); outline-offset: 1px; border-color: transparent; }
#fbStatus { margin: .7rem 0 0 !important; min-height: 1.2em; }

/* ---------- start page ---------- */
#start {
  position: fixed; inset: 0; z-index: 5000;
  display: flex; flex-direction: column; overflow-y: auto;
  background: var(--ground);
  transition: opacity .45s ease, visibility .45s;
}
#start.gone { opacity: 0; visibility: hidden; }
#startBg {
  position: fixed; inset: 0;
  background: var(--bg, none) center / cover no-repeat;
  filter: saturate(.8);
}
#startBg::after {   /* photo fades into the ground under the text */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(rgba(0,0,0,.05) 0%, rgba(0,0,0,.45) 35%, var(--ground) 70%);
}
.startIn {
  position: relative; width: 100%; max-width: 34rem; margin-top: auto;
  padding: 2rem 1.4rem calc(1.6rem + env(safe-area-inset-bottom));
}
#startDate { margin: 0 0 .2rem; font: 600 1.1rem var(--cond); color: var(--ink); opacity: .9; }
#startDate, .tag { text-shadow: 0 1px 3px rgba(0,0,0,.7), 0 0 24px rgba(0,0,0,.35); }
.logo {
  margin: 0 0 .9rem;
  font: 800 clamp(3.4rem, min(21vw, 19vh), 8.5rem)/.82 var(--cond);
  letter-spacing: -.035em;
  text-shadow: 0 2px 30px rgba(0,0,0,.35);
}
.tag { margin: 0 0 1.4rem; font-size: 1.1rem; line-height: 1.45; max-width: 26rem; }
.scale { margin: 0 0 1.6rem; max-width: 22rem; }
.scale .bar {
  height: .55rem; border-radius: .3rem;
  background: linear-gradient(90deg, var(--far), #ece2c8 50%, var(--near) 88%, var(--hit));
}
.scale .ends {
  display: flex; justify-content: space-between;
  margin-top: .35rem; font: 600 .9rem var(--cond); color: var(--dim);
}
#play { width: 100%; max-width: 22rem; padding: 1rem; font-size: 1.35rem; }
#startStats { margin: 1rem 0 0; color: var(--dim); font-size: .95rem; max-width: 26rem; }
#startStats:empty, #startBgNote:empty { display: none; }
#startBgNote { margin: .5rem 0 0; font-size: .75rem; color: var(--dim); opacity: .8; }

/* ---------- map hint ---------- */
#hint {
  position: absolute; z-index: 900; left: .6rem; right: 3.4rem; top: .6rem; margin: 0; max-width: 24rem;
  padding: .6rem .8rem; border-radius: .4rem;
  background: rgba(16,20,23,.86); color: var(--ink);
  font: 600 1rem/1.3 var(--cond); text-align: center;
  pointer-events: none;
}
#hint small { display: block; margin-top: .2rem; font: 400 .8rem/1.3 var(--body); color: var(--dim); }
#hint[hidden] { display: none; }
body:not(.sv) #frame { cursor: zoom-in; }

/* ---------- full-screen photo ---------- */
#big { max-width: none; width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border-radius: 0; background: #000; }
#big img { width: 100%; height: 100%; object-fit: contain; display: block; }
#closeBig { position: absolute; top: max(.7rem, env(safe-area-inset-top)); right: .8rem; background: rgba(0,0,0,.5); }

#endRank { font: 600 1.25rem/1.2 var(--cond); margin-bottom: .3rem !important; }

/* ---------- wide screens: photo beside the map ---------- */
@media (min-width: 560px) and (min-aspect-ratio: 4/3) {
  #app { grid-template-rows: none; grid-template-columns: minmax(0, 58fr) minmax(0, 42fr); }
}

@media (min-width: 900px) {
  .startIn { padding: 3rem 4rem 3.5rem; max-width: 40rem; }
}

@media (prefers-reduced-motion: reduce) {
  #pic, body, #start { transition: none; }
  #readout.pop .num { animation: none; }
}

/* Mapillary logo in the photo credit (their terms ask for the logo + a link) */
#credit .mly img { height: 1.35em; vertical-align: -0.38em; border-radius: 2px; }

.sheet .small a, .startPrivacy a { color: var(--dim); }
.endPrivacy { margin: .6rem 0 0 !important; }
.startPrivacy { margin: .6rem 0 0; font-size: .75rem; }

#credit .year { font-weight: 600; margin-right: .3rem; }

/* inside Facebook's own browser: how to keep progress */
#inApp { margin: 1rem 0 0; max-width: 26rem; padding: .7rem .8rem; border-radius: .4rem;
  background: rgba(255,225,77,.1); border: 1px solid rgba(255,225,77,.35); font-size: .9rem; }
#inApp[hidden] { display: none; }
#inApp p { margin: 0 0 .6rem; }
#inApp button { padding: .4rem .8rem; font-size: .95rem; }

#startBgNote a { color: inherit; }
#startBgNote .mly img { height: 1.3em; vertical-align: -0.35em; border-radius: 2px; }
