:root {
  color-scheme: light;
  --ink: #181818;
  --paper: #f5f2e9;
  --grass: #397a48;
  --sky: #8fcde8;
  --sun: #f4b63f;
  --danger: #b44336;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 18%, rgba(244, 182, 63, 0.3), transparent 24%),
    linear-gradient(180deg, #a9dded 0%, #dceccf 72%, #78a761 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.directory-page {
  align-items: start;
  overflow: auto;
}

.directory-shell {
  width: min(100%, 1060px);
  padding: 16px 0 32px;
}

.directory-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 18px;
}

.directory-header h1 {
  margin: 0;
  color: #202020;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1;
}

.game-directory {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(128px, 16vh);
  gap: 16px;
}

.game-tile {
  position: relative;
  display: flex;
  align-items: end;
  min-height: 128px;
  overflow: hidden;
  border: 4px solid #202020;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(245, 242, 233, 0.92), rgba(214, 235, 201, 0.88)),
    #f5f2e9;
  box-shadow: 4px 4px 0 #202020;
  color: #202020;
  text-decoration: none;
}

.game-tile--active {
  background: #8fcde8;
}

.game-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-tile::after {
  position: absolute;
  inset: auto 0 0 0;
  height: 58%;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.7));
  content: "";
}

.game-tile:not(.game-tile--active)::after {
  background: linear-gradient(180deg, transparent, rgba(245, 242, 233, 0.72));
}

.game-tile span {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  padding: 14px 16px;
  color: #fffdf6;
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.48);
}

.game-tile:not(.game-tile--active) span {
  color: rgba(32, 32, 32, 0.5);
  text-shadow: none;
}

.game-tile--active:hover,
.game-tile--active:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #202020;
  outline: none;
}

.game-page {
  align-content: center;
  gap: 14px;
}

.game-page-header {
  display: grid;
  grid-template-columns: 96px 1fr 96px;
  align-items: center;
  width: min(100%, 960px);
}

.game-page-header h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1;
}

.home-link {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  min-height: 38px;
  border: 3px solid #202020;
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(245, 242, 233, 0.9);
  box-shadow: 3px 3px 0 #202020;
  color: #202020;
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
  text-transform: uppercase;
}

.home-link:hover,
.home-link:focus-visible {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 #202020;
  outline: none;
}

.game-shell {
  position: relative;
  width: min(100%, 960px);
  aspect-ratio: 16 / 9;
  border: 4px solid #202020;
  border-radius: 8px;
  overflow: hidden;
  background: var(--sky);
  box-shadow: 0 18px 50px rgba(25, 35, 18, 0.22);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  inset: 18px 18px auto 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.status,
.scoreboard {
  min-height: 44px;
  border: 3px solid #202020;
  border-radius: 8px;
  background: rgba(245, 242, 233, 0.88);
  box-shadow: 3px 3px 0 #202020;
}

.status {
  display: flex;
  align-items: center;
  max-width: min(56vw, 360px);
  padding: 0 14px;
  font-size: clamp(14px, 1.7vw, 18px);
  font-weight: 800;
}

.scoreboard {
  display: grid;
  grid-template-columns: auto 48px;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
}

.scoreboard span {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.scoreboard strong {
  min-width: 38px;
  text-align: right;
  font-size: 28px;
  line-height: 1;
}

.controls {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;
}

button {
  width: 64px;
  height: 64px;
  border: 3px solid #202020;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 3px 3px 0 #202020;
  color: #202020;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #202020;
}

.leaderboard {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 210px;
  border: 3px solid #202020;
  border-radius: 8px;
  background: rgba(245, 242, 233, 0.9);
  box-shadow: 3px 3px 0 #202020;
  color: #202020;
}

.leaderboard__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 6px 8px 4px 10px;
  border-bottom: 2px solid rgba(32, 32, 32, 0.18);
}

.leaderboard h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button {
  width: 28px;
  height: 28px;
  border-width: 2px;
  border-radius: 50%;
  box-shadow: 2px 2px 0 #202020;
  font-size: 17px;
}

.leaderboard__list {
  min-height: 104px;
  max-height: 126px;
  margin: 0;
  padding: 8px 10px 9px 30px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
}

.leaderboard__list li {
  padding: 1px 0;
}

.leaderboard__score {
  float: right;
  font-variant-numeric: tabular-nums;
}

.score-form {
  padding: 8px 10px 10px;
  border-top: 2px solid rgba(32, 32, 32, 0.18);
}

.score-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.score-form__row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 6px;
}

.score-form input {
  min-width: 0;
  height: 34px;
  border: 2px solid #202020;
  border-radius: 6px;
  padding: 0 8px;
  background: #fffdf6;
  color: #202020;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
}

.score-form button {
  width: auto;
  height: 34px;
  border-width: 2px;
  border-radius: 6px;
  box-shadow: 2px 2px 0 #202020;
  font-size: 12px;
}

.restart-dialog {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(32, 32, 32, 0.24);
}

.restart-dialog[hidden] {
  display: none;
}

.restart-dialog__panel {
  width: min(84%, 330px);
  border: 4px solid #202020;
  border-radius: 8px;
  padding: 24px;
  background: rgba(245, 242, 233, 0.96);
  box-shadow: 5px 5px 0 #202020;
  text-align: center;
}

.restart-dialog h2 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1;
}

.restart-dialog p {
  margin: 0 0 18px;
  font-size: 15px;
  font-weight: 800;
}

.restart-button {
  width: auto;
  height: 46px;
  min-width: 156px;
  border-radius: 8px;
  padding: 0 16px;
  font-size: 15px;
  text-transform: uppercase;
}

@media (pointer: coarse) {
  .controls {
    display: block;
  }
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  .directory-page {
    place-items: start center;
  }

  .game-page {
    align-content: center;
    gap: 10px;
  }

  .game-page-header {
    grid-template-columns: 76px 1fr 76px;
  }

  .home-link {
    min-height: 32px;
    border-width: 2px;
    padding: 0 10px;
    box-shadow: 2px 2px 0 #202020;
    font-size: 12px;
  }

  .directory-shell {
    padding-top: 6px;
  }

  .directory-header {
    margin-bottom: 12px;
  }

  .game-directory {
    grid-template-columns: 1fr;
    grid-auto-rows: 118px;
    gap: 12px;
  }

  .hud {
    inset: 10px 10px auto 10px;
  }

  .status,
  .scoreboard {
    min-height: 38px;
    border-width: 2px;
    box-shadow: 2px 2px 0 #202020;
  }

  .status {
    padding: 0 10px;
  }

  .scoreboard {
    grid-template-columns: auto 34px;
    gap: 6px;
    padding: 0 9px;
  }

  .scoreboard strong {
    min-width: 28px;
    font-size: 22px;
  }

  .leaderboard {
    right: 10px;
    bottom: 10px;
    width: 180px;
  }

  .leaderboard__list {
    min-height: 78px;
    max-height: 78px;
    padding-left: 28px;
    font-size: 12px;
  }

  .score-form {
    padding: 7px 8px 8px;
  }
}
