/* Slovíčko's whole look: the site's two-colour print on warm paper, set as a word game. A letter that is in
   its place is a block of blue ink; one that belongs elsewhere is an orange dot; one that is not in the word
   is hatched away. Shape says it as well as colour. 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;
  --orange: #ff7a1a;
  --on-blue: #fbf6e9;
  --on-orange: #1e1f3d;
  --hatch: rgb(30 31 61 / 0.16);
  --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 board takes what the screen has left after the header and the keyboard. */
  --key-h: clamp(40px, 6.4dvh, 54px);
  --tile: clamp(34px, min(15.5vw, (100dvh - 4 * var(--key-h) - 11.5rem) / 6), 62px);
  --step: 160ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15162b;
    --label: #20213f;
    --ink: #f3ecda;
    --muted: #b6b4d2;
    --pink: #ff6aa6;
    --blue: #7390ff;
    --orange: #ff9547;
    --on-blue: #15162b;
    --on-orange: #15162b;
    --hatch: rgb(243 236 218 / 0.14);
    --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 {
  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: 0 10px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

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

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 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: 400 1.25rem / 1 var(--font-display);
}

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

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

.modes a {
  display: grid;
  place-items: center;
  min-height: 34px;
  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(-1.2deg);
}

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

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

/* --- the board -------------------------------------------------------------------------------------- */

.game {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.board-frame {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 4px 0 8px;
}

.board {
  display: grid;
  gap: 5px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: 5px;
}

.tile {
  --i: 0;
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 3px;
  background: var(--label);
  color: var(--ink);
  font: 400 calc(var(--tile) * 0.6) / 1 var(--font-display);
  text-transform: uppercase;
  user-select: none;
}

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

.tile.is-typed {
  border-color: var(--ink);
}

.tile.is-new {
  animation: press 90ms ease-out;
}

/* here: a block of blue */
.tile[data-mark='2'] {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--on-blue);
}

/* elsewhere: an orange dot */
.tile[data-mark='1'] {
  border-color: var(--orange);
  background: radial-gradient(circle closest-side, var(--orange) 0 91%, transparent 94%) var(--label);
  color: var(--on-orange);
}

/* not in the word: hatched away */
.tile[data-mark='0'] {
  border-color: transparent;
  background: repeating-linear-gradient(135deg, transparent 0 4px, var(--hatch) 4px 6px) var(--paper);
  color: var(--muted);
}

/* A guess is stamped letter by letter: each tile keeps its bare look until its turn, then takes the ink. */
.row.is-told .tile {
  animation:
    stamp 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2) calc(var(--i) * var(--step)) backwards,
    bare 180ms step-end calc(var(--i) * var(--step)) backwards;
}

.row.is-won .tile {
  animation: hop 480ms ease-out calc(var(--i) * 70ms);
}

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

@keyframes press {
  from { transform: scale(1.1); }
}

@keyframes stamp {
  0% { transform: none; }
  40% { transform: scale(1.14) rotate(-3deg); }
  62% { transform: scale(0.94) rotate(1deg); }
  100% { transform: none; }
}

@keyframes bare {
  from {
    border-color: var(--ink);
    background: var(--label);
    color: var(--ink);
  }
}

@keyframes hop {
  30% { transform: translateY(-22%) rotate(-2deg); }
  60% { transform: translateY(4%); }
}

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

/* What the game says: a label laid over the line above the board, never over a guess. */
.toast {
  position: absolute;
  top: -36px;
  left: 0;
  right: 0;
  z-index: 2;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 5px 12px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9375rem;
  text-align: center;
  transform: rotate(-1deg);
  pointer-events: none;
}

.toast:empty {
  display: none;
}

/* --- the keyboard ----------------------------------------------------------------------------------- */

.keyboard {
  --gap: 4px;
  --key-w: min(46px, (100vw - 20px - 10 * var(--gap)) / 11);
  display: grid;
  gap: 5px;
  justify-content: center;
  padding-bottom: 2px;
  touch-action: manipulation;
}

.keys {
  display: flex;
  gap: var(--gap);
  justify-content: center;
}

.key {
  width: var(--key-w);
  height: var(--key-h);
  padding: 0;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  font: 400 clamp(1.05rem, 4.6vw, 1.3rem) / 1 var(--font-display);
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.key:active {
  transform: translateY(2px);
}

.key--wide {
  width: calc(2 * var(--key-w) + var(--gap));
  background: var(--ink);
  color: var(--paper);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.key--back {
  font-family: var(--font-body);
  font-size: 1.15rem;
}

.key[data-mark='2'] {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--on-blue);
}

.key[data-mark='1'] {
  border-color: var(--orange);
  background: radial-gradient(circle closest-side, var(--orange) 0 88%, transparent 92%) var(--label);
  color: var(--on-orange);
}

.key[data-mark='0'] {
  border-color: var(--line);
  background: repeating-linear-gradient(135deg, transparent 0 3px, var(--hatch) 3px 5px) var(--paper);
  color: var(--muted);
}

/* --- when a game is over ---------------------------------------------------------------------------- */

.result {
  min-height: calc(4 * var(--key-h) + 17px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--label);
  text-align: center;
}

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

.result h2:focus {
  outline: none;
}

.result p {
  margin: 0;
  font-size: 0.9375rem;
}

.result .word {
  font: 400 1.5rem / 1 var(--font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
}

.result .clock {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.button {
  min-height: 42px;
  padding: 0 14px;
  display: inline-grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--paper);
  font-size: 0.9375rem;
  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);
  box-shadow: 2px 2px 0 var(--ink);
}

/* --- 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: 400 clamp(1.1rem, 5vw, 1.5rem) / 1 var(--font-display);
  text-decoration: none;
}

.day small {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font: 0.6875rem / 1 var(--font-body);
}

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

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

.day[data-state='lost'] {
  border-color: var(--orange);
  background: radial-gradient(circle closest-side, var(--orange) 0 91%, transparent 94%) var(--label);
  color: var(--on-orange);
}

.day[data-state='playing'] {
  border-style: dashed;
}

.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;
  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 h3 {
  margin: 18px 0 8px;
  font-size: 1rem;
}

.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;
}

.legend {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  font-size: 0.9375rem;
}

.legend li {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
}

.tile--demo {
  --tile: 40px;
}

.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;
}

.small {
  color: var(--muted);
}

.bars + .small {
  margin-top: 10px;
}

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

.numbers--two {
  grid-template-columns: repeat(2, 1fr);
}

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

.numbers b {
  font: 400 clamp(1.35rem, 6.2vw, 1.9rem) / 1 var(--font-display);
  white-space: nowrap;
}

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

.bars {
  display: grid;
  grid-template-columns: 1.5em 1fr;
  align-items: center;
  gap: 4px 8px;
  margin: 0;
  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(--blue);
  color: var(--on-blue);
}

.bar.is-lost {
  background: var(--orange);
  color: var(--on-orange);
}

@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: 18px;
  }
  .modes a {
    min-height: 38px;
  }
}
