* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: #6d4c41;
  font-family: 'Press Start 2P', cursive;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

#game-container {
  background-color: #3e2723;
  border: 8px solid #2a1a10;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0px 15px 30px rgba(0, 0, 0, 0.6);
  width: 1200px;
  max-width: 100%;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, #4e342e 0%, #3e2723 100%);
  border-bottom: 4px solid #2a1a10;
  border-radius: 8px;
  padding: 15px 20px;
  margin-bottom: 20px;
}

h1 {
  font-size: 32px;
  color: #ffd700;
  text-shadow: 4px 4px 0 #d35400;
}

.stats {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 20px;
  border-radius: 8px;
  border: 2px solid #5c4033;
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
}

.stats p {
  font-size: 14px;
  margin: 5px 0;
  color: #e67e22;
}

.stats p span {
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

main {
  display: flex;
  gap: 20px;
}

#farm-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.farm-status {
  display: flex;
  justify-content: space-between;
  background: #8b5a2b;
  padding: 10px;
  border: 4px solid #3e2610;
}

.bar-container {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
}

.bar {
  width: 80px;
  height: 15px;
  background: #000;
  border: 2px solid #fff;
  position: relative;
}

.bar-text {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 1px;
  left: 0;
  font-size: 8px;
  color: white;
  text-shadow: 1px 1px 0 #000;
}

.fill {
  height: 100%;
  width: 100%;
}

.food {
  background: #ffaa00;
}

.water {
  background: #00aaff;
}

#gameCanvas {
  background: #87ceeb;
  border: 6px solid #5c4033;
  border-radius: 8px;
  cursor: pointer;
  image-rendering: pixelated;
  width: 100%;
}

#shop {
  width: 320px;
  background: linear-gradient(135deg, #d7ccc8 0%, #a1887f 100%);
  border: 6px solid #5c4033;
  border-radius: 8px;
  box-shadow: inset 5px 0 15px rgba(0, 0, 0, 0.15);
  padding: 20px;
  color: #3e2610;
  display: flex;
  flex-direction: column;
  max-height: 650px;
  overflow: hidden;
}

#shop-scroll {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
}

h2 {
  font-size: 20px;
  text-align: center;
  margin-bottom: 15px;
  color: #4e342e;
  text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.5);
  border-bottom: 2px dashed #8d6e63;
  padding-bottom: 10px;
}

.pixel-btn,
.shop-btn {
  font-family: inherit;
  background: #f4d03f;
  border: 4px solid;
  border-color: #fff #d35400 #d35400 #fff;
  border-radius: 4px;
  box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.15);
  color: #5c4033;
  font-weight: bold;
  padding: 10px;
  cursor: pointer;
  text-transform: uppercase;
  font-size: 12px;
  transition: transform 0.1s, box-shadow 0.1s;
}

.pixel-btn:hover:not(:disabled),
.shop-btn:hover:not(:disabled) {
  background: #f1c40f;
  transform: translateY(-2px);
  box-shadow: 3px 5px 0px rgba(0, 0, 0, 0.2);
}

.shop-btn:disabled:hover {
  transform: none;
  box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.15);
  background: #f4d03f;
}

.pixel-btn:active,
.shop-btn:active {
  border-color: #d35400 #fff #fff #d35400;
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.15);
}

.pixel-btn.small {
  padding: 5px;
  font-size: 8px;
}

#sell-btn {
  background: #ffd700;
  font-weight: bold;
}

.shop-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  margin-bottom: 15px;
  font-size: 8px;
  background: #e0e0e0;
  line-height: 1.5;
  padding: 10px 8px;
}

.shop-btn>span:first-of-type {
  text-align: left;
  flex: 1;
  word-wrap: break-word;
  padding-right: 5px;
}

.shop-btn>span:last-of-type {
  text-align: right;
  flex-shrink: 0;
  font-size: 8px;
}

.shop-btn * {
  pointer-events: none;
}

.shop-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  border-color: #fff #666 #666 #fff;
}

.maxed-btn {
  background: #6d8e63 !important;
  border-color: #8dab83 #3d5e33 #3d5e33 #8dab83 !important;
  color: #f1f8e9 !important;
  opacity: 0.9 !important;
}

.maxed-btn>span:last-of-type {
  color: #ffeb3b !important;
  font-weight: bold;
}

#game-tooltip {
  position: absolute;
  background: #5c3a21;
  border: 4px solid #2b170e;
  border-radius: 4px;
  padding: 10px;
  color: #f4d03f;
  font-size: 8px;
  line-height: 1.5;
  pointer-events: none;
  z-index: 1000;
  max-width: 250px;
  text-shadow: 1px 1px 0px #000;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
  display: none;
}

