:root {
  color-scheme: light;
  --ink: #171b18;
  --muted: #65706b;
  --panel: rgba(250, 251, 246, 0.94);
  --panel-strong: #ffffff;
  --line: rgba(31, 42, 35, 0.18);
  --field: #426f46;
  --field-dark: #2f5639;
  --chalk: #f7f9ef;
  --gold: #d49a2f;
  --orange: #d65f2c;
  --charcoal: #1d2420;
  --shadow: rgba(14, 22, 17, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.64), rgba(255, 255, 255, 0.08)),
    linear-gradient(135deg, #d6e4cf 0%, #f2e3bf 48%, #cad4da 100%);
  display: grid;
  place-items: center;
  padding: clamp(12px, 2.8vw, 28px);
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.game-shell {
  width: min(100%, 1180px);
  min-height: min(760px, calc(100vh - 24px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: stretch;
  touch-action: manipulation;
}

.game-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef4e7;
  box-shadow: 0 26px 70px var(--shadow);
  touch-action: none;
}

.game-mount {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 520px;
  background: #eff5ec;
  touch-action: manipulation;
}

.game-mount canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.start-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
  background: rgba(239, 245, 236, 0.68);
  backdrop-filter: blur(6px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.start-layer.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay-label,
.status-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 9ch;
  font-size: clamp(3rem, 8vw, 6.8rem);
  line-height: 0.88;
}

h2 {
  margin-top: 4px;
  font-size: 1.55rem;
  line-height: 1;
}

.overlay-meta {
  margin: 0;
  color: #38443d;
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 700;
}

.primary-button,
.icon-button,
.touch-button {
  border: 0;
  border-radius: 8px;
  color: #fffaf0;
  background: var(--charcoal);
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(29, 36, 32, 0.2);
}

.primary-button {
  min-width: 150px;
  min-height: 52px;
  padding: 0 24px;
  font-weight: 850;
}

.primary-button:hover,
.icon-button:hover,
.touch-button:hover {
  filter: brightness(1.08);
}

.primary-button:focus-visible,
.icon-button:focus-visible,
.touch-button:focus-visible {
  outline: 3px solid rgba(212, 154, 47, 0.55);
  outline-offset: 3px;
}

.game-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 58px rgba(14, 22, 17, 0.16);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.live-dot {
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 0 5px rgba(212, 154, 47, 0.18);
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.pet-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(31, 42, 35, 0.07);
  padding: 4px;
}

.pet-option {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 850;
  cursor: pointer;
}

.pet-option:hover {
  background: rgba(255, 255, 255, 0.62);
}

.pet-option:focus-visible {
  outline: 3px solid rgba(212, 154, 47, 0.55);
  outline-offset: 2px;
}

.pet-option.is-selected {
  color: #fffaf0;
  background: var(--charcoal);
  box-shadow: 0 8px 18px rgba(29, 36, 32, 0.17);
}

.score-cell {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 13px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.score-cell span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.score-cell strong {
  color: var(--ink);
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1;
}

.panel-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.demo-button {
  background: var(--field-dark);
}

.icon-button {
  min-height: 48px;
  font-weight: 900;
}

.touch-controls {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 10px;
}

.touch-button {
  min-height: 58px;
  font-size: 1.45rem;
  font-weight: 900;
  background: var(--field-dark);
  touch-action: none;
}

.touch-button.jump {
  background: var(--orange);
}

@media (max-width: 900px) {
  body {
    align-items: start;
    padding: 8px;
  }

  .game-shell {
    min-height: 0;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .game-mount {
    min-height: 52vw;
  }

  .game-panel {
    padding: 12px;
    gap: 10px;
  }

  .score-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .score-cell {
    min-height: 58px;
    padding: 8px;
  }

  .touch-controls {
    margin-top: 0;
    gap: 8px;
  }

  .touch-button {
    min-height: 64px;
    font-size: 1.6rem;
  }
}

@media (max-width: 620px) {
  body {
    padding: 6px;
  }

  .game-shell {
    gap: 6px;
  }

  .game-mount {
    min-height: 56vw;
  }

  .score-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .score-cell {
    min-height: 50px;
    padding: 6px;
  }

  .score-cell strong {
    font-size: 1.1rem;
  }

  .panel-header {
    gap: 6px;
  }

  h2 {
    font-size: 1.2rem;
  }

  h1 {
    font-size: clamp(2.7rem, 15vw, 4.6rem);
  }

  .touch-controls {
    gap: 6px;
  }

  .touch-button {
    min-height: 72px;
    font-size: 1.8rem;
    border-radius: 12px;
  }

  .touch-button.jump {
    min-height: 72px;
  }

  .pet-switch {
    gap: 3px;
    padding: 3px;
  }

  .pet-option {
    min-height: 38px;
  }

  .panel-actions {
    gap: 6px;
  }

  .icon-button {
    min-height: 44px;
  }
}

@media (max-height: 680px) and (max-width: 900px) {
  .game-mount {
    min-height: 44vw;
  }

  .score-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .score-cell {
    min-height: 44px;
    padding: 5px;
  }

  .touch-button {
    min-height: 60px;
  }
}
