/* Shared pieces for every Dokugotchi page: the game's pixel font, pixel
   panels, pets, the mini sudoku and the follow-along buddy.
   Pages set the colour tokens and call Doku.installSkins() for panel frames.
   Font sizes are multiples of 10px so each font pixel is a whole screen pixel. */

@font-face {
  font-family: "Dokugotchi Pixel";
  src: url("../assets/fonts/dokugotchi-pixel-regular.woff2") format("woff2");
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: "Dokugotchi Pixel";
  src: url("../assets/fonts/dokugotchi-pixel-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: block;
}

:root {
  --font: "Dokugotchi Pixel", ui-monospace, monospace;
  --u: 3px; /* one panel pixel */
  --t-body: 20px;
  --t-head: 30px;
  --t-big: 40px;
  --t-display: 80px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: 30px;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: optimizeSpeed;
  font-kerning: none;
  font-variant-ligatures: none;
}

h1,
h2,
h3,
p {
  margin: 0;
  font-weight: 700;
  text-wrap: balance;
}
p {
  font-weight: 400;
  text-wrap: pretty;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

img,
canvas {
  max-width: 100%;
  image-rendering: pixelated;
}

::selection {
  background: var(--select-bg);
  color: var(--select-fg);
}

:focus-visible {
  outline: calc(var(--u) * 1) solid var(--focus);
  outline-offset: calc(var(--u) * 1);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Pixel panels ---------- */

.px {
  border-style: solid;
  border-width: calc(var(--u) * 4) calc(var(--u) * 4) calc(var(--u) * 6);
  border-image: var(--skin, var(--skin-paper)) 4 4 6 fill / calc(var(--u) * 4) calc(var(--u) * 4) calc(var(--u) * 6);
  image-rendering: pixelated;
}
.px--flat {
  border-bottom-width: calc(var(--u) * 4);
  border-image: var(--skin-flat, var(--skin-paper-flat)) 4 4 4 fill / calc(var(--u) * 4);
}

/* A chunky button that presses straight down. */
.btn {
  --skin: var(--skin-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 10px;
  border-style: solid;
  border-width: calc(var(--u) * 4) calc(var(--u) * 4) calc(var(--u) * 6);
  border-image: var(--skin) 4 4 6 fill / calc(var(--u) * 4) calc(var(--u) * 4) calc(var(--u) * 6);
  background: none;
  font-weight: 700;
  color: var(--on-accent);
  text-decoration: none;
  /* Labels wrap between words only when a button is wider than the screen. */
  max-width: 100%;
  text-align: center;
  transition: translate 60ms steps(1);
}
.btn:hover {
  filter: brightness(1.04);
}
.btn:active,
.btn[aria-pressed="true"] {
  translate: 0 calc(var(--u) * 2);
  border-bottom-width: calc(var(--u) * 4);
  border-image: var(--skin-flat, var(--skin-accent-flat)) 4 4 4 fill / calc(var(--u) * 4);
}
/* Apple's official App Store badge, exactly as Apple supplies it (not redrawn in pixels).
   Apple asks for at least 40px tall on screen and clear space of a quarter of its height:
   at 56px tall, this 4px margin plus the 10px gap around buttons makes 14px. */
.store-badge {
  display: inline-flex;
  margin: 4px;
  border-radius: 10px;
}
.store-badge img {
  display: block;
  width: auto;
  height: 56px;
  image-rendering: auto;
}
.btn--paper {
  --skin: var(--skin-paper);
  --skin-flat: var(--skin-paper-flat);
  color: var(--ink);
}
.btn--butter {
  --skin: var(--skin-butter);
  --skin-flat: var(--skin-butter-flat);
  color: var(--ink);
}
.btn--sky {
  --skin: var(--skin-sky);
  --skin-flat: var(--skin-sky-flat);
  color: var(--ink);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Pets ---------- */

pixel-pet {
  display: inline-block;
  position: relative;
  width: var(--pet-w, 120px);
  height: var(--pet-h, 138px);
  flex: none;
}
.pixel-pet__sprite {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
pixel-pet[flip] .pixel-pet__sprite {
  scale: -1 1;
}

/* A little speech bubble with a tail, drawn from pixel frames. */
.bubble {
  --skin: var(--skin-paper);
  position: relative;
  padding: 0 4px;
  color: var(--ink);
}
.bubble::after {
  content: "";
  position: absolute;
  left: 22px;
  bottom: calc(var(--u) * -9);
  width: calc(var(--u) * 4);
  height: calc(var(--u) * 4);
  background:
    linear-gradient(var(--line) 0 0) 0 0 / var(--u) 100% no-repeat,
    linear-gradient(var(--line) 0 0) 100% 0 / var(--u) 75% no-repeat,
    linear-gradient(var(--line) 0 0) var(--u) 100% / var(--u) var(--u) no-repeat,
    linear-gradient(var(--line) 0 0) calc(var(--u) * 2) 75% / var(--u) var(--u) no-repeat,
    linear-gradient(var(--paper) 0 0) var(--u) 0 / calc(var(--u) * 2) 75% no-repeat;
}

/* ---------- Mini sudoku ---------- */

.sudoku__board {
  --cell: 52px;
  display: grid;
  width: max-content;
  max-width: 100%;
  padding: calc(var(--u) * 1);
  background: var(--grid-thick);
}
.sudoku__row {
  display: grid;
  grid-template-columns: repeat(6, var(--cell));
  gap: 0;
}
.sudoku__cell {
  width: var(--cell);
  height: var(--cell);
  border: 0;
  margin: 0;
  padding: 0;
  background: var(--board);
  box-shadow:
    inset -1px 0 0 var(--grid-thin),
    inset 0 -1px 0 var(--grid-thin);
  font-weight: 400;
  font-size: var(--t-head);
  line-height: 1;
  color: var(--given);
  display: grid;
  place-items: center;
  position: relative;
}
.sudoku__cell[data-c="2"] {
  box-shadow:
    inset -3px 0 0 var(--grid-thick),
    inset 0 -1px 0 var(--grid-thin);
}
.sudoku__row:nth-child(2n):not(:last-child) .sudoku__cell {
  box-shadow:
    inset -1px 0 0 var(--grid-thin),
    inset 0 -3px 0 var(--grid-thick);
}
.sudoku__row:nth-child(2n):not(:last-child) .sudoku__cell[data-c="2"] {
  box-shadow:
    inset -3px 0 0 var(--grid-thick),
    inset 0 -3px 0 var(--grid-thick);
}
.sudoku__cell[data-c="5"] {
  box-shadow: inset 0 -1px 0 var(--grid-thin);
}
.sudoku__row:nth-child(2n):not(:last-child) .sudoku__cell[data-c="5"] {
  box-shadow: inset 0 -3px 0 var(--grid-thick);
}
.sudoku__row:last-child .sudoku__cell {
  box-shadow: inset -1px 0 0 var(--grid-thin);
}
.sudoku__row:last-child .sudoku__cell[data-c="2"] {
  box-shadow: inset -3px 0 0 var(--grid-thick);
}
.sudoku__row:last-child .sudoku__cell[data-c="5"] {
  box-shadow: none;
}
.sudoku__cell.is-given {
  font-weight: 700;
}
.sudoku__cell.is-peer {
  background-color: var(--peer);
}
.sudoku__cell.is-same {
  background-color: var(--same-digit);
}
.sudoku__cell.is-selected {
  background-color: var(--selected);
  outline: 3px solid var(--selected-ring);
  outline-offset: -3px;
}
.sudoku__cell.is-entered {
  color: var(--entered);
}
.sudoku__cell.is-wrong {
  color: var(--wrong);
}
/* The game's mistake zigzag under a wrong digit. */
.sudoku__cell.is-wrong::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 7px;
  width: 24px;
  height: 4px;
  translate: -50% 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='4' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h2v2H0zM2 2h2v2H2zM4 0h2v2H4zM6 2h2v2H6z' fill='%23D2453F'/%3E%3C/svg%3E") 0 0 / 8px 4px repeat-x;
}
.sudoku__cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
  z-index: 1;
}
.sudoku.is-solved .sudoku__cell {
  animation: solved-hop 420ms steps(3) both;
  animation-delay: calc((var(--i, 0)) * 20ms);
}
@keyframes solved-hop {
  50% {
    translate: 0 -6px;
  }
}
.sudoku__pad {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.sudoku__pad .btn {
  min-width: 0;
  padding: 0;
  font-size: var(--t-head);
  color: var(--ink);
}

/* ---------- Coins ---------- */

.coin {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' shape-rendering='crispEdges'%3E%3Cpath d='M3 0h4v1h1v1h1v1h1v4h-1v1h-1v1h-1v1H3v-1H2v-1H1V7H0V3h1V2h1V1h1z' fill='%236B4310'/%3E%3Cpath d='M3 1h4v1h1v1h1v4H8v1H7v1H3V8H2V7H1V3h1V2h1z' fill='%23F7C14C'/%3E%3Cpath d='M3 2h2v1H4v2H3V4H2V3h1z' fill='%23FFE9A6'/%3E%3Cpath d='M4 3h2v4H4z' fill='%23E0A22E'/%3E%3C/svg%3E") 0 0 / 100% 100%;
  image-rendering: pixelated;
}

/* ---------- Buddy ---------- */

.buddy {
  position: fixed;
  left: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
  z-index: 40;
  width: 80px;
  height: 92px;
  border: 0;
  padding: 0;
  background: none;
  translate: var(--x, 20px) 0;
  transition: translate 0s;
}
.buddy pixel-pet {
  pointer-events: none;
}
.buddy__say {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: max-content;
  max-width: 260px;
  margin-bottom: 12px;
  white-space: normal;
  text-align: left;
  pointer-events: none;
}
.buddy__say[hidden] {
  display: none;
}
.buddy__zz {
  position: absolute;
  right: -4px;
  top: -6px;
  font-weight: 700;
  color: var(--ink-soft);
  pointer-events: none;
  animation: zz 1.6s steps(4) infinite;
}
@keyframes zz {
  0% {
    translate: 0 6px;
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
  100% {
    translate: 8px -14px;
    opacity: 0;
  }
}
.heart-pop {
  position: fixed;
  z-index: 41;
  width: 20px;
  height: 18px;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='9' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h3v1h2V0h3v1h1v4H9v1H8v1H7v1H6v1H4V8H3V7H2V6H1V5H0V1h1z' fill='%235E4038'/%3E%3Cpath d='M1 1h3v1h2V1h3v3H8v1H7v1H6v1H4V6H3V5H2V4H1z' fill='%23FF8FA6'/%3E%3Cpath d='M2 2h1v1H2z' fill='%23FFF'/%3E%3C/svg%3E") 0 0 / 100% 100%;
  image-rendering: pixelated;
  animation: heart-up 900ms steps(6) forwards;
}
@keyframes heart-up {
  to {
    translate: 0 -60px;
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* A shelter cushion: the pet sitting on a round cushion, its name underneath. Tiles are at least
   as wide as the longest name word, measured in the visitor's own browser (Doku.fitNames sets
   --name-min on the grid), so names only ever wrap between words and rows show as many whole
   tiles as fit. */
.cushion {
  position: relative;
  border: 0;
  padding: 6px 0 4px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 14px;
  background: none;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 20px;
}
/* The cushion sits under the pet's feet, whatever the length of the name below. */
.cushion::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 80px;
  width: 104px;
  height: 24px;
  translate: -50% 0;
  background: radial-gradient(closest-side, var(--c, var(--peach)) 96%, transparent 100%);
}
.cushion span {
  padding: 0 2px 6px;
  text-align: center;
  overflow-wrap: normal;
}
.cushion:hover pixel-pet { translate: 0 -4px; }
.cushion[aria-pressed="true"] { color: var(--ink); }
.cushion[aria-pressed="true"] span { background: linear-gradient(var(--selected-ring) 0 0) 50% 100% / 70% 3px no-repeat; }
@media (max-width: 620px) {
  /* A little less room around each name on phones, so two tiles fit side by side more often. */
  :root { --name-pad: 12px; }
}

/* ---------- Music ---------- */

/* The music button sits in the bottom-right corner, above the buddy (who stops walking short of it).
   On a phone it's just the note. */
.music {
  position: fixed;
  right: var(--gutter-r);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 42;
  min-height: 50px;
  min-width: 50px;
  padding: 0 8px;
  gap: 8px;
  color: var(--ink);
}
/* Off: the note is crossed out and the button's contents fade right back. */
.music[aria-pressed="false"] > * {
  opacity: 0.35;
}
.music__note {
  --note: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' shape-rendering='crispEdges'%3E%3Cpath d='M7 1h2v1H7zM7 2h3v1H7zM7 3h1v1H7zM9 3h2v1H9zM7 4h1v1H7zM10 4h1v1H10zM7 5h1v1H7zM10 5h1v1H10zM7 6h1v1H7zM9 6h1v1H9zM4 7h4v1H4zM3 8h5v1H3zM3 9h5v1H3zM4 10h3v1H4z'/%3E%3C/svg%3E") 0 0 / 100% 100%;
  width: 24px;
  height: 24px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--note);
  mask: var(--note);
}
.music[aria-pressed="false"] .music__note {
  --note: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h1v1H0zM1 1h1v1H1zM7 1h2v1H7zM2 2h1v1H2zM7 2h3v1H7zM3 3h1v1H3zM7 3h1v1H7zM9 3h2v1H9zM4 4h1v1H4zM7 4h1v1H7zM10 4h1v1H10zM5 5h1v1H5zM7 5h1v1H7zM10 5h1v1H10zM6 6h1v1H6zM9 6h1v1H9zM4 7h2v1H4zM7 7h1v1H7zM3 8h4v1H3zM8 8h1v1H8zM3 9h5v1H3zM9 9h1v1H9zM4 10h3v1H4zM10 10h1v1H10zM11 11h1v1H11z'/%3E%3C/svg%3E") 0 0 / 100% 100%;
}
/* While it plays, the note bobs to the beat, two game pixels at a time. */
.music[aria-pressed="true"] .music__note {
  animation: note-bob 1.2s steps(1) infinite;
}
.music[aria-busy="true"] .music__note {
  animation: note-wait 0.6s steps(1) infinite;
}
@keyframes note-bob {
  50% { translate: 0 -4px; }
}
@keyframes note-wait {
  50% { opacity: 0.3; }
}
@media (max-width: 620px) {
  .music { padding: 0; }
  .music__label { display: none; }
}

/* Privacy and support, at the very bottom of each version. */
.help-links {
  margin: 0;
  padding: 20px var(--gutter-r) 90px var(--gutter);
  text-align: center;
  font-weight: 400;
  color: var(--ink-soft);
}
.help-links a { color: inherit; font-weight: 700; text-underline-offset: 4px; }
