:root {
  --bg-top: #6f4b43;
  --bg-bottom: #b78b69;
  --panel: #fff9ee;
  --ink: #27343d;
  --accent: #f2a51a;
  --surface-stroke: #b58d75;
  --surface-shadow: #1f2c3d42;
  --overlay-veil: #3b3f5526;
  --menu-card: #67516478;
  --menu-card-stroke: #ffffff2e;
  --btn-primary-bg: #ffe8ab;
  --btn-primary-ink: #3e2f19;
  --btn-secondary-bg: #eff3f7;
  --btn-secondary-ink: #27343d;
  --btn-ghost-ink: #fff8e4;
  --canvas-frame: #7d5a48;
  --font-pixel: "Silkscreen", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.35rem;
  font-family: var(--font-pixel);
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 14%, #f6dfc570 0 11%, transparent 12%),
    radial-gradient(circle at 82% 24%, #f3dcc05a 0 10%, transparent 11%),
    repeating-linear-gradient(
      45deg,
      #fbe7d20f 0 14px,
      transparent 14px 28px
    ),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.game-shell {
  width: min(1000px, 93vw);
  background: #c8ab92e8;
  color: #1f262d;
  border: none;
  border-radius: 18px;
  box-shadow: 0 20px 52px #2d1f1b45;
  padding: 1.1rem 1.1rem 1.3rem;
  animation: shellIn 320ms ease-out both;
}

h1 {
  margin: 0;
  text-align: center;
  letter-spacing: 0.03em;
  color: #1e262d;
  font-size: clamp(1.8rem, 2.2vw + 0.9rem, 2.65rem);
}

.subtitle {
  margin: 0.48rem 0 0.9rem;
  text-align: center;
  color: #22303a;
  font-size: clamp(0.93rem, 1vw + 0.45rem, 1.08rem);
}

.asset-credit {
  margin: 0.52rem 0 0;
  font-size: 0.72rem;
  text-align: center;
  color: #2a3138;
  opacity: 1;
}

.asset-credit a {
  color: #1c4b69;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.asset-credit a:hover {
  color: #143449;
}

.page-help-btn {
  appearance: none;
  border: 1px solid #947864;
  background: #efe2d1;
  color: #2b2f35;
  border-radius: 8px;
  padding: 0.36rem 0.56rem;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.1;
}

.page-help-btn:hover {
  background: #e6d5c2;
}

.page-bottom-actions {
  margin: 0.8rem 0 0.35rem;
  display: flex;
  justify-content: center;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  border: 4px solid var(--canvas-frame);
  box-shadow: inset 0 0 0 1px #b9987f80;
  background: #a5dbff;
  cursor: crosshair;
  touch-action: none;
  image-rendering: pixelated;
}

.canvas-wrap {
  position: relative;
}

.menu-overlay {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  overflow: hidden;
  pointer-events: none;
}

.menu-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #3a425b52, var(--overlay-veil));
  opacity: 0;
  transition: opacity 180ms ease;
}

.menu-overlay[data-view="hidden"]::before {
  opacity: 0;
}

.menu-overlay:not([hidden])::before {
  opacity: 1;
}

.menu-overlay > * {
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.menu-panel[hidden] {
  display: none !important;
}

.menu-panel h2 {
  margin: 0;
  font-size: 1.55rem;
}

.menu-panel p {
  margin: 0.5rem 0 0.85rem;
  font-size: 0.95rem;
}

#start-menu.menu-panel,
#pause-menu.menu-panel,
#settings-menu.menu-panel,
#stats-menu.menu-panel,
#level-complete-menu.menu-panel,
#shop-menu.menu-panel {
  position: absolute;
  inset: 0;
  max-height: none;
  overflow: auto;
  border: 1px solid var(--menu-card-stroke);
  background: var(--menu-card);
  backdrop-filter: blur(2px);
  color: #fff8e4;
  box-shadow: inset 0 1px #ffffff24;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.72rem;
  text-align: center;
  padding: 2rem 1.45rem;
  animation: panelIn 220ms ease-out both;
}

#start-menu.menu-panel {
  overflow: visible;
  transform: translateY(-34px);
}

#pause-menu.menu-panel,
#settings-menu.menu-panel {
  justify-content: center;
}

.start-menu-chicken {
  width: clamp(110px, 18vw, 220px);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  animation: floatIdle 2600ms ease-in-out infinite;
}

#start-menu h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(3rem, 5vw + 0.9rem, 4.7rem);
}

#start-menu .menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

