:root {
  --ink: #24313f;
  --muted: #6c7a89;
  --paper: #f6f1e8;
  --sky: #9bd8ff;
  --grass: #4f8f5f;
  --grass-dark: #276443;
  --dino: #2f6f4f;
  --dino-dark: #1e4c38;
  --cactus: #2b7c5a;
  --cactus-dark: #1d5d42;
  --danger: #c84c35;
}

* {
  box-sizing: border-box;
}

body {
  align-items: stretch;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.7), transparent 26rem),
    linear-gradient(160deg, #dff3ff 0%, #fbf2db 58%, #f4d4a1 100%);
  color: var(--ink);
  display: flex;
  font-family: "Courier New", Consolas, monospace;
  font-weight: 700;
  justify-content: center;
  margin: 0;
  min-height: 100vh;
  padding: clamp(10px, 2.5vw, 24px);
}

.game-shell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - clamp(20px, 5vw, 48px));
  width: min(1180px, 100%);
}

.game-header {
  align-items: end;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 14px;
}

h1 {
  font-size: clamp(1.15rem, 4vw, 2.35rem);
  line-height: 1.2;
  margin: 0;
}

.header-actions {
  align-items: center;
  display: flex;
  gap: 16px;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  font-size: clamp(0.68rem, 1.8vw, 0.95rem);
  gap: 14px;
  justify-content: flex-end;
  line-height: 1.8;
  text-align: right;
}

.scoreboard strong {
  color: var(--danger);
  font-weight: 700;
}

