
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #0d1a0d;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  overflow: hidden;
  color: #c8e0c8;
  overscroll-behavior: none;
  touch-action: none;
}
#game-wrapper {
  position: relative;
  border: 1px solid rgba(26, 60, 26, 0.2);
  border-radius: 6px;
  box-shadow: 0 0 60px rgba(0,0,0,0.8), 0 0 120px rgba(26, 60, 26, 0.08);
  width: min(100vw, calc(100vh * 1.5));
  max-width: none;
  height: auto;
  aspect-ratio: 3 / 2;
  background: #4a8c32;
  overflow: hidden;
  isolation: isolate;
}
canvas {
  display: block;
  background: #5da83a;
  cursor: crosshair;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#ui-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: auto;
}
/* ===== TOP HUD BAR ===== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 38px;
  background: rgba(8, 16, 8, 0.82);
  border-bottom: 2px solid #1a2e1a;
  display: flex;
  align-items: center;
  color: #a8c8a8;
  font-size: 11px;
  pointer-events: none;
}

#hud-bar {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  gap: 0;
}
.hud-cell {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 14px;
  height: 100%;
  border-right: 1px solid rgba(26, 46, 26, 0.5);
}
.hud-cell:last-child { border-right: none; }
.hud-cell-icon { font-size: 15px; line-height: 1; }
.hud-cell-body {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.hud-cell-label {
  font-size: 7px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #4a6a4a;
  font-weight: 600;
}
.hud-cell-value {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #a8c8a8;
}
.hud-cell-value.gold     { color: #d4a353; }
.hud-cell-value.eggs     { color: #f5cba7; }
.hud-cell-value.quota    { color: #7ab8d4; }
.hud-cell-value.chickens { color: #e88d8d; }
.hud-cell-value.fried    { color: #e8a87c; }
#hud-bar .hud-fill { flex: 1; border: none; }

/* ---- Minimap panel (bottom-left corner) ---- */
#minimap-panel {
  position: absolute;
  bottom: 10px;
  left: 10px;
  width: 216px;
  height: 110px;
  background: rgba(8, 16, 8, 0.88);
  border: 2px solid #1a2e1a;
  border-bottom: none;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 1;
  border-radius: 6px 6px 0 0;
}
#minimap-panel canvas {
  border: 1px solid #1a2e1a;
  width: 185px;
  height: 85px;
  image-rendering: pixelated;
}
#minimap-panel #zoom-controls {
  position: absolute;
  top: 3px;
  right: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
#minimap-panel .zoom-btn {
  background: rgba(10, 20, 10, 0.85);
  border: 1px solid #2a4a2a;
  color: #5a7a5a;
  font-size: 9px;
  width: 18px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  font-weight: 700;
  font-family: monospace;
}
#minimap-panel .zoom-btn:hover { background: #1a2e1a; color: #a8c8a8; }
#minimap-panel .zoom-preset { font-size: 8px; }
#minimap-panel #zoom-level {
  font-size: 6px;
  color: #3a5a3a;
  text-align: center;
  line-height: 1;
}

/* ---- Bottom GUI Panel (extends right from minimap) ---- */
#bottom-gui-panel {
  position: absolute;
  bottom: 10px;
  left: 236px;
  right: 10px;
  height: 210px;
  background: rgba(12, 32, 12, 0.88);
  border: 2px solid #1a2e1a;
  border-bottom: none;
  border-left: none;
  border-radius: 0 6px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  z-index: 1;
  overflow: hidden;
}
#bottom-gui-panel .bpanel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(26, 46, 26, 0.6);
  flex-shrink: 0;
}
#bottom-gui-panel .bpanel-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}
#bottom-gui-panel .bpanel-stat .stat-icon {
  font-size: 18px;
  line-height: 1;
}
#bottom-gui-panel .bpanel-stat .stat-label {
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #4a6a4a;
  font-weight: 600;
}
#bottom-gui-panel .bpanel-stat .stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #d4a353;
  letter-spacing: 0.3px;
}
#bottom-gui-panel .bpanel-stat .stat-value.eggs {
  color: #f5cba7;
}
#bottom-gui-panel .bpanel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  overflow-y: auto;
}

