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

:root {
  --bg-dark: #5f8f62;
  --panel-bg: rgba(255, 252, 235, 0.94);
  --accent: #efbc38;
  --accent-dark: #c98f21;
  --text: #334732;
  --text-light: #6c7d54;
  --success: #6fab54;
  --danger: #dc6f5f;
  --battery-low: #efbc38;
  --battery-ok: #68a85e;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-dark);
  touch-action: manipulation;
  user-select: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: linear-gradient(180deg, #a9d5ed 0%, #dceff2 55%, #8fbd6b 55%, #5f964f 100%);
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  pointer-events: none;
  z-index: 25;
}

.hud-left, .hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
}

.hud-right {
  align-items: flex-end;
  flex-direction: row;
  gap: 10px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-bg);
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
  color: var(--text);
  font-size: 15px;
  box-shadow: 0 2px 10px rgba(75, 98, 42, 0.14);
  border: 1px solid rgba(239, 188, 56, 0.2);
}

.hud-icon {
  font-size: 16px;
}

.shagan-icon {
  color: #d49721;
}

.hud-label {
  color: var(--text-light);
  font-size: 12px;
  font-weight: 500;
}

.hud-label-small {
  color: var(--text-light);
  font-size: 11px;
  font-weight: 500;
}

.belna-display {
  margin-top: 2px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.belna-display.empty {
  opacity: 0.72;
}

.belna-display.belna-bump {
  animation: belnaBump 0.32s ease;
}

@keyframes belnaBump {
  0% { transform: scale(1); }
  45% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.battery-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  padding: 6px 12px;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(75, 98, 42, 0.14);
  border: 1px solid rgba(239, 188, 56, 0.2);
}

.battery-bar-wrap {
  width: 80px;
  height: 14px;
  background: #e8e1bc;
  border-radius: 7px;
  overflow: hidden;
  border: 2px solid #d7ca8f;
}

.battery-bar {
  height: 100%;
  width: 100%;
  background: var(--battery-ok);
  border-radius: 5px;
  transition: width 0.3s ease, background 0.3s ease;
}

.battery-bar.low {
  background: var(--battery-low);
  animation: batteryPulse 1s ease-in-out infinite;
}

.battery-bar.critical {
  background: var(--danger);
  animation: batteryPulse 0.5s ease-in-out infinite;
}

.battery-bar.battery-bump {
  filter: brightness(1.15);
  transition: width 0.45s ease, filter 0.2s ease;
}

@keyframes batteryPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#battery-percent {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 36px;
}

.hud-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--panel-bg);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(75, 98, 42, 0.14);
  transition: transform 0.15s ease, background 0.15s ease;
}

.hud-btn:hover {
  transform: scale(1.08);
  background: #fff;
}

.hud-btn:active {
  transform: scale(0.95);
}

/* Low battery warning */
#low-battery-warning {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(224, 122, 122, 0.9);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 14px;
  z-index: 15;
  animation: warningBounce 0.8s ease-in-out infinite;
  pointer-events: none;
}

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

/* Shop overlay */
#shop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(51, 71, 50, 0.44);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: auto;
}

.shop-panel {
  background: var(--panel-bg);
  border-radius: 18px;
  padding: 24px 28px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 12px 36px rgba(62, 88, 46, 0.24);
  border: 1px solid rgba(239, 188, 56, 0.26);
}

.shop-panel h2 {
  color: var(--text);
  margin-bottom: 4px;
  font-size: 22px;
}

.shop-balance {
  color: var(--text-light);
  margin-bottom: 16px;
  font-size: 14px;
}

.shop-balance span {
  color: #d49721;
  font-weight: 700;
}

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  align-items: center;
  padding: 12px 14px;
  border: 2px solid #e6dbac;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.shop-item:hover:not(:disabled) {
  border-color: var(--accent);
  background: #fff9d7;
}