#start-menu .menu-actions button {
  min-width: min(300px, 86vw);
  opacity: 0;
  animation: actionIn 220ms ease-out forwards;
}

#start-menu .menu-actions button:nth-child(1) {
  animation-delay: 70ms;
}

#start-menu .menu-actions button:nth-child(2) {
  animation-delay: 120ms;
}

#start-menu .menu-actions button:nth-child(3) {
  animation-delay: 170ms;
}

#start-menu #menu-play {
  font-size: clamp(1.45rem, 1.4vw + 0.92rem, 1.9rem);
  padding-top: 0.62rem;
  padding-bottom: 0.62rem;
}

#start-menu #menu-stats,
#start-menu #menu-settings {
  font-size: clamp(1.22rem, 1.1vw + 0.84rem, 1.58rem);
}

#stats-menu.menu-panel {
  align-items: stretch;
  justify-content: flex-start;
  padding-top: 2.5rem;
}

#pause-menu h2,
#settings-menu h2 {
  font-size: clamp(2.8rem, 5.2vw, 4.8rem);
}

#settings-menu {
  color: #fffef4;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding-top: 2.4rem;
}

#level-complete-menu.menu-panel,
#shop-menu.menu-panel {
  justify-content: center;
}

#shop-menu.menu-panel {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

#stats-menu h2,
#level-complete-menu h2,
#shop-menu h2 {
  font-size: clamp(2.5rem, 5vw, 4.3rem);
}

#level-complete-menu h2 {
  font-size: clamp(3rem, 6vw, 5.16rem);
}

#level-complete-title {
  color: #ffe39f;
}

#stats-menu p,
#level-complete-menu p,
#shop-menu p {
  color: #fffef4;
  font-size: clamp(1.05rem, 1.4vw, 1.4rem);
}

#shop-coins,
#shop-feedback {
  width: min(900px, 96%);
  margin: 0.25rem auto 0.55rem;
  text-align: center;
}

#shop-feedback {
  min-height: 1.6rem;
  font-size: clamp(0.95rem, 1.1vw, 1.1rem);
  color: #fff6ce;
}

.shop-list {
  width: min(900px, 96%);
  margin: 0 auto 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 260px));
  justify-content: center;
  gap: 0.7rem;
}

.shop-item {
  border: 1px solid #ffffff3a;
  background: #ffffff14;
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.2rem;
  min-height: 332px;
}

.shop-modifier-icon {
  width: clamp(58px, 6.8vw, 78px);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin: 0.1rem 0 0.15rem;
}

#shop-menu .shop-item h3 {
  margin: 0 0 0.35rem;
  color: #fffef4;
  font-size: clamp(1.1rem, 1.5vw, 1.42rem);
  line-height: 1.2;
  min-height: 2.5em;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#shop-menu .shop-item p {
  margin: 0 0 0.4rem;
  color: #fffef4;
  font-size: clamp(0.83rem, 1vw, 0.95rem);
  line-height: 1.35;
}

#shop-menu .shop-item .shop-item-copy {
  min-height: 3.3em;
}

#shop-menu .shop-item .shop-item-status {
  min-height: 1.5em;
  margin-bottom: 0.2rem;
}

.shop-buy {
  min-width: 92px;
  font-size: 0.96rem;
  padding: 0.42rem 0.62rem;
  margin-top: auto;
}

#level-complete-summary {
  font-size: clamp(1.26rem, 1.68vw, 1.68rem);
}

#stats-summary {
  width: min(900px, 96%);
  margin: 0.35rem auto 0.55rem;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.58rem;
  justify-content: center;
}

.menu-actions button {
  appearance: none;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: clamp(1.28rem, 1.6vw + 0.8rem, 1.72rem);
  font-weight: 800;
  line-height: 1.18;
  letter-spacing: 0.02em;
  padding: 0.54rem 0.92rem;
  min-width: min(248px, 84vw);
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

#level-complete-menu .menu-actions button {
  font-size: clamp(1.22rem, 1.4vw + 0.72rem, 1.62rem);
}

.btn-primary {
  background: var(--btn-primary-bg);
  border-color: #ffd987;
  color: var(--btn-primary-ink);
}

.btn-primary:hover {
  background: #ffe29a;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  border-color: #d6dde3;
  color: var(--btn-secondary-ink);
}

.btn-secondary:hover {
  background: #e8eef3;
  transform: translateY(-1px);
}

.btn-ghost {
  background: #ffffff0f;
  border-color: #ffffff52;
  color: var(--btn-ghost-ink);
}

