@font-face {
  font-family: "Spill Hand";
  src: url("/assets/fonts/patrick-hand-regular.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

:root {
  color-scheme: light;
  --wood: #76502f;
  --paper: #ead9b7;
  --paper-light: #f1e4c9;
  --graphite: #3d392f;
  --graphite-soft: #625b4d;
  --moss: #63724d;
  --moss-dark: #46543a;
  --pencil-blue: #7f8d94;
  --focus-light: #fff3cf;
  --hand: "Spill Hand", "Chalkboard SE", "Bradley Hand", cursive;
  --body: "Avenir Next", Avenir, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--wood);
}

body {
  min-height: 100%;
  margin: 0;
  padding: clamp(0rem, 2.2vw, 1.5rem);
  background-color: var(--wood);
  background-image: url("/assets/sketchbook/desk-book-sewn.webp");
  background-position: center;
  background-size: cover;
  color: var(--graphite);
  font-family: var(--body);
}

button,
a {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus-light);
  outline-offset: 3px;
  box-shadow: 0 0 0 7px #2c2923;
}

.game-page {
  position: relative;
  isolation: isolate;
  width: min(100%, 53rem);
  min-height: calc(100svh - clamp(0rem, 4.4vw, 3rem));
  margin: 0 auto;
  overflow: hidden;
  padding:
    clamp(5.8rem, 7vw, 7rem)
    clamp(3rem, 5.4vw, 4.5rem)
    clamp(4rem, 7vw, 6rem)
    clamp(5.5rem, 10vw, 7.5rem);
  border: 0;
  background-color: transparent;
  background-image: url("/assets/sketchbook/collection-sewn-page.webp");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-shadow: none;
}

#paper-light {
  position: absolute;
  z-index: -1;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.22;
  mix-blend-mode: multiply;
}

.back-link {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  color: var(--graphite);
  font-family: var(--hand);
  font-size: clamp(1rem, 2.6vw, 1.3rem);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.32rem;
}

.back-link:hover {
  color: var(--moss-dark);
  text-decoration: underline;
}

.game-intro {
  margin: clamp(0.8rem, 2.8vw, 1.8rem) auto 0;
  text-align: center;
}