.shop-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.shop-item-name {
  grid-column: 2;
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.shop-item-desc {
  grid-column: 2;
  font-size: 12px;
  color: var(--text-light);
}

.shop-item-cost {
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: center;
  font-weight: 700;
  color: #d49721;
  font-size: 14px;
}

.shop-hint {
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
}

.item-icon {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  vertical-align: middle;
}

.shop-item .item-icon {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: center;
  justify-self: center;
}

.belna-icon::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 13px;
  width: 23px;
  height: 7px;
  border-radius: 8px;
  background: linear-gradient(90deg, #b47a3c 0 18%, #d9ad6f 18% 82%, #b47a3c 82%);
  transform: rotate(-18deg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.battery-icon {
  border-radius: 6px;
  background: #6fab54;
  box-shadow: inset 0 0 0 3px #e6f4d6;
}

.battery-icon::after {
  content: '';
  position: absolute;
  right: -3px;
  top: 10px;
  width: 4px;
  height: 8px;
  border-radius: 2px;
  background: #6fab54;
}

.shagan-magnet-icon,
.shagan-icon-visual {
  background: radial-gradient(circle at 36% 34%, #ffe28a 0 25%, #efbc38 26% 64%, #d49721 65%);
  box-shadow: 0 0 0 3px rgba(239, 188, 56, 0.18);
}

.shagan-magnet-icon::before,
.shagan-icon-visual::before {
  content: '✦';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8a6812;
  font-size: 13px;
  font-weight: 800;
}

.speed-icon::before,
.speed-icon::after {
  content: '';
  position: absolute;
  left: 5px;
  width: 18px;
  height: 5px;
  border-radius: 8px;
  background: #6fab54;
}

.speed-icon::before {
  top: 8px;
  box-shadow: -4px 7px 0 #efbc38;
}

.speed-icon::after {
  top: 18px;
  width: 12px;
  background: #d49721;
}

.khoo-icon {
  border-radius: 5px;
  background: linear-gradient(180deg, #4a6a5a, #2f4b3f);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.12);
}

.khoo-icon::before {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  top: 6px;
  height: 4px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
}

/* Overlay screens */
.overlay-screen {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(169, 213, 237, 0.86), rgba(255, 248, 200, 0.8) 54%, rgba(109, 161, 76, 0.82));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 30;
  color: var(--text);
  text-align: center;
  padding: 20px;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.28s ease;
}

.overlay-screen::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28%;
  background:
    linear-gradient(transparent, rgba(89, 145, 65, 0.34)),
    repeating-linear-gradient(90deg, transparent 0 22px, rgba(239, 188, 56, 0.22) 22px 25px, transparent 25px 44px);
  pointer-events: none;
}

.overlay-screen > * {
  position: relative;
  z-index: 1;
}

.overlay-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.intro-screen {
  background:
    linear-gradient(180deg, rgba(169, 213, 237, 0.98), rgba(255, 247, 191, 0.94) 58%, rgba(116, 174, 83, 0.95));
}

.birthday-message {
  max-width: 720px;
  font-size: clamp(24px, 5vw, 42px);
  line-height: 1.22;
  font-weight: 750;
  color: #334732;
  text-shadow: 0 2px 16px rgba(255, 255, 255, 0.55);
  animation: introFadeIn 0.9s ease both;
  margin-bottom: 22px;
}

.intro-btn {
  min-width: 180px;
}

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

.overlay-top {
  z-index: 50;
}

.game-over-reason {
  font-size: 14px;
  opacity: 0.85;
  margin-bottom: 12px;
  max-width: 320px;
}

.overlay-screen h1 {
  font-size: clamp(28px, 6vw, 42px);
  margin-bottom: 8px;
  text-shadow: 0 2px 14px rgba(255, 255, 255, 0.6);
}

.overlay-screen h2 {
  font-size: clamp(24px, 5vw, 32px);
  margin-bottom: 16px;
}

.subtitle {
  font-size: 16px;
  color: var(--text-light);
  margin-bottom: 24px;
}

.menu-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 520px;
  margin-bottom: 18px;
}

.menu-items > span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 5px 10px;
  border-radius: 20px;
  background: rgba(255, 252, 235, 0.78);
  border: 1px solid rgba(239, 188, 56, 0.24);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.instructions {
  background: rgba(255, 252, 235, 0.76);
  border: 1px solid rgba(239, 188, 56, 0.25);
  border-radius: 16px;
  padding: 16px 24px;
  margin-bottom: 28px;
  line-height: 1.8;
  font-size: 14px;
}

.instructions kbd {
  background: rgba(239, 188, 56, 0.22);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: inherit;
}

.primary-btn {
  padding: 14px 36px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: 30px;
  background: var(--accent);
  color: #2f432e;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(91, 111, 38, 0.24);
  transition: transform 0.15s ease, background 0.15s ease;
}

.primary-btn:hover {
  background: var(--accent-dark);
  transform: scale(1.04);
}

.primary-btn:active {
  transform: scale(0.97);
}

.game-over-stats {
  background: rgba(255, 252, 235, 0.76);
  border: 1px solid rgba(239, 188, 56, 0.25);
  border-radius: 16px;
  padding: 16px 32px;
  margin-bottom: 24px;
  line-height: 2;
  font-size: 16px;
}

.game-over-stats span {
  font-weight: 700;
  color: #d49721;
}

.revive-panel {
  width: min(360px, 90vw);
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 252, 235, 0.78);
  border: 1px solid rgba(239, 188, 56, 0.25);
}

.revive-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.revive-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#revive-name {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #d7ca8f;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font: inherit;
  outline: none;
}

#revive-name:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239, 188, 56, 0.18);
}

#revive-name:disabled {
  opacity: 0.65;
}

.secondary-btn {
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: #6fab54;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.secondary-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.revive-message {
  min-height: 18px;
  margin-top: 7px;
  color: var(--text-light);
  font-size: 12px;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(255, 248, 200, 0.22);
}

.countdown-word {
  min-width: 150px;
  padding: 18px 30px 20px;
  border-radius: 24px;
  background: rgba(255, 252, 235, 0.92);
  border: 2px solid rgba(239, 188, 56, 0.42);
  box-shadow: 0 14px 36px rgba(62, 88, 46, 0.22);
  color: var(--text);
  font-size: clamp(48px, 12vw, 96px);
  line-height: 1;
  font-weight: 800;
  text-align: center;
}

.countdown-word.tick {
  animation: countdownTick 0.35s ease;
}

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

/* Jump button */
.jump-btn {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 16px 48px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 40px;
  background: rgba(255, 252, 245, 0.92);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 10;
  transition: transform 0.1s ease, background 0.1s ease;
  pointer-events: auto;
}

.jump-btn:active {
  transform: translateX(-50%) scale(0.94);
  background: #fff;
}

@media (min-width: 768px) {
  .jump-btn {
    display: none;
  }
}
