:root {
  font-family: "Trebuchet MS", Arial, sans-serif;
  color: #18332a;
  background: #f3f7f4;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 12% 15%, rgba(179, 223, 197, 0.34), transparent 28%),
    radial-gradient(circle at 90% 85%, rgba(204, 226, 214, 0.46), transparent 30%),
    #f3f7f4;
}

button {
  font: inherit;
}

.intro-screen {
  position: fixed;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #fff;
  background:
    radial-gradient(circle at 50% 42%, rgba(61, 157, 101, 0.3), transparent 34%),
    #10271d;
  opacity: 1;
  transition: opacity 350ms ease, visibility 350ms ease;
}

.intro-screen.is-dismissed {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.intro-content {
  width: min(100%, 360px);
  text-align: center;
}

.intro-kicker {
  margin: 0 0 10px;
  color: #a9d8b7;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.3em;
}

.intro-content h1 {
  margin: 0;
  font-size: clamp(2.5rem, 11vw, 4rem);
  letter-spacing: 0.04em;
}

.intro-loader {
  overflow: hidden;
  width: min(100%, 230px);
  height: 5px;
  margin: 28px auto 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.2);
}

.intro-loader span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: #8dd6a5;
  transform: scaleX(0);
  transform-origin: left;
  animation: intro-loading 5s linear forwards;
}

.intro-caption {
  margin: 0;
  color: #ccded1;
  font-size: 0.9rem;
}

@keyframes intro-loading {
  to {
    transform: scaleX(1);
  }
}

.game-card {
  width: min(100%, 480px);
  padding: 30px;
  border: 1px solid #e4ece6;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 70px rgba(35, 72, 53, 0.11);
}

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

.eyebrow,
.score-label {
  margin: 0;
  color: #789185;
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

h1 {
  margin: 5px 0 0;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: clamp(1.8rem, 7vw, 2.3rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.score-card {
  min-width: 82px;
  padding: 9px 14px 8px;
  border: 1px solid #e5eee8;
  border-radius: 14px;
  background: #f7faf8;
  text-align: center;
}

.score-label,
#score {
  display: block;
}

#score {
  margin-top: 1px;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.game-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1;
  border: 5px solid #e7f0e9;
  border-radius: 16px;
  background: #f8fbf8;
}

#game-board {
  display: block;
  width: 100%;
  height: 100%;
}

.game-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  color: #426353;
  font-size: clamp(0.9rem, 4vw, 1.05rem);
  font-weight: 600;
  text-align: center;
  pointer-events: none;
}

.game-message.is-hidden {
  display: none;
}

.game-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.button {
  min-height: 48px;
  flex: 1;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:focus-visible,
.direction-button:focus-visible {
  outline: 3px solid #a5d7b5;
  outline-offset: 3px;
}

.button-primary {
  color: #fff;
  background: #278653;
  box-shadow: 0 7px 16px rgba(39, 134, 83, 0.19);
}

.button-primary:hover {
  background: #207548;
}

.button-secondary {
  color: #286943;
  background: #eaf5ed;
}

.button-secondary:hover {
  background: #dff0e4;
}

.button[hidden] {
  display: none;
}

.mobile-controls {
  display: none;
}

.controls-hint {
  margin: 14px 0 0;
  color: #82958a;
  font-size: 0.82rem;
  text-align: center;
}

@media (max-width: 520px) {
  .game-card {
    padding: clamp(18px, 5vw, 26px);
    border-radius: 20px;
  }

  .game-frame {
    border-width: 4px;
    border-radius: 13px;
  }

  .mobile-controls {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(2, 46px);
    justify-content: center;
    gap: 7px;
    margin: 17px auto 0;
  }

  .direction-button {
    border: 1px solid #deebe1;
    border-radius: 12px;
    color: #286943;
    background: #f4f9f5;
    cursor: pointer;
    font-size: 1rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .direction-button:active {
    background: #e2f1e6;
  }

  .direction-up {
    grid-column: 2;
    grid-row: 1;
  }

  .direction-left {
    grid-column: 1;
    grid-row: 2;
  }

  .direction-down {
    grid-column: 2;
    grid-row: 2;
  }

  .direction-right {
    grid-column: 3;
    grid-row: 2;
  }
}

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