.game-intro h1 {
  margin: 0;
  font-family: var(--hand);
  font-size: clamp(2.8rem, 6.5vw, 4.5rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.035em;
}

.game-intro p {
  max-width: 35rem;
  margin: 1rem auto 0;
  color: var(--graphite-soft);
  font-family: var(--hand);
  font-size: clamp(1.05rem, 3vw, 1.45rem);
  line-height: 1.35;
}

.game-choices {
  display: grid;
  gap: 1.25rem;
  width: min(100%, 41rem);
  margin: clamp(1.5rem, 4vw, 2.4rem) auto;
}

fieldset {
  min-width: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

legend {
  width: 100%;
  margin-bottom: 0.7rem;
  color: var(--graphite-soft);
  font-family: var(--hand);
  font-size: 1.02rem;
  text-align: center;
}

.choice-row {
  display: grid;
  gap: clamp(0.55rem, 2vw, 1rem);
}

.choice-row--mode {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-row--difficulty {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.paper-choice,
#play-again {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.15rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid rgb(92 71 45 / 48%);
  border-radius: 1px;
  background-color: #dfc99f;
  background-image: url("/assets/sketchbook/page-back.webp");
  background-position: 43% 47%;
  background-size: 380%;
  color: var(--graphite);
  box-shadow:
    0 0.28rem 0.55rem rgb(66 43 22 / 20%),
    inset 0 0 0.5rem rgb(93 67 37 / 8%);
  cursor: pointer;
  font-family: var(--hand);
  font-size: clamp(0.88rem, 2.6vw, 1.15rem);
  line-height: 1.08;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    color 160ms ease;
}

.paper-choice:nth-child(odd) {
  transform: rotate(-0.45deg);
}

.paper-choice:nth-child(even) {
  transform: rotate(0.4deg);
}

.paper-choice {
  flex-direction: column;
  gap: 0.12rem;
}

.mode-pictures {
  display: flex;
  height: 1.8rem;
  align-items: center;
  justify-content: center;
}

.mode-pictures img {
  width: 2.15rem;
  height: 2.15rem;
  object-fit: contain;
}

.mode-pictures--together img {
  width: 1.85rem;
  height: 1.85rem;
  margin-inline: -0.08rem;
}

.difficulty-leaves {
  display: flex;
  height: 1.15rem;
  align-items: center;
  justify-content: center;
}

.difficulty-leaves img {
  width: 1.12rem;
  height: 1.12rem;
  margin-inline: -0.12rem;
  object-fit: contain;
}

.paper-choice:hover,
#play-again:hover {
  color: var(--moss-dark);
  transform: translateY(-2px) rotate(0deg);
}

.paper-choice:active,
#play-again:active {
  transform: translateY(2px) scale(0.98);
}

.paper-choice.is-selected {
  border: 2px solid var(--moss-dark);
  background-color: #d8c69e;
  color: var(--moss-dark);
  box-shadow:
    0 0.28rem 0.55rem rgb(66 43 22 / 18%),
    inset 0 0 0 3px rgb(70 84 58 / 24%),
    inset 0 -0.2rem 0 rgb(99 114 77 / 52%);
}

.difficulty-choice[hidden] {
  display: none;
}

.play-area {
  width: min(100%, 39rem);
  margin: 0 auto;
}

.friend-board {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 2.7%;
  background-color: var(--paper-light);
  background-image: url("./assets/tre-sma-venner-board.webp");
  background-position: center;
  background-size: cover;
  filter: drop-shadow(0 0.75rem 0.8rem rgb(70 45 23 / 13%));
}

.friend-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.friend-cell:hover:not(:disabled) {
  background: rgb(255 247 218 / 20%);
}

.friend-cell:disabled {
  cursor: default;
}

.friend-cell[data-winning="true"] {
  background: rgb(235 221 171 / 28%);
}

.friend-cell img {
  display: block;
  width: 78%;
  height: 78%;
  object-fit: contain;
  animation: friend-arrives 360ms cubic-bezier(0.3, 0.9, 0.35, 1.18) both;
  pointer-events: none;
  user-select: none;
}

.turn-status {
  display: flex;
  min-height: 2.9em;
  max-width: 36rem;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin: clamp(1rem, 3vw, 1.6rem) auto 0;
  color: var(--graphite-soft);
  font-family: var(--hand);
  font-size: clamp(1.02rem, 3vw, 1.3rem);
  line-height: 1.35;
  text-align: center;
}

.turn-friend {
  width: 3.15rem;
  height: 3.15rem;
  flex: 0 0 auto;
  object-fit: contain;
}

.game-actions {
  display: flex;
  justify-content: center;
  margin-top: 0.8rem;
}

#play-again {
  min-width: 12rem;
  padding-inline: 1.4rem;
  font-size: 1.1rem;
}

.webgl-fallback {
  max-width: 32rem;
  margin: 1rem auto 0;
  color: var(--pencil-blue);
  font-family: var(--hand);
  text-align: center;
}

