* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1a1714;
  font-family: 'Segoe UI', 'Arial', sans-serif;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
}

#game-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: linear-gradient(180deg, #2b2420 0%, #1f1b17 55%, #14110f 100%);
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container:fullscreen,
#game-container:-webkit-full-screen {
  width: 100%;
  height: 100%;
  padding: 0;
  background: #1a1714;
}

body.play-active {
  background: #000;
}

#rotateGate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 4, 0.96);
  padding: 24px;
  text-align: center;
}

#rotateGate.visible {
  display: flex;
}

#rotateGate .rotate-card {
  max-width: 320px;
}

#rotateGate .rotate-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

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

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 20px;
  pointer-events: none;
  z-index: 10;
  gap: 8px;
}

.hud-chip {
  background: rgba(20, 17, 14, 0.7);
  border: 2px solid #d8a23a;
  border-radius: 10px;
  padding: 8px 16px;
  color: #f0d9a8;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 1px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

.hud-chip span {
  color: #ffffff;
  font-size: 20px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 6, 0.97);
  z-index: 20;
  text-align: center;
  padding: 24px;
}

.overlay.hidden {
  display: none;
}

.title-main {
  font-size: 52px;
  font-weight: 900;
  color: #f0d9a8;
  letter-spacing: 3px;
  text-shadow: 0 4px 0 #8a5a1f, 0 6px 12px rgba(0, 0, 0, 0.6);
  margin-bottom: 4px;
  line-height: 1.1;
}

.title-sub {
  color: #d8a23a;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  margin-bottom: 30px;
  opacity: 0.85;
}

.btn {
  background: linear-gradient(180deg, #e8b454, #c4863a);
  border: none;
  border-radius: 12px;
  padding: 16px 48px;
  font-size: 22px;
  font-weight: 900;
  color: #2b1d0d;
  letter-spacing: 1px;
  box-shadow: 0 4px 0 #7a4d1f, 0 8px 16px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  margin-top: 10px;
  transition: transform 0.1s;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #7a4d1f, 0 4px 8px rgba(0, 0, 0, 0.4);
}

.btn-secondary {
  background: transparent;
  border: 2px solid #d8a23a;
  border-radius: 12px;
  padding: 10px 32px;
  font-size: 16px;
  font-weight: 800;
  color: #d8a23a;
  letter-spacing: 1px;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.15s;
}

.btn-secondary:active {
  background: rgba(216, 162, 58, 0.15);
}

.instructions {
  color: #c9b89a;
  font-size: 15px;
  line-height: 1.7;
  max-width: 320px;
  margin-bottom: 26px;
}

.instructions b {
  color: #f0d9a8;
}

.score-result {
  font-size: 64px;
  font-weight: 900;
  color: #ffffff;
  margin: 6px 0 2px;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.score-result-label {
  color: #d8a23a;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  margin-bottom: 18px;
}

.best-row {
  color: #a89878;
  font-size: 14px;
  margin-bottom: 24px;
}

.best-row b {
  color: #f0d9a8;
}

.skins-progress {
  color: #a89878;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 14px;
}

.skins-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: min(94%, 480px);
  max-height: 52vh;
  overflow-y: auto;
  margin-bottom: 18px;
  padding: 4px 2px;
}

.skin-card {
  border-radius: 10px;
  padding: 8px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
  background: rgba(255, 255, 255, 0.04);
  position: relative;
}

.skin-card.unlocked:hover {
  background: rgba(216, 162, 58, 0.1);
}

.skin-card.selected {
  border-color: #d8a23a;
  background: rgba(216, 162, 58, 0.13);
}

.skin-card.locked {
  opacity: 0.45;
  cursor: default;
}

.skin-preview {
  width: 36px;
  height: 44px;
}

.skin-name {
  font-size: 9px;
  font-weight: 800;
  color: #f0d9a8;
  text-align: center;
  line-height: 1.2;
}

.skin-req {
  font-size: 8px;
  color: #a89878;
  text-align: center;
}

.side-btn {
  position: absolute;
  z-index: 15;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: 3px solid #d8a23a;
  background: rgba(20, 17, 14, 0.88);
  color: #f0d9a8;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 0 #7a4d1f, 0 6px 12px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0;
}

.side-btn .side-label {
  font-size: 9px;
  font-weight: 800;
  margin-top: -2px;
}

.side-btn.help {
  border-color: #7a8a9a;
  box-shadow: 0 4px 0 #3a4a5a, 0 6px 12px rgba(0, 0, 0, 0.5);
}

.side-btn.hide-seek {
  border-color: #3a9d6e;
  background: rgba(10, 20, 14, 0.88);
  box-shadow: 0 4px 0 #1f6b46, 0 6px 12px rgba(0, 0, 0, 0.5);
}

.side-btn.hide-seek .side-label {
  color: #6fd86f;
}

.side-btn.battle {
  border-color: #c44b3a;
  background: rgba(20, 10, 8, 0.88);
  box-shadow: 0 4px 0 #7a2010, 0 6px 12px rgba(0, 0, 0, 0.5);
}

.side-btn.battle .side-label {
  color: #ff8a6a;
}

#pauseBtn {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(20, 17, 14, 0.7);
  border: 2px solid #d8a23a;
  border-radius: 10px;
  color: #f0d9a8;
  font-size: 20px;
  padding: 6px 16px;
  cursor: pointer;
  display: none;
}