#shop-scroll,
#ranking-list {
  scrollbar-width: thin;
  scrollbar-color: #f4d03f #4a2e15;
}

#shop-scroll::-webkit-scrollbar,
#ranking-list::-webkit-scrollbar {
  width: 14px;
}

#shop-scroll::-webkit-scrollbar-track,
#ranking-list::-webkit-scrollbar-track {
  background: #4a2e15;
  border: 3px solid #3e2723;
  border-radius: 4px;
}

#shop-scroll::-webkit-scrollbar-thumb,
#ranking-list::-webkit-scrollbar-thumb {
  background: #f4d03f;
  border: 3px solid #d35400;
  border-radius: 4px;
}

#shop-scroll::-webkit-scrollbar-thumb:hover,
#ranking-list::-webkit-scrollbar-thumb:hover {
  background: #f1c40f;
}

/* MOBILE LANDSCAPE TIER */
@media (max-width: 950px) and (orientation: landscape),
(max-height: 600px) and (orientation: landscape) {
  body {
    padding: 0;
    align-items: flex-start;
  }

  #game-container {
    display: grid;
    grid-template-columns: 1fr minmax(200px, 30%);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "farm header"
      "farm shop";
    width: 100vw;
    height: 100vh;
    max-width: none;
    padding: 5px;
    gap: 5px;
    border: none;
    border-radius: 0;
  }

  header {
    grid-area: header;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 5px;
    align-items: center;
    margin-bottom: 0;
    padding: 5px;
    text-align: center;
  }

  h1 {
    font-size: 12px;
    grid-column: 1 / span 2;
    grid-row: 1;
    margin-bottom: 2px;
  }

  header>div {
    display: contents;
  }

  .stats:nth-of-type(1)>p {
    grid-column: 1;
    grid-row: 2;
    background: rgba(0, 0, 0, 0.4);
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #5c4033;
    margin: 0;
    font-size: 10px;
  }

  #ui-chicken-icon {
    width: 24px !important;
    height: 24px !important;
    margin-top: -2px !important;
    margin-bottom: -2px !important;
  }

  .stats:nth-of-type(2)>p {
    grid-column: 1 / span 2;
    grid-row: 3;
    background: rgba(0, 0, 0, 0.4);
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #5c4033;
    margin: 0;
    font-size: 10px;
  }

  #wipe-btn {
    padding: 5px;
    font-size: 8px;
    grid-column: 2;
    grid-row: 2;
    height: 100%;
    margin: 0;
  }

  main {
    display: contents;
  }

  #debug-floating {
    display: none !important;
  }

  #farm-area {
    grid-area: farm;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    gap: 5px;
  }

  canvas {
    flex: 0 1 auto;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    aspect-ratio: 800 / 600;
    align-self: center;
    touch-action: none;
    border: 4px solid #5c4033;
    border-radius: 8px;
  }

  #shop {
    grid-area: shop;
    width: auto;
    max-width: none;
    min-width: 0;
    overflow: hidden;
    padding: 5px;
    max-height: none;
  }

  #shop-scroll {
    overflow-y: auto;
  }

  #shop h2 {
    font-size: 12px;
    margin-bottom: 8px;
    padding-bottom: 5px;
  }

  .shop-btn {
    margin-bottom: 8px;
    padding: 6px 8px;
  }

  #mute-btn,
  #pause-btn,
  #toggle-info-btn {
    width: 18px !important;
    height: 18px !important;
    font-size: 8px !important;
    padding: 2px !important;
    border-width: 2px !important;
  }

  #pause-btn {
    left: 22px !important;
  }

  #steam-btn {
    font-size: 8px !important;
    padding: 6px !important;
    margin-top: 5px !important;
    line-height: 1.2 !important;
  }
}

/* RETIRE BUTTON PULSE */
@keyframes retire-pulse {
  0% {
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.15), 0 0 0px rgba(255, 200, 0, 0);
  }

  50% {
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.15), 0 0 18px 6px rgba(255, 180, 0, 0.7);
  }

  100% {
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.15), 0 0 0px rgba(255, 200, 0, 0);
  }
}

#buy-retire {
  animation: retire-pulse 2s ease-in-out infinite;
}

/* MOBILE PORTRAIT TIER */
@media (max-width: 950px) and (orientation: portrait) {

  #game-container,
  #debug-floating,
  #game-tooltip {
    display: none !important;
  }

  body {
    align-items: center;
    background: #000;
    padding: 20px;
    text-align: center;
  }

  body::before {
    content: "📱🔄\A\A Please rotate your device to landscape mode to play.";
    font-size: 16px;
    white-space: pre-wrap;
    line-height: 1.5;
    color: #ffd700;
    text-shadow: 2px 2px 0px #d35400;
  }
}