/* ---- Build bar (inside bottom panel) ---- */
#build-hud {
  display: none;
  position: absolute;
  bottom: 10px;
  left: 236px;
  right: 10px;
  height: 210px;
  background: rgba(12, 32, 12, 0.88);
  border: 2px solid #1a2e1a;
  border-bottom: none;
  border-left: none;
  border-radius: 0 6px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  align-items: flex-start;
  align-content: flex-start;
  gap: 3px;
  padding: 8px 12px;
  pointer-events: auto;
  font-size: 10px;
  overflow-x: auto;
  z-index: 2;
  flex-wrap: wrap;
}
#build-hud .build-label {
  font-size: 8px;
  font-weight: 700;
  color: #4a6a4a;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding-right: 8px;
  border-right: 1px solid #122412;
  margin-right: 4px;
  flex-shrink: 0;
}
.build-item {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 7px;
  border: 1px solid #122412;
  background: rgba(15, 26, 15, 0.6);
  cursor: pointer;
  color: #5a7a5a;
  font-weight: 600;
  font-size: 9px;
  white-space: nowrap;
  flex-shrink: 0;
}
.build-item:hover {
  background: #1a2e1a;
  border-color: #2a4a2a;
  color: #a8c8a8;
}
.build-item.active {
  border-color: #8bba8a;
  background: rgba(26, 36, 24, 0.8);
  color: #8bba8a;
}
.build-item .bi-icon { font-size: 11px; }
.build-item .bi-price {
  font-size: 8px;
  color: #4a6a4a;
  background: #050d05;
  padding: 1px 3px;
  margin-left: 2px;
}
.build-item .bi-cnt {
  font-size: 8px;
  color: #3a5a3a;
  min-width: 10px;
  margin-left: 2px;
}
.build-item.can-afford .bi-cnt { color: #8bba8a; }
.build-item.cant-afford { opacity: 0.35; }
#build-hud .bi-hint {
  color: #1a3a1a;
  font-size: 8px;
  margin-left: auto;
  padding-left: 6px;
  border-left: 1px solid #122412;
  flex-shrink: 0;
}