#autopilotBtn {
  position: absolute;
  top: 14px;
  left: calc(50% + 58px);
  z-index: 40;
  background: rgba(20, 17, 14, 0.85);
  border: 2px solid #7a8a9a;
  border-radius: 10px;
  color: #c8d0d8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  cursor: pointer;
  pointer-events: all;
}

#autopilotBtn.on {
  border-color: #6fd86f;
  color: #b8f0b8;
  box-shadow: 0 0 0 1px rgba(111, 216, 111, 0.35);
}

#autopilotBtn.hidden {
  display: none;
}

#autopilotLogBtn {
  position: absolute;
  top: 14px;
  left: calc(50% + 128px);
  z-index: 40;
  background: rgba(20, 17, 14, 0.85);
  border: 2px solid #7a8a9a;
  border-radius: 10px;
  color: #c8d0d8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  cursor: pointer;
  pointer-events: all;
}

#autopilotLogBtn.hidden {
  display: none;
}

#langToggle {
  position: absolute;
  top: 14px;
  z-index: 16;
  background: rgba(20, 17, 14, 0.75);
  border: 2px solid #7a8a9a;
  border-radius: 10px;
  color: #f0d9a8;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 10px;
  cursor: pointer;
  pointer-events: all;
}

html[dir="rtl"] #langToggle {
  left: 14px;
}

html[dir="ltr"] #langToggle {
  right: 14px;
}

/* Mobile control chrome */
#controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  display: none;
}

#controls.visible {
  display: block;
}

body.touch-play #controls {
  display: none !important;
}

#mobileHints {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  z-index: 12;
  display: none;
  pointer-events: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0 10px;
  gap: 10px;
}

#mobileHints.visible {
  display: flex;
}

#mobileHints .hint-mid {
  flex: 1;
  text-align: center;
  color: #c9b89a;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

#mobileHints .hint-mid.wide {
  max-width: 70%;
}

#mobileHints .motion-status {
  margin-top: 2px;
  color: #d8a23a;
  font-size: 10px;
}

.mobile-jump-btn {
  pointer-events: all;
  min-width: 72px;
  min-height: 72px;
  border-radius: 50%;
  border: 3px solid #c44b3a;
  background: rgba(30, 10, 10, 0.88);
  color: #f0d9a8;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 4px 0 #7a2010, 0 6px 12px rgba(0, 0, 0, 0.45);
  flex-shrink: 0;
}

.mobile-jump-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #7a2010, 0 3px 8px rgba(0, 0, 0, 0.45);
}

.ctrl-cluster {
  position: absolute;
  bottom: 18px;
  pointer-events: all;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ctrl-cluster.left {
  left: 12px;
}

.ctrl-cluster.right {
  right: 12px;
  flex-wrap: wrap;
  max-width: 200px;
  justify-content: flex-end;
}

.ctrl-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #5a4a35;
  background: rgba(20, 15, 10, 0.85);
  color: #f0d9a8;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.1;
  padding: 4px;
}

.ctrl-btn.fire {
  width: 68px;
  height: 68px;
  border-color: #d8a23a;
  font-size: 13px;
}

.ctrl-btn.detach {
  border-color: #c44b3a;
}

.ctrl-btn.active,
.ctrl-btn:active {
  background: rgba(216, 162, 58, 0.35);
}

#aimPad {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid #5a4a35;
  background: rgba(20, 15, 10, 0.55);
  position: relative;
  touch-action: none;
}

#aimKnob {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(216, 162, 58, 0.85);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.help-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 300px;
  text-align: start;
  max-height: 55vh;
  overflow-y: auto;
  margin-bottom: 8px;
}

.help-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid #3a3024;
}

.help-card h3 {
  color: #f0d9a8;
  font-weight: 800;
  font-size: 15px;
}

.help-card p {
  color: #c9b89a;
  font-size: 13px;
  margin-top: 3px;
}

/* Battle / hide-seek overlays reuse layout from index */
#battleOverlay {
  gap: 0;
  padding: 0;
  background: rgba(8, 4, 4, 0.97);
  pointer-events: none;
}

#battleCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#battleResultOverlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 6, 0.97);
  text-align: center;
  padding: 24px;
}

#hideSeekScreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  overflow: hidden;
  background: #0a0a0f;
  touch-action: none;
}

#hs_gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#hs_hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  pointer-events: none;
  z-index: 10;
}

#hs_dpad {
  position: absolute;
  bottom: 24px;
  left: 16px;
  z-index: 10;
  display: grid;
  grid-template-columns: 56px 56px 56px;
  grid-template-rows: 56px 56px;
  gap: 6px;
}

.hs-dpad-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #5a4a35;
  background: rgba(20, 15, 10, 0.85);
  color: #f0d9a8;
  font-size: 22px;
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#hs_overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 16, 0.97);
  text-align: center;
  padding: 24px;
}

#hs_overlay.hidden {
  display: none;
}

#hs_resultOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 16, 0.97);
  text-align: center;
  padding: 24px;
}

.result-big {
  font-size: 64px;
  font-weight: 900;
  color: #fff;
  margin: 8px 0 2px;
}

.result-sub {
  color: #d8a23a;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 16px;
}

@media (min-width: 900px) {
  #controls {
    opacity: 0.55;
  }
}
