/* Kolik?'s whole look: the site's two-colour print on warm paper, set as a question and two numbers. Blue and
   pink are the page's inks: the title, the buttons, the band and the pin of an answer's picture. Stars are
   yellow with an ink outline, a hit is green, a miss is hatched away, as everywhere. What a finger presses
   or reads at a glance is set bold in the body face, not in the narrow display face. No web font, nothing
   from another origin (server.mjs). */

:root {
  color-scheme: light dark;

  --paper: #f3ecda;
  --label: #fbf6e9;
  --ink: #1e1f3d;
  --muted: #55567a;
  --pink: #ff4d94;
  --blue: #2d5be3;
  --on-blue: #fbf6e9;
  --green: #17b06b;
  --yellow: #ffd60a;
  --on-mark: #1e1f3d;
  --hatch: rgb(30 31 61 / 0.2);
  --line: rgb(30 31 61 / 0.28);
  --grain: 0.3;

  --font-display: Impact, Haettenschweiler, 'Arial Narrow Bold', 'Roboto Condensed', 'Liberation Sans Narrow',
    sans-serif-condensed, sans-serif;
  --font-body: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Segoe UI Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  /* The room between the page and the screen's edges: a little more on a larger phone, never none. */
  --pad-x: clamp(16px, 5vw, 22px);
  --pad-y: clamp(10px, 2.3dvh, 20px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15162b;
    --label: #20213f;
    --ink: #f3ecda;
    --muted: #b6b4d2;
    --pink: #ff6aa6;
    --blue: #7390ff;
    --on-blue: #15162b;
    --green: #3fd493;
    --yellow: #ffe04a;
    --on-mark: #15162b;
    --hatch: rgb(243 236 218 / 0.17);
    --line: rgb(243 236 218 / 0.3);
    --grain: 0.12;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 var(--font-body);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Paper grain, over everything, touching nothing. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: var(--grain);
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .12 0 0 0 0 .12 0 0 0 0 .24 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

[hidden] {
  display: none !important;
}

/* A field the page copies from when the clipboard will not be written to directly. */
.offscreen {
  position: fixed;
  top: 0;
  left: -100vw;
  opacity: 0;
}

a {
  color: inherit;
}

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

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

.sheet {
  max-width: 34rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--pad-y) max(var(--pad-x), env(safe-area-inset-right)) calc(var(--pad-y) + env(safe-area-inset-bottom))
    max(var(--pad-x), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}

.small {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

.center {
  text-align: center;
}

/* --- the header ------------------------------------------------------------------------------------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 4px;
}

.title {
  margin: 0;
  font: 400 clamp(1.7rem, 8vw, 2.4rem) / 1 var(--font-display);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Two plates a little out of register. */
.title a {
  text-decoration: none;
  color: var(--blue);
  text-shadow: 0.06em 0.045em 0 var(--pink);
}

.tools {
  display: flex;
  gap: 8px;
}

.tool {
  min-height: 36px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  font-size: 0.9375rem;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}

.tool--round {
  width: 36px;
  padding: 0;
  font: 700 1.125rem / 1 var(--font-body);
}

.tool:active,
.button:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* Two paper labels; the one in use is inked. */
.modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 6px 0 0;
}

.modes a {
  display: grid;
  place-items: center;
  min-height: 36px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  font-size: 0.9375rem;
  text-decoration: none;
}

.modes a[aria-current='page'] {
  background: var(--ink);
  color: var(--paper);
  transform: rotate(-1deg);
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.caption {
  margin: 0;
  padding: 10px 2px 8px;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--muted);
}

/* --- the question ----------------------------------------------------------------------------------- */

.play {
  display: grid;
  gap: 14px;
  padding-bottom: 8px;
}

/* A card laid on the sheet, its blue plate printed a little off. */
.question {
  margin: 0 4px 4px 0;
  padding: 14px 14px 15px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  box-shadow: 4px 4px 0 var(--blue);
  font: 700 clamp(1.1875rem, 5.4vw, 1.5rem) / 1.3 var(--font-body);
  text-wrap: balance;
  hyphens: manual;
}

/* --- the range: two numbers, each with its unit and its words for thousands ------------------------- */

.guess {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 8px;
}

.field__name {
  font-weight: 700;
  font-size: 1.0625rem;
}

.field__input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  /* 16 px at least: a smaller field makes a phone zoom in when it is touched */
  font-weight: 700;
  font-size: 1.3125rem;
  font-variant-numeric: tabular-nums;
}

.field__input:focus-visible {
  outline-offset: 1px;
}

.field__unit {
  max-width: 8.5rem;
  font-weight: 700;
  font-size: 1.0625rem;
  overflow-wrap: anywhere;
}

.field--bare .field__input {
  grid-column: 2 / -1;
}

.field--bare .field__unit {
  display: none;
}

.scales {
  grid-column: 2 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* tisíc, milion, miliarda: a label that is inked while it is on */
.scale {
  min-height: 34px;
  padding: 0 10px;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  font-weight: 700;
  font-size: 0.9375rem;
  cursor: pointer;
  touch-action: manipulation;
}

.scale[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

/* what the game understood, and what it would be worth */
.said {
  margin: 2px 0 0;
  min-height: 1.5em;
  font-weight: 700;
}

.said.is-hint {
  font-weight: 400;
  font-size: 0.9375rem;
  color: var(--muted);
}

.said.is-wrong {
  padding: 4px 8px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--yellow);
  color: var(--on-mark);
}

.worth {
  display: grid;
  gap: 2px;
}

.worth__stars {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  color: var(--muted);
}

.guess.is-wrong {
  animation: shake 320ms ease-in-out;
}

@keyframes shake {
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* --- stars ------------------------------------------------------------------------------------------ */

.stars {
  display: inline-flex;
  gap: 2px;
  vertical-align: middle;
}

.star {
  --i: 0;
  width: 22px;
  height: 22px;
  flex: none;
  overflow: visible;
}

.star path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.star.is-on path {
  fill: var(--yellow);
  stroke: var(--ink);
}

.star:nth-child(2) { --i: 1; }
.star:nth-child(3) { --i: 2; }
.star:nth-child(4) { --i: 3; }
.star:nth-child(5) { --i: 4; }

.stars--big {
  gap: 4px;
}

.stars--big .star {
  width: clamp(38px, 12vw, 48px);
  height: clamp(38px, 12vw, 48px);
}

/* An answer's stars are stamped one after another: each keeps its bare look until its turn. */
.stars.is-new .star.is-on {
  animation:
    stamp 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2) calc(var(--i) * 150ms + 120ms) backwards,
    bare 150ms step-end calc(var(--i) * 150ms + 120ms) backwards;
}

.stars.is-new .star.is-on path {
  animation: bare-ink 150ms step-end calc(var(--i) * 150ms + 120ms) backwards;
}

@keyframes stamp {
  0% { transform: none; }
  40% { transform: scale(1.3) rotate(-8deg); }
  65% { transform: scale(0.94) rotate(2deg); }
  100% { transform: none; }
}

@keyframes bare {
  from { opacity: 1; }
}

@keyframes bare-ink {
  from {
    fill: none;
    stroke: var(--line);
  }
}

/* --- buttons ---------------------------------------------------------------------------------------- */

.button {
  min-height: 44px;
  padding: 0 14px;
  display: inline-grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--paper);
  font-size: 0.9375rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}

.button--main {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--on-blue);
}