/* ---- Toast notifications ---- */
#toast-container {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  width: min(420px, calc(100% - 24px));
  pointer-events: none;
  z-index: 20;
}
.toast {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid #315131;
  border-left-width: 4px;
  border-radius: 7px;
  background: rgba(8, 16, 8, 0.94);
  color: #d8e8d8;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  animation: toastIn 0.25s ease, toastOut 0.3s ease 3.5s forwards;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
.toast-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  font-size: 17px;
}
.toast-copy { min-width: 0; }
.toast-title { color: #f0f5f0; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .7px; }
.toast-detail { color: #a9bea9; margin-top: 1px; }
.toast.sale { border-color: #2ecc71; }
.toast.theft, .toast.danger { border-color: #ff4757; }
.toast.fryer { border-color: #f39c12; }
.toast.info { border-color: #54a0ff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(-6px); }
}

/* Screen Overlays */
.menu-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(8, 20, 8, 0.82);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid rgba(26, 60, 26, 0.15);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #c8e0c8;
  pointer-events: auto;
  box-shadow: inset 0 0 120px rgba(0,0,0,0.5);
  z-index: 8;
}
.menu-screen h1 {
  font-family: 'Playfair Display', serif;
  font-size: 44px;
  font-weight: 700;
  color: #d4a353;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 12px rgba(212, 163, 83, 0.25);
  margin-bottom: 4px;
}
.menu-screen .subtitle {
  font-size: 15px;
  color: #8ab88a;
  margin-bottom: 28px;
  font-weight: 400;
  letter-spacing: 0.3px;
  font-style: italic;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.menu-btn {
  padding: 11px 30px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  background: linear-gradient(135deg, #1a3a1a, #2a5a2a);
  color: #c8e0c8;
  cursor: pointer;
  margin: 5px;
  min-width: 240px;
  letter-spacing: 0.5px;
  transition: all 0.25s ease;
  text-align: center;
  box-shadow: 0 3px 12px rgba(26, 60, 26, 0.3);
}
.menu-btn:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #2a5a2a, #3a7a3a);
  box-shadow: 0 5px 18px rgba(26, 60, 26, 0.4);
}
.menu-btn:active {
  transform: translateY(0px);
}
.menu-btn.sec-btn {
  background: rgba(26, 60, 26, 0.08);
  color: #8ab88a;
  border: 1px solid rgba(26, 60, 26, 0.2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.menu-btn.sec-btn:hover {
  background: rgba(26, 60, 26, 0.15);
  border-color: rgba(26, 60, 26, 0.4);
  color: #c8e0c8;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

/* Customization Panel */
#custom-panel {
  display: flex;
  gap: 30px;
  align-items: center;
  background: rgba(13, 26, 13, 0.5);
  backdrop-filter: blur(8px);
  padding: 24px;
  border-radius: 8px;
  border: 1px solid rgba(26, 60, 26, 0.2);
  margin-bottom: 24px;
  max-width: 800px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.custom-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.option-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.option-group label {
  font-size: 10px;
  color: #d4a353;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 1px;
}
.option-group select {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid rgba(26, 60, 26, 0.2);
  background: rgba(8, 20, 8, 0.85);
  color: #c8e0c8;
  cursor: pointer;
  outline: none;
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.option-group select:focus {
  border-color: #d4a353;
  box-shadow: 0 0 8px rgba(212, 163, 83, 0.25);
}

/* Unified Farm Stand & Fryer Modal */
#farm-stand-modal {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(8, 20, 8, 0.98);
  border: 1px solid rgba(212, 163, 83, 0.3);
  border-radius: 8px;
  padding: 24px;
  width: 780px;
  color: #c8e0c8;
  box-shadow: 0 0 50px rgba(0,0,0,0.95);
  pointer-events: auto;
  z-index: 10;
}
#farm-stand-modal h2 {
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  font-weight: 600;
  color: #d4a353;
  margin-bottom: 12px;
  text-align: center;
}
.farm-stand-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(212, 163, 83, 0.15);
  padding-bottom: 10px;
}
.farm-stand-panels {
  display: flex;
  gap: 20px;
}
.farm-stand-panel {
  flex: 1;
  background: rgba(13, 26, 13, 0.5);
  border: 1px solid rgba(26, 60, 26, 0.15);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.farm-stand-panel h3 {
  font-family: 'Playfair Display', serif;
  font-size: 11px;
  margin-bottom: 14px;
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(26, 60, 26, 0.15);
}
.farm-stand-panel.left h3 { color: #cc8a5a; }
.farm-stand-panel.right h3 { color: #7a9a6a; }

.sauce-item, .shop-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(26, 60, 26, 0.1);
}
.sauce-item:last-child, .shop-item:last-child {
  border-bottom: none;
}
.sauce-item-desc, .shop-item-desc {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.sauce-item-name, .shop-item-name { font-weight: 500; font-size: 13px; }
.sauce-item-sub, .shop-item-sub { font-size: 11px; color: #5a7a5a; }

.sauce-select-btn, .shop-buy-btn {
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.sauce-select-btn { background: #4a6a3a; color: #c8e0c8; }
.shop-buy-btn { background: #2a5a2a; color: #c8e0c8; }
.sauce-select-btn:disabled, .shop-buy-btn:disabled { background: #1a2a1a; color: #3a5a3a; opacity: 0.5; cursor: default; }

.fryer-cooking-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  text-align: center;
}
.fryer-progress-container {
  width: 100%;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  height: 12px;
  overflow: hidden;
  margin-top: 8px;
}
.fryer-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4a7a3a, #2a5a2a);
  transition: width 0.1s linear;
}

#quota-popup {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(8, 20, 8, 0.97);
  border: 1px solid #d4a353;
  border-radius: 10px;
  padding: 30px 40px;
  text-align: center;
  color: #c8e0c8;
  box-shadow: 0 0 60px rgba(0,0,0,0.9);
  z-index: 15;
  pointer-events: auto;
}
#quota-popup h2 { color: #d4a353; margin-bottom: 12px; font-size: 26px; font-family: 'Playfair Display', serif; font-weight: 600; }
#quota-popup p { margin: 6px 0; font-size: 14px; color: #8ab88a; }
#quota-popup button {
  margin-top: 16px;
  padding: 8px 24px;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  background: #1a3a1a;
  color: #c8e0c8;
  cursor: pointer;
  font-weight: 600;
}
#quota-popup button:hover { background: #2a5a2a; }

#game-over-screen {
  background: rgba(8, 20, 8, 0.96);
}
#game-over-screen h2 {
  font-family: 'Playfair Display', serif;
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #d4a353;
}
#game-over-screen .final-score { font-size: 26px; color: #d4a353; margin: 10px 0; font-weight: 700; }
#game-over-screen .stats { font-size: 14px; color: #8ab88a; line-height: 1.7; text-align: center; }
#high-scores {
  margin: 16px 0;
  font-size: 12px;
  color: #5a7a5a;
  max-width: 500px;
}
#high-scores .score-entry { margin: 4px 0; font-family: 'Inter', monospace; }
#high-scores .score-entry .rank { color: #d4a353; font-weight: 600; }
.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
/* Mobile-first game shell and touch controls */
#mobile-controls {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 7;
  user-select: none;
  -webkit-user-select: none;
}
#touch-joystick {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 2px solid rgba(200, 224, 200, .34);
  background: rgba(8, 20, 8, .48);
  box-shadow: inset 0 0 28px rgba(0,0,0,.38);
  pointer-events: auto;
  touch-action: none;
}
#joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(200, 224, 200, .82);
  border: 2px solid rgba(255,255,255,.45);
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
  transform: translate(0, 0);
}
.touch-action-btn {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 92px; height: 92px;
  border-radius: 50%;
  border: 2px solid rgba(212, 163, 83, .7);
  background: rgba(18, 48, 18, .88);
  color: #f3e5c2;
  font: 800 12px/1.1 'Inter', sans-serif;
  letter-spacing: .7px;
  text-transform: uppercase;
  pointer-events: auto;
  touch-action: manipulation;
  box-shadow: 0 5px 20px rgba(0,0,0,.45);
}
.touch-action-btn:active { transform: scale(.94); background: #2a5a2a; }
.touch-action-btn.inactive {
  opacity: .28;
  border-color: rgba(200,224,200,.25);
  background: rgba(8,20,8,.5);
}
#touch-build-btn, #touch-pause-btn {
  position: absolute;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(200,224,200,.35);
  background: rgba(8,20,8,.78);
  color: #c8e0c8;
  font: 700 9px 'Inter', sans-serif;
  pointer-events: auto;
  touch-action: manipulation;
}
#touch-build-btn { right: max(112px, calc(env(safe-area-inset-right) + 112px)); bottom: max(25px, env(safe-area-inset-bottom)); }
#touch-pause-btn { right: max(12px, env(safe-area-inset-right)); top: max(48px, calc(env(safe-area-inset-top) + 48px)); }
#build-done-btn {
  display: none;
  position: sticky;
  right: 0;
  flex: 0 0 auto;
  min-width: 72px;
  min-height: 42px;
  border: 1px solid #8bba8a;
  border-radius: 5px;
  background: #244b24;
  color: #d8ecd8;
  font-weight: 800;
}

html.mobile-device {
  body { align-items: center; min-height: 100dvh; }
  body.building { --build-dock-height: min(44dvh, 330px); }
  #game-wrapper {
    width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.building #game-wrapper {
    padding-bottom: var(--build-dock-height);
    background: #081408;
  }
  #hud { height: 44px; overflow: hidden; }
  #hud-bar { overflow-x: auto; scrollbar-width: none; padding-right: 58px; }
  #hud-bar::-webkit-scrollbar { display: none; }
  .hud-cell { padding: 0 8px; flex: 0 0 auto; }
  .hud-cell-icon { display: none; }
  .hud-cell-label { font-size: 6px; letter-spacing: 1px; }
  .hud-cell-value { font-size: 13px; }
  #minimap-panel, #bottom-gui-panel { display: none !important; }
  #build-hud {
    left: 10px; right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    height: auto;
    max-height: min(58dvh, 470px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    align-items: stretch;
    overflow: hidden auto;
    border: 2px solid #294829;
    border-radius: 10px;
    padding: 10px;
    z-index: 9;
  }
  #build-hud[style*="display: flex"] { display: grid !important; }
  body.building #build-hud {
    height: calc(var(--build-dock-height) - 20px);
    max-height: none;
  }
  #build-hud::before {
    content: 'BUILD';
    grid-column: 1 / -1;
    color: #8bba8a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2px;
    padding: 1px 2px 3px;
  }
  #build-hud .build-label, #build-hud .bi-hint { display: none; }
  #build-hud .build-item {
    min-width: 0;
    min-height: 70px;
    padding: 8px 5px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    border-radius: 7px;
    font-size: 11px;
    text-align: center;
    white-space: normal;
  }
  #build-hud .build-item .bi-icon { font-size: 19px; }
  #build-hud .build-item .bi-price { margin: 0; font-size: 9px; }
  #build-hud .build-item .bi-cnt { display: none; }
  #build-done-btn {
    display: block;
    position: static;
    grid-column: 1 / -1;
    width: 100%;
    min-height: 46px;
    border-radius: 7px;
  }
  body.building #touch-joystick,
  body.building #touch-action-btn,
  body.building #touch-build-btn { display: none; }
  .menu-screen { padding: 54px 16px 16px; overflow-y: auto; justify-content: flex-start; }
  .menu-screen h1 { font-size: clamp(28px, 8vw, 42px); text-align: center; }
  .menu-screen .subtitle { margin-bottom: 16px; text-align: center; }
  .menu-btn { min-width: min(280px, 88vw); min-height: 46px; }
  #custom-panel { flex-direction: column; gap: 12px; padding: 14px; margin-bottom: 12px; max-width: 94vw; }
  .custom-options { gap: 8px; }
  #farm-stand-modal { width: calc(100% - 20px); max-height: calc(100% - 58px); overflow-y: auto; padding: 14px; }
  #quota-popup { width: calc(100% - 32px); padding: 22px 16px; }
}