.game {
  aspect-ratio: 16 / 7;
  background: linear-gradient(var(--sky) 0 68%, #d9b879 68% 100%);
  border: 4px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 18px 0 rgba(36, 49, 63, 0.12);
  cursor: pointer;
  min-height: 420px;
  overflow: hidden;
  position: relative;
  user-select: none;
}

.game:focus {
  outline: 4px solid rgba(200, 76, 53, 0.35);
  outline-offset: 4px;
}

.sky {
  inset: 0;
  overflow: hidden;
  position: absolute;
}

.sun {
  background: #ffd261;
  border: 4px solid #d99631;
  border-radius: 50%;
  height: 58px;
  position: absolute;
  right: 7%;
  top: 12%;
  width: 58px;
}

.cloud {
  animation: drift linear infinite;
  background: #fff;
  border: 3px solid rgba(36, 49, 63, 0.18);
  border-radius: 999px;
  height: 26px;
  position: absolute;
  width: 86px;
}

.cloud::before,
.cloud::after {
  background: inherit;
  border: inherit;
  border-bottom: 0;
  border-radius: 50% 50% 0 0;
  content: "";
  position: absolute;
}

.cloud::before {
  height: 28px;
  left: 13px;
  top: -17px;
  width: 31px;
}

.cloud::after {
  height: 36px;
  right: 14px;
  top: -24px;
  width: 38px;
}

.cloud-one {
  animation-duration: 25s;
  top: 22%;
}

.cloud-two {
  animation-delay: -9s;
  animation-duration: 31s;
  top: 38%;
  transform: scale(0.7);
}

.cloud-three {
  animation-delay: -17s;
  animation-duration: 36s;
  top: 16%;
  transform: scale(0.85);
}

.ground {
  background:
    repeating-linear-gradient(90deg, transparent 0 28px, rgba(39, 100, 67, 0.35) 28px 36px),
    linear-gradient(var(--grass) 0 22px, var(--grass-dark) 22px 28px, transparent 28px);
  bottom: 82px;
  height: 28px;
  left: 0;
  position: absolute;
  right: 0;
}

.dino {
  --dino-bottom: 108px;
  background: var(--dino);
  border: 4px solid var(--dino-dark);
  border-radius: 13px 13px 8px 8px;
  bottom: var(--dino-bottom);
  height: 74px;
  left: 10%;
  position: absolute;
  width: 72px;
  z-index: 5;
}

.dino::before {
  background: var(--dino);
  border: 4px solid var(--dino-dark);
  border-bottom: 0;
  border-radius: 12px 12px 4px 4px;
  content: "";
  height: 42px;
  position: absolute;
  right: -18px;
  top: -32px;
  width: 54px;
}

.dino::after {
  background: var(--dino);
  border: 4px solid var(--dino-dark);
  border-right: 0;
  border-radius: 30px 0 0 30px;
  content: "";
  height: 24px;
  left: -34px;
  position: absolute;
  top: 28px;
  transform: rotate(-18deg);
  width: 42px;
}

.eye {
  background: var(--ink);
  border-radius: 50%;
  height: 7px;
  position: absolute;
  right: 5px;
  top: -16px;
  width: 7px;
  z-index: 2;
}

.mouth {
  background: var(--dino-dark);
  height: 4px;
  position: absolute;
  right: -11px;
  top: -1px;
  width: 22px;
  z-index: 2;
}

.arm {
  background: var(--dino-dark);
  border-radius: 8px;
  height: 7px;
  position: absolute;
  right: 12px;
  top: 26px;
  width: 24px;
}

.leg {
  animation: run 0.22s steps(2) infinite;
  background: var(--dino-dark);
  bottom: -26px;
  height: 28px;
  position: absolute;
  width: 14px;
}

.leg-front {
  right: 10px;
}

.leg-back {
  animation-delay: 0.11s;
  left: 12px;
}

.dino.jumping .leg,
.dino.ducking .leg,
.game.paused .leg {
  animation-play-state: paused;
}

.dino.ducking {
  height: 45px;
  width: 88px;
}

.dino.ducking::before {
  right: -14px;
  top: -19px;
}

.dino.ducking .eye {
  top: -3px;
}

.dino.ducking .mouth {
  top: 12px;
}

.obstacle {
  bottom: 106px;
  position: absolute;
  z-index: 4;
}

.cactus {
  background: var(--cactus);
  border: 4px solid var(--cactus-dark);
  border-radius: 8px 8px 4px 4px;
  height: 62px;
  width: 28px;
}

.cactus::before,
.cactus::after {
  background: var(--cactus);
  border: 4px solid var(--cactus-dark);
  content: "";
  height: 24px;
  position: absolute;
  top: 18px;
  width: 18px;
}

.cactus::before {
  border-right: 0;
  border-radius: 10px 0 0 10px;
  left: -18px;
}

.cactus::after {
  border-left: 0;
  border-radius: 0 10px 10px 0;
  right: -18px;
  top: 30px;
}

.rock {
  background: #80644b;
  border: 4px solid #543f31;
  border-radius: 50% 48% 10px 12px;
  height: 34px;
  width: 50px;
}

.bird {
  background: #6954a8;
  border: 4px solid #3d326e;
  border-radius: 50%;
  height: 24px;
  width: 46px;
}

.bird::before,
.bird::after {
  background: #6954a8;
  border: 4px solid #3d326e;
  content: "";
  height: 12px;
  position: absolute;
  top: -8px;
  width: 24px;
}

.bird::before {
  border-radius: 18px 18px 0 18px;
  left: -6px;
  transform: rotate(-18deg);
}

.bird::after {
  border-radius: 18px 18px 18px 0;
  right: -6px;
  transform: rotate(18deg);
}

.message {
  align-items: center;
  background: rgba(246, 241, 232, 0.86);
  border: 4px solid var(--ink);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  left: 50%;
  line-height: 1.7;
  max-width: min(520px, calc(100% - 32px));
  padding: 18px;
  position: absolute;
  text-align: center;
  top: 45%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.message.hidden {
  display: none;
}

.message p {
  margin: 0;
}

.message small {
  color: var(--muted);
  font-size: clamp(0.45rem, 1.5vw, 0.65rem);
}

.touch-controls {
  display: none;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
}

button {
  background: var(--ink);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  min-width: 120px;
  padding: 14px 16px;
  touch-action: manipulation;
}

.sound-toggle {
  align-items: center;
  aspect-ratio: 1;
  display: inline-flex;
  flex: 0 0 auto;
  justify-content: center;
  min-width: 0;
  padding: 0;
  width: 46px;
}

.sound-icon {
  border-bottom: 9px solid transparent;
  border-right: 13px solid #fff;
  border-top: 9px solid transparent;
  height: 20px;
  position: relative;
  width: 20px;
}

.sound-icon::before {
  background: #fff;
  border-radius: 2px;
  content: "";
  height: 14px;
  left: -7px;
  position: absolute;
  top: -7px;
  width: 8px;
}

.sound-icon::after {
  border: 3px solid #fff;
  border-bottom-color: transparent;
  border-left: 0;
  border-top-color: transparent;
  border-radius: 0 999px 999px 0;
  content: "";
  height: 24px;
  left: 11px;
  position: absolute;
  top: -12px;
  width: 14px;
}

.sound-toggle.muted .sound-icon::after {
  background: #fff;
  border: 0;
  border-radius: 999px;
  height: 4px;
  left: 10px;
  top: -2px;
  transform: rotate(-35deg);
  width: 25px;
}

button:active {
  transform: translateY(2px);
}

@keyframes drift {
  from {
    left: 100%;
  }

  to {
    left: -130px;
  }
}

@keyframes run {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(8px);
  }
}

@media (max-width: 720px) {
  body {
    min-height: 100svh;
    padding: 10px;
  }

  .game-header {
    align-items: center;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
  }

  .header-actions {
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  .scoreboard {
    font-size: clamp(0.72rem, 3.4vw, 0.86rem);
    justify-content: flex-start;
    text-align: left;
  }

  .game {
    aspect-ratio: auto;
    border-width: 3px;
    min-height: min(64svh, 590px);
  }

  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 12px;
  }

  .message {
    font-size: clamp(0.72rem, 3vw, 0.9rem);
    padding: 14px;
  }

  .message small {
    font-size: 0.6rem;
  }

  button {
    font-size: clamp(0.78rem, 3.3vw, 0.92rem);
    min-height: 54px;
    min-width: 0;
    padding-inline: 10px;
  }

  .sound-toggle {
    height: 46px;
    min-height: 0;
    width: 46px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 1.08rem;
  }

  .game {
    min-height: 62svh;
  }

  .touch-controls {
    gap: 8px;
  }
}