.button--wide {
  width: calc(100% - 2px);
  min-height: 50px;
  margin-top: 2px;
  font-size: 1.125rem;
  letter-spacing: 0.02em;
}

.button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* --- an answer told ---------------------------------------------------------------------------------- */

.result {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 16px 12px 16px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  text-align: center;
}

.result h2 {
  margin: 0;
  font: 400 clamp(1.7rem, 7.5vw, 2.2rem) / 1.05 var(--font-display);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.result h2:focus {
  outline: none;
}

.result p {
  margin: 0;
}

.verdict {
  font-weight: 700;
}

.truth {
  display: grid;
  gap: 2px;
}

.truth span,
.yours,
.source,
.next {
  font-size: 0.9375rem;
  color: var(--muted);
}

.truth b {
  font-size: clamp(1.6rem, 7.6vw, 2.25rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.fact {
  max-width: 30rem;
  padding: 10px 0 2px;
  border-top: 2px dashed var(--line);
  text-align: left;
  text-wrap: pretty;
}

.source {
  justify-self: start;
}

.source a {
  color: var(--ink);
  font-weight: 700;
}

.next .clock {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding-top: 4px;
}

/* The picture of an answer: a line of numbers, small ones on the left; on it the range, a blue band, and
   the true value, a pink pin. Inside the band is a hit. */
.tape {
  width: 100%;
  max-width: 26rem;
  display: grid;
  gap: 6px;
  padding: 2px 0;
}

.tape__line {
  position: relative;
  height: 34px;
  margin: 0 9px;
  background: linear-gradient(var(--ink), var(--ink)) 0 50% / 100% 2px no-repeat;
}

.tape__band {
  position: absolute;
  top: 8px;
  bottom: 8px;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: var(--blue);
}

/* a range from zero has no left end on this line */
.tape__band.is-open {
  border-left-style: dashed;
}

.tape__pin {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}

.tape__pin::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--pink);
  transform: translate(-50%, -50%);
}

.tape__key {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  font-size: 0.9375rem;
  color: var(--muted);
}

.key {
  display: inline-block;
  border: 2px solid var(--ink);
}

.key--band {
  width: 20px;
  height: 12px;
  border-radius: 2px;
  background: var(--blue);
}

.key--pin {
  width: 14px;
  height: 14px;
  margin-left: 12px;
  border-radius: 50%;
  background: var(--pink);
}

/* What the game says: a label laid over the bottom of the sheet. */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 4;
  width: max-content;
  max-width: calc(100vw - 2 * var(--pad-x));
  margin: 0;
  padding: 6px 12px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9375rem;
  text-align: center;
  transform: translateX(-50%) rotate(-1deg);
  pointer-events: none;
}