html.mobile-device body.touch-active #mobile-controls { display: block; }

html.desktop-device #mobile-controls { display: none !important; }

@media (max-width: 520px) and (orientation: portrait) {
  #touch-joystick { width: 112px; height: 112px; }
  .touch-action-btn { width: 82px; height: 82px; }
  .custom-options { grid-template-columns: 1fr; }
}

@media (orientation: landscape) {
  html.mobile-device #build-hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: min(72dvh, 360px);
  }
  html.mobile-device #build-hud .build-item { min-height: 62px; }
}

/* Keep menus usable with browser bars, safe areas and short landscape screens. */
html.mobile-device .menu-screen{padding-top:max(24px,env(safe-area-inset-top));padding-bottom:max(16px,env(safe-area-inset-bottom));touch-action:pan-y}html.mobile-device #hud{padding-top:env(safe-area-inset-top);height:calc(44px + env(safe-area-inset-top))}html.mobile-device #touch-pause-btn{top:calc(52px + env(safe-area-inset-top))}html.mobile-device #farm-stand-modal,html.mobile-device #build-hud{touch-action:pan-y}

.touch-hint{display:none}html.mobile-device .desktop-hint{display:none}html.mobile-device .touch-hint{display:inline}

/* Compact, unlabeled skin choices with full-size touch targets. */
.skin-swatches { display:flex; align-items:center; gap:2px; grid-column:1 / -1; }
.skin-swatches button { width:36px; height:44px; padding:0; background:transparent; border:0; cursor:pointer; display:grid; place-items:center; }
.skin-swatches button::before { content:""; width:22px; height:22px; border-radius:50%; background:var(--swatch); border:2px solid transparent; }
.skin-swatches button[aria-pressed="true"]::before { outline:2px solid #d4a353; outline-offset:2px; }
.skin-swatches button:focus-visible { outline:2px solid #d4a353; border-radius:5px; }
#previewCanvas { width:120px; height:150px; flex:none; }
#custom-panel, #custom-save-btn { flex-shrink:0; }
@media (orientation:landscape) and (max-height:520px) {
  html.mobile-device #custom-panel { flex-direction:row; padding:10px; gap:18px; }
  html.mobile-device #custom-screen h1 { font-size:26px; margin-bottom:12px; }
  html.mobile-device #custom-screen .custom-options { gap:6px 12px; }
}

/* House advert on failure: replay stays available beside the product. */
#game-over-screen { overflow-y:auto; padding:24px 16px; }
.game-over-layout { display:flex; align-items:center; justify-content:center; gap:28px; width:min(760px,100%); flex-shrink:0; margin:auto; }
.game-over-results { flex:1; min-width:0; text-align:center; }
.product-ad { width:240px; flex:none; padding:20px 18px; border:1px solid #527788; border-radius:12px; background:#234b61; color:#fff5de; text-align:center; }
.product-ad[hidden] { display:none; }
.product-ad-eyebrow { font-size:9px; letter-spacing:2px; }
.product-ad img { display:block; width:100%; height:160px; object-fit:contain; margin:4px auto; }
.product-ad h3 { font-size:24px; letter-spacing:1px; margin:0 0 8px; }
.product-ad p { font-size:12px; line-height:1.5; margin:0 0 14px; color:#e2eaf0; }
.product-ad-footer { font-size:8px; letter-spacing:1.4px; color:#e5c15b; }
@media (max-width:560px) {
  .game-over-layout { flex-direction:column; gap:18px; }
  .game-over-results { width:100%; }
  .product-ad { width:min(300px,100%); }
  .product-ad img { height:130px; }
}
@media (orientation:landscape) and (max-height:520px) {
  .game-over-layout { gap:18px; }
  .product-ad { width:220px; padding:14px; }
  .product-ad img { height:115px; }
  #game-over-screen h2 { font-size:26px; }
  #game-over-screen .final-score { font-size:22px; margin:6px 0; }
  #game-over-screen .stats { font-size:12px; line-height:1.5; }
  #game-over-screen #high-scores { margin:10px 0; }
}
