:root {
  --bg-dark: #0a1015;
  --bg-panel: #131c24;
  --bg-card: #1a2630;
  --border-pixel: #2e4050;
  --emerald: #34d399;
  --emerald-dark: #15803d;
  --amber: #f59e0b;
  --amber-dark: #b45309;
  --red: #ef4444;
  --cyan: #38bdf8;
  --text-main: #f1f5f9;
  --text-dim: #94a3b8;
  --font-ui: 'Segoe UI', Roboto, system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-ui);
}

button, input, select {
  font-family: inherit;
}

/* Scrollbar tipis untuk panel studio HP landscape */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #0c1319; }
::-webkit-scrollbar-thumb { background: #334657; border-radius: 3px; }

/* ========== PENGUNCI MODE MIRING MUTLAK ========== */
#portrait-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: radial-gradient(circle at center, #182530 0%, #070b0f 100%);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 16px;
}

#portrait-lock-overlay.active {
  display: flex;
}

.rotate-phone-anim {
  width: 72px;
  height: 112px;
  border: 4px solid var(--emerald);
  border-radius: 12px;
  position: relative;
  background: #0f1b24;
  box-shadow: 0 0 24px rgba(52, 211, 153, 0.25);
  animation: rotatePhone 2.2s ease-in-out infinite;
}

.rotate-phone-anim::after {
  content: '';
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 4px;
  border-radius: 2px;
  background: var(--emerald);
}

@keyframes rotatePhone {
  0%, 20% { transform: rotate(0deg); }
  55%, 80% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

@media (orientation: portrait) {
  #portrait-lock-overlay {
    display: flex !important;
  }
}

/* ========== TOMBOL & KOMPONEN UMUM ========== */
.mc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 2px solid #415669;
  border-bottom-width: 4px;
  background: #21303d;
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.12s ease;
  text-decoration: none;
}

.mc-btn:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

.mc-btn.primary {
  background: #16a34a;
  border-color: #4ade80;
  border-bottom-color: #14532d;
  color: #ffffff;
}

.mc-btn.amber {
  background: #d97706;
  border-color: #fbbf24;
  border-bottom-color: #78350f;
  color: #fff;
}

.mc-btn.danger {
  background: #b91c1c;
  border-color: #f87171;
  border-bottom-color: #7f1d1d;
}

.mc-btn.cyan {
  background: #0284c7;
  border-color: #38bdf8;
  border-bottom-color: #075985;
}

.mc-btn.small {
  padding: 5px 8px;
  font-size: 11px;
  border-bottom-width: 3px;
}

.mc-btn.active {
  background: #0f766e;
  border-color: var(--emerald);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.25);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  background: #1a2834;
  border: 1px solid var(--border-pixel);
  color: var(--text-dim);
}

.badge.ok { color: var(--emerald); border-color: #1f6f50; background: #0e291f; }
.badge.warn { color: var(--amber); border-color: #8a5612; background: #2c1e0b; }

/* ========== LOBBY (INDEX.HTML) ========== */
.lobby-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background:
    linear-gradient(180deg, rgba(16, 28, 24, 0.92), rgba(8, 12, 16, 0.98)),
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(52, 211, 153, 0.04) 32px),
    repeating-linear-gradient(90deg, transparent, transparent 31px, rgba(52, 211, 153, 0.04) 32px);
  gap: 10px;
}

.lobby-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border-pixel);
  flex-shrink: 0;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 2px solid var(--emerald);
}

.brand-title h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
}

.brand-title small {
  display: block;
  font-size: 11px;
  color: var(--emerald);
  font-weight: 600;
}

.lobby-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.05fr 1.25fr 1fr;
  gap: 12px;
}

.lobby-card {
  background: rgba(19, 28, 36, 0.92);
  border: 2px solid var(--border-pixel);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.lobby-char-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 60%, #1c312a 0%, #0d151c 75%);
  border: 1px solid #293c4b;
  border-radius: 8px;
  position: relative;
  margin: 6px 0;
}

#lobby-skin-preview {
  image-rendering: pixelated;
  max-height: 100%;
  max-width: 100%;
}

.lobby-loadout-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.info-row {
  background: #101820;
  border: 1px solid #253544;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.info-row span { color: var(--text-dim); }
.info-row strong { color: #fff; }

.lobby-actions {
  justify-content: space-between;
  gap: 10px;
}

.play-big-btn {
  padding: 14px 16px;
  font-size: 16px;
  letter-spacing: 0.6px;
  width: 100%;
}

.dev-big-btn {
  padding: 12px 14px;
  font-size: 14px;
  width: 100%;
}

.dev-shortcuts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

/* Modal Developer di Lobby */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(5, 8, 12, 0.82);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--bg-panel);
  border: 2px solid var(--amber);
  border-radius: 12px;
  max-width: 680px;
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.65);
}

.dev-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.dev-tile {
  background: #101921;
  border: 2px solid #2b3f51;
  border-radius: 8px;
  padding: 12px;
  text-decoration: none;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color 0.15s, transform 0.1s;
}