.btn-ghost:hover {
  background: #ffffff1e;
  border-color: #ffffff72;
  transform: translateY(-1px);
}

.menu-actions button:focus-visible,
.shop-buy:focus-visible,
.page-help-btn:focus-visible {
  outline: 2px solid #fff5be;
  outline-offset: 2px;
}

.leaderboard-list {
  margin: 0 auto 0.8rem;
  width: min(900px, 96%);
  border: none;
  border-radius: 0;
  background: transparent;
  max-height: min(54vh, 520px);
  overflow: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  color: #fffef4;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 0.42rem 0.48rem;
  border-bottom: 1px solid #ffffffe0;
  text-align: left;
  white-space: nowrap;
}

.leaderboard-table th {
  position: sticky;
  top: 0;
  background: #2e4d5ec7;
  z-index: 1;
}

.leaderboard-table tbody tr:nth-child(even) {
  background: #ffffff14;
}

strong {
  color: var(--accent);
}

.audio-tools {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  pointer-events: auto;
}

#music-volume {
  width: clamp(160px, 24vw, 280px);
  accent-color: #f2a51a;
}

#music-volume-value {
  min-width: 1.7rem;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fffef4;
}

#settings-menu .menu-actions {
  margin: 0.2rem 0 0.7rem;
}

#settings-menu .menu-actions button {
  color: var(--btn-secondary-ink);
}

#settings-menu .menu-actions button:hover {
  color: #1f2c33;
}

.settings-audio {
  width: min(440px, 96%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

#settings-menu .audio-tools {
  width: min(520px, 100%);
  margin: 0 auto;
  justify-content: center;
  flex-wrap: nowrap;
}

#settings-menu .audio-tools label {
  color: #fffef4;
  font-size: clamp(0.9rem, 1.3vw, 1.1rem);
  font-weight: 700;
  white-space: nowrap;
}

#settings-menu #music-volume-value {
  color: #fffef4;
}

.help-dialog {
  border: 1px solid #e5d9be;
  border-radius: 14px;
  padding: 0;
  width: min(480px, 92vw);
  background: #fffaf0;
  color: #2b343e;
  box-shadow: 0 16px 36px #00000045;
}

.help-dialog::backdrop {
  background: #10131a80;
  backdrop-filter: blur(1px);
}

.help-dialog-body {
  padding: 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.help-dialog h2 {
  margin: 0;
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
}

.help-dialog p {
  margin: 0;
  line-height: 1.5;
  font-size: 0.88rem;
}

.dev-tools {
  margin-top: 0.8rem;
}

.dev-toggle {
  appearance: none;
  border: 2px solid #f0d8b1;
  background: #fff3dc;
  color: #3a2b1a;
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.dev-toggle:hover {
  background: #ffe8be;
}

.dev-panel {
  margin-top: 0.6rem;
  border: 2px solid #f0e1c7;
  background: #fffcf2;
  border-radius: 12px;
  padding: 0.7rem;
}

.dev-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 0.55rem 0.65rem;
}

.dev-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #3e4d56;
}

.dev-grid input {
  width: 100%;
  border: 1px solid #d8c9af;
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font: inherit;
  font-weight: 500;
  color: #27343d;
  background: #ffffff;
}

.dev-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.dev-actions button {
  appearance: none;
  border: 1px solid #d3bf9e;
  border-radius: 9px;
  background: #fff4dc;
  color: #3f2f1f;
  font-weight: 700;
  padding: 0.42rem 0.65rem;
  cursor: pointer;
}

.dev-actions button:hover {
  background: #ffe8be;
}

#dev-status {
  font-size: 0.84rem;
  font-weight: 700;
  color: #3f5531;
}

@media (max-width: 700px) {
  body {
    padding: 0.6rem;
  }

  .game-shell {
    width: min(980px, 96vw);
    padding: 0.82rem;
  }

  .subtitle {
    margin: 0.45rem 0 0.66rem;
  }

  .audio-tools {
    gap: 0.35rem;
    padding: 0.3rem 0.35rem;
  }

  #music-volume {
    width: clamp(100px, 32vw, 150px);
  }

  .menu-panel {
    padding: 1rem 0.9rem;
  }

  .shop-list {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .shop-item {
    width: min(360px, 100%);
    min-height: 0;
  }

  .menu-actions button {
    min-width: min(260px, 90vw);
    min-height: 44px;
    padding-top: 0.52rem;
    padding-bottom: 0.52rem;
  }

  .dev-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .dev-actions {
    flex-wrap: wrap;
  }
}

@keyframes shellIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes actionIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes floatIdle {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}
