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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #2b1509;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #fff6dc;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#dojo-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Top HUD Bar */
#hud-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 10;
}

/* Score Medallion (Top-Left) */
#score-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  filter: drop-shadow(0 3px 6px rgba(16, 5, 1, 0.7));
}

.score-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-melon {
  flex-shrink: 0;
  transform: rotate(-12deg);
}

#score-value {
  font-family: "Trebuchet MS", "Arial Black", Impact, sans-serif;
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 900;
  line-height: 0.95;
  color: #ffd43b;
  -webkit-text-stroke: 2px #3d1804;
  text-shadow: 0 3px 0 #3d1804, 0 5px 12px rgba(0, 0, 0, 0.55);
  transition: transform 0.12s ease-out;
}

#score-value.pop {
  transform: scale(1.22);
}

.best-row {
  padding-left: 4px;
  font-size: clamp(12px, 1.8vw, 15px);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #f7c77c;
  text-shadow: 0 2px 4px rgba(18, 6, 1, 0.9);
}

#title-best-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(34, 15, 6, 0.72);
  border: 2px solid rgba(255, 198, 92, 0.45);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.badge-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #f3c677;
}

#title-best-value {
  font-size: 20px;
  font-weight: 900;
  color: #ffdd4a;
}

/* Lives + Controls (Top-Right) */
#hud-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

#lives-rack {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 14px;
  background: rgba(24, 9, 3, 0.48);
  border: 1.5px solid rgba(255, 200, 120, 0.2);
}

.life-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.life-x svg {
  display: block;
  overflow: visible;
}

.life-x path {
  fill: none;
  stroke: rgba(112, 138, 178, 0.55);
  stroke-width: 5.5;
  stroke-linecap: round;
  filter: drop-shadow(0 2px 2px rgba(10, 4, 1, 0.75));
  transition: stroke 0.18s ease;
}

.life-sm svg {
  width: 22px;
  height: 22px;
}

.life-md svg {
  width: 28px;
  height: 28px;
}

.life-lg svg {
  width: 34px;
  height: 34px;
}

.life-x.lost path {
  stroke: #ff2636;
  filter: drop-shadow(0 0 8px rgba(255, 38, 54, 0.9)) drop-shadow(0 2px 2px #2e0408);
}

.life-x.slam {
  animation: life-slam 0.42s cubic-bezier(0.18, 1.5, 0.34, 1);
}

@keyframes life-slam {
  0% {
    transform: scale(1.9) rotate(-14deg);
  }
  55% {
    transform: scale(0.86) rotate(6deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.hud-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.dojo-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(255, 206, 118, 0.52);
  background: linear-gradient(180deg, #5e341a 0%, #361b0c 100%);
  color: #fff2cc;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45), inset 0 1px 1px rgba(255, 224, 160, 0.25);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.dojo-icon-btn:hover {
  transform: translateY(-1px) scale(1.05);
  border-color: #ffe08a;
}

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

.dojo-icon-btn:focus-visible,
.dojo-btn:focus-visible {
  outline: 3px solid #ffe45e;
  outline-offset: 2px;
}

/* Bottom-left controls hint (kept well clear of bottom-right host share bar) */
#controls-hint {
  position: absolute;
  left: 16px;
  bottom: 16px;
  max-width: calc(100vw - 400px);
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(24, 10, 4, 0.62);
  border: 1px solid rgba(255, 204, 128, 0.26);
  color: #f3d7a8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  pointer-events: none;
  z-index: 8;
}

/* Pause Modal */
.modal-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 7, 3, 0.66);
  backdrop-filter: blur(4px);
  z-index: 20;
  padding: 20px;
}

.dojo-card {
  width: min(340px, 92vw);
  padding: 26px 24px 24px;
  border-radius: 20px;
  background: linear-gradient(180deg, #5c3319 0%, #351a0b 100%);
  border: 3px solid #d49442;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 232, 178, 0.3);
  text-align: center;
}

.card-title {
  font-family: "Trebuchet MS", "Arial Black", Impact, sans-serif;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #ffe054;
  text-shadow: 0 3px 0 #2e1103;
}

.card-subtitle {
  margin-top: 4px;
  margin-bottom: 20px;
  font-size: 14px;
  color: #f0cfa0;
}

.card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dojo-btn {
  padding: 12px 18px;
  border-radius: 12px;
  border: 2px solid rgba(255, 210, 126, 0.45);
  background: linear-gradient(180deg, #6e3d1e 0%, #47230f 100%);
  color: #fff6dc;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.dojo-btn.primary {
  border-color: #ffe885;
  background: linear-gradient(180deg, #52b838 0%, #2a781a 100%);
  text-shadow: 0 2px 2px rgba(12, 42, 8, 0.7);
}

.dojo-btn.subtle {
  background: rgba(34, 15, 6, 0.65);
  border-color: rgba(255, 198, 118, 0.26);
  color: #e6c697;
}

.dojo-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.dojo-btn:active {
  transform: scale(0.98);
}

/* Game Over Plaque */
#gameover-panel {
  position: absolute;
  top: clamp(46px, 9vh, 78px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 15;
  padding: 0 16px;
}

.gameover-card {
  width: min(520px, 94vw);
  padding: 16px 20px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(68, 34, 16, 0.92) 0%, rgba(34, 15, 6, 0.94) 100%);
  border: 2.5px solid rgba(240, 174, 78, 0.68);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.62);
  text-align: center;
}

.gameover-reason {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(217, 30, 44, 0.25);
  border: 1px solid rgba(255, 88, 98, 0.6);
  color: #ff9fa6;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.gameover-title {
  margin-top: 4px;
  font-family: "Trebuchet MS", "Arial Black", Impact, sans-serif;
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #ff454f;
  -webkit-text-stroke: 1.5px #290408;
  text-shadow: 0 4px 0 #290408;
}

.gameover-scores {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  border-radius: 12px;
  background: rgba(20, 8, 3, 0.56);
  border: 1px solid rgba(255, 200, 118, 0.22);
}

.stat-box.highlight {
  border-color: rgba(255, 212, 59, 0.62);
  background: rgba(94, 48, 12, 0.56);
}

.stat-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #e8be82;
}

.stat-num {
  margin-top: 2px;
  font-family: "Trebuchet MS", "Arial Black", sans-serif;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 900;
  color: #fff6dc;
}

.stat-box.highlight .stat-num {
  color: #ffde4a;
}

.new-best-seal {
  position: absolute;
  top: -9px;
  right: -4px;
  padding: 2px 6px;
  border-radius: 6px;
  background: #e82436;
  color: #fff7cf;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  transform: rotate(6deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.gameover-hint {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #f0cfa0;
}

/* Narrow / Mobile / Peek adjustments */
@media (max-width: 640px) {
  #controls-hint {
    max-width: calc(100vw - 72px);
    font-size: 11px;
    bottom: 12px;
    left: 12px;
  }

  .gameover-scores {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-height: 420px) {
  #controls-hint {
    display: none;
  }

  .dojo-icon-btn {
    width: 32px;
    height: 32px;
  }

  .gameover-card {
    padding: 10px 14px;
  }

  .gameover-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #score-value,
  .life-x,
  .dojo-icon-btn,
  .dojo-btn {
    transition: none;
  }
  .life-x.slam {
    animation: none;
  }
}