.toast:empty {
  display: none;
}

/* --- the archive ------------------------------------------------------------------------------------ */

.archive {
  padding: 4px 2px 16px;
}

.archive__sum {
  margin: 0 0 10px;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--muted);
}

.month {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  margin-bottom: 8px;
}

.month h2 {
  margin: 0;
  text-align: center;
  font: 400 1.6rem / 1 var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.month a,
.month span {
  display: grid;
  place-items: center;
  height: 40px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  font-size: 1.1rem;
  text-decoration: none;
}

.month span {
  border-color: var(--line);
  background: none;
  color: var(--line);
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.calendar .dow {
  padding-bottom: 2px;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--muted);
}

.day {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  color: var(--ink);
  font: 700 clamp(1rem, 4.6vw, 1.3rem) / 1 var(--font-body);
  text-decoration: none;
}

/* a day with its stars: the date, and under it what the answer earned */
.day[data-state='hit'] {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
  font-size: clamp(0.9375rem, 4.2vw, 1.125rem);
}

.day small {
  font: 700 0.75rem / 1 var(--font-body);
}

.day.is-off {
  border-color: transparent;
  background: none;
  color: var(--line);
  font-weight: 400;
}

.day[data-state='hit'] {
  border-color: var(--green);
  background: var(--green);
  color: var(--on-mark);
}

.day[data-state='miss'] {
  border-color: var(--line);
  background: repeating-linear-gradient(135deg, transparent 0 4px, var(--hatch) 4px 6px) var(--paper);
  color: var(--muted);
}

.day.is-today {
  outline: 3px solid var(--pink);
  outline-offset: 1px;
}

.key-to {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9375rem;
  color: var(--muted);
}

.key-to li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.key-to .day {
  width: 18px;
  padding: 0;
  aspect-ratio: 1;
  border-width: 2px;
}

/* --- trouble, dialogs ------------------------------------------------------------------------------- */

.trouble {
  margin: 24px auto;
  max-width: 24rem;
  padding: 16px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  text-align: center;
}

.dialog {
  width: min(30rem, calc(100vw - 20px));
  max-height: calc(100dvh - 24px);
  padding: 18px 16px 16px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  color: var(--ink);
  box-shadow: 6px 6px 0 var(--blue);
}

.dialog::backdrop {
  background: rgb(21 22 43 / 0.55);
}

.dialog h2 {
  margin: 0 0 10px;
  font: 400 1.7rem / 1 var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dialog p {
  margin: 0 0 10px;
  font-size: 0.9375rem;
}

.dialog__close {
  float: right;
  margin: -6px -4px 0 8px;
}

.dialog__close button {
  width: 36px;
  height: 36px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--paper);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

/* the rule: stars, and how wide a range may be for them */
.rules {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  font-size: 0.9375rem;
}

.rules li {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  line-height: 1.3;
}

.how {
  margin: 0 0 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 0.9375rem;
}

.how dt {
  font-weight: 700;
}

.how dd {
  margin: 0;
}

.numbers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0 0 12px;
}

.numbers div {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 2px;
  padding: 8px 2px;
  border: 2px solid var(--line);
  border-radius: 3px;
  text-align: center;
}

.numbers b {
  font: 700 clamp(1.3rem, 6vw, 1.75rem) / 1.1 var(--font-body);
  white-space: nowrap;
}

.numbers span {
  font-size: 0.9375rem;
  line-height: 1.2;
  color: var(--muted);
}

.bars {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 8px;
  margin: 0 0 10px;
  font-size: 0.9375rem;
}

.bars dt {
  text-align: right;
}

.bars dd {
  margin: 0;
}

.bar {
  min-width: 1.8em;
  padding: 2px 6px;
  border-radius: 2px;
  background: repeating-linear-gradient(135deg, transparent 0 3px, var(--hatch) 3px 5px);
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bar.is-some {
  background: var(--green);
  color: var(--on-mark);
}

.bar.is-lost {
  background: var(--ink);
  color: var(--paper);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* A screen with room to spare: let the sheet breathe. */
@media (min-width: 40rem) and (min-height: 46rem) {
  .top {
    padding-top: 6px;
  }
  .play {
    gap: 18px;
  }
  .question {
    padding: 18px 18px 20px;
  }
}