.dev-tile:hover, .dev-tile:active {
  border-color: var(--amber);
  transform: translateY(-1px);
}

.dev-tile.highlight {
  border-color: var(--emerald);
  background: linear-gradient(135deg, #10251e 0%, #101921 100%);
}

.dev-tile strong { font-size: 14px; }
.dev-tile span { font-size: 11px; color: var(--text-dim); line-height: 1.35; }

/* ========== STUDIO DEVELOPER (STUDIO.HTML) ========== */
.studio-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #090e13;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.studio-topbar {
  height: 42px;
  flex-shrink: 0;
  background: #121b23;
  border-bottom: 2px solid var(--border-pixel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  gap: 8px;
}

.studio-tabs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
}

.studio-body {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

.studio-left-dock {
  width: 168px;
  flex-shrink: 0;
  background: #101820;
  border-right: 2px solid var(--border-pixel);
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
}

.studio-viewport {
  flex: 1;
  min-width: 0;
  position: relative;
  background: #0b1117;
  overflow: hidden;
}

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

.viewport-hud-top {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  gap: 6px;
}

.viewport-hud-top > * {
  pointer-events: auto;
}

.viewport-hud-bottom {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  pointer-events: none;
}

.viewport-hud-bottom > * {
  pointer-events: auto;
}

.studio-right-panel {
  width: 248px;
  flex-shrink: 0;
  background: #101820;
  border-left: 2px solid var(--border-pixel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: width 0.2s ease;
}

.studio-right-panel.collapsed {
  width: 0;
  border-left: none;
  overflow: hidden;
}

.panel-subtabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 6px;
  background: #0d141b;
  border-bottom: 1px solid var(--border-pixel);
  flex-shrink: 0;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-box {
  background: #16212c;
  border: 1px solid #283a4a;
  border-radius: 6px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--emerald);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.btn-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }

.palette-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.swatch {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 2px solid #2a3947;
  cursor: pointer;
}

.swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--emerald);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--emerald);
  margin: 0;
}

.hud-pill {
  background: rgba(11, 17, 23, 0.85);
  border: 1px solid #2f4354;
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  backdrop-filter: blur(4px);
}

#uv-2d-canvas {
  width: 100%;
  aspect-ratio: 1;
  background: repeating-conic-gradient(#1f2933 0% 25%, #161e26 0% 50%) 50% / 12px 12px;
  border: 2px solid #394e61;
  border-radius: 4px;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

.audit-item {
  font-size: 11px;
  line-height: 1.35;
  padding: 5px 6px;
  border-radius: 4px;
  background: #0f171e;
  border-left: 3px solid var(--emerald);
}

.audit-item.warn { border-left-color: var(--amber); background: #21190b; }
.audit-item.error { border-left-color: var(--red); background: #261013; }

/* ========== BATTLE HUD (BATTLE.HTML) ========== */
.battle-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

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

.battle-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 10px 14px;
}

.battle-hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.battle-hud-top > * { pointer-events: auto; }

.hud-stat-box {
  background: rgba(10, 16, 22, 0.78);
  border: 1px solid #334a5e;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hp-bar-track {
  width: 110px;
  height: 10px;
  background: #1f2933;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid #394b5c;
}

.hp-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.15s;
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.crosshair::before, .crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 3px #000;
}

.crosshair::before { left: 9px; top: 0; width: 2px; height: 20px; }
.crosshair::after { top: 9px; left: 0; height: 2px; width: 20px; }

.touch-look-zone {
  position: absolute;
  right: 0;
  top: 56px;
  bottom: 0;
  left: 38%;
  pointer-events: auto;
  touch-action: none;
}

.joystick-base {
  position: absolute;
  left: calc(22px + env(safe-area-inset-left));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(15, 23, 32, 0.55);
  border: 2px solid rgba(52, 211, 153, 0.5);
  pointer-events: auto;
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin-left: -23px;
  margin-top: -23px;
  border-radius: 50%;
  background: rgba(52, 211, 153, 0.85);
  border: 2px solid #fff;
}

.battle-action-pad {
  position: absolute;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 62px);
  gap: 10px;
  pointer-events: auto;
}

.action-circle {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.45);
  background: rgba(17, 26, 34, 0.78);
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.action-circle.fire {
  background: rgba(220, 38, 38, 0.85);
  border-color: #fca5a5;
  grid-column: span 2;
  width: 134px;
  height: 58px;
  border-radius: 28px;
  font-size: 14px;
}

/* Optimasi khusus HP Landscape pendek (tinggi <= 440px) */
@media (max-height: 440px) {
  .studio-left-dock { width: 148px; padding: 5px; }
  .studio-right-panel { width: 224px; }
  .lobby-shell { padding: 6px 12px; gap: 6px; }
  .lobby-topbar { padding-bottom: 5px; }
  .brand-title h1 { font-size: 15px; }
  .play-big-btn { padding: 10px; font-size: 14px; }
}