@keyframes friend-arrives {
  from {
    opacity: 0;
    transform: translateY(0.45rem) scale(0.82) rotate(-4deg);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

@media (min-width: 561px) {
  body {
    display: grid;
    min-height: 100svh;
    place-items: center;
    padding: 1rem;
    background-image: url("./assets/tre-sma-venner-walnut-desk.webp");
    background-position: center;
    background-size: cover;
  }

  .game-page {
    display: grid;
    width: min(96vw, 141svh, 78rem);
    min-height: 0;
    aspect-ratio: 3 / 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto 1fr auto auto;
    column-gap: 20%;
    align-content: stretch;
    padding: 7% 8.5% 6.5%;
    background-image: url("./assets/tre-sma-venner-desktop-sewn-book.webp");
    background-size: cover;
  }

  .back-link {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
  }

  .game-intro {
    grid-column: 1;
    grid-row: 2;
    margin: 0.7rem 0 0;
    text-align: left;
  }

  .game-intro h1 {
    font-size: clamp(2.35rem, 5vw, 4rem);
  }

  .game-intro p {
    margin: 0.75rem 0 0;
  }

  .game-choices {
    grid-column: 1;
    grid-row: 3 / 6;
    align-self: start;
    width: 100%;
    margin: clamp(1.2rem, 2.5vh, 2rem) 0 0;
  }

  .play-area {
    grid-column: 2;
    grid-row: 1 / 4;
    align-self: center;
    width: 100%;
  }

  .friend-board {
    width: min(100%, 27rem);
    margin-inline: auto;
  }

  .turn-status {
    grid-column: 2;
    grid-row: 4;
    min-height: 2.7em;
    margin-top: 0.5rem;
  }

  .game-actions {
    grid-column: 2;
    grid-row: 5;
    margin-top: 0.35rem;
  }

  .webgl-fallback {
    position: absolute;
    right: 10%;
    bottom: 5.5%;
    width: 32%;
  }
}

@media (min-width: 561px) and (max-width: 899px) {
  .game-page {
    padding-block: 6%;
  }

  .back-link {
    min-height: 2rem;
    font-size: 0.92rem;
  }

  .game-intro {
    margin-top: 0.35rem;
  }

  .game-intro h1 {
    font-size: clamp(2rem, 5vw, 2.8rem);
  }

  .game-intro p {
    margin-top: 0.35rem;
    font-size: 1rem;
  }

  .game-choices {
    gap: 0.55rem;
    margin-top: 0.65rem;
  }

  legend {
    margin-bottom: 0.3rem;
    font-size: 0.86rem;
  }

  .choice-row--mode .paper-choice {
    flex-direction: row;
    gap: 0.25rem;
    min-height: 3.1rem;
    padding: 0.3rem;
    font-size: 0.9rem;
  }

  .choice-row--mode .mode-pictures {
    height: 1.4rem;
  }

  .choice-row--mode .mode-pictures img {
    width: 1.55rem;
    height: 1.55rem;
  }

  .choice-row--difficulty {
    gap: 0.3rem;
  }

  .choice-row--difficulty .paper-choice {
    min-height: 3.1rem;
    padding: 0.25rem;
    font-size: 0.86rem;
  }
}

@media (max-width: 560px) {
  body {
    padding: 0;
  }

  .game-page {
    width: 100%;
    min-height: 100svh;
    padding:
      max(1rem, env(safe-area-inset-top))
      0.9rem
      max(1.5rem, env(safe-area-inset-bottom))
      3.4rem;
    border: 0;
    border-radius: 0;
    background-color: var(--paper);
    background-image: url("./assets/tre-sma-venner-sewn-page.webp");
    background-position: center top;
    background-size: 100% 100%;
    box-shadow: none;
  }

  .back-link {
    margin-left: 0;
  }

  .game-intro {
    margin-top: 0.5rem;
  }

  .game-intro h1 {
    font-size: clamp(2.35rem, 11.5vw, 3.15rem);
  }

  .game-intro p {
    max-width: 19rem;
    margin-top: 0.65rem;
    font-size: 1.05rem;
  }

  .game-choices {
    gap: 0.75rem;
    margin-block: 0.9rem;
  }

  legend {
    margin-bottom: 0.5rem;
    font-size: 0.92rem;
  }

  .paper-choice {
    min-height: 3rem;
    padding-inline: 0.35rem;
    font-size: 0.88rem;
  }

  .friend-board {
    width: min(100%, 25rem);
    margin-inline: auto;
  }

  .turn-status {
    margin-top: 0.55rem;
    font-size: 1rem;
  }
